@mschmitz89 opened this issue on February 13th 2017

Hey, I'm using latest PIWIK 3.0.1 and want one part of the website being tracked in 2 websites simultaneously.

I followed the way written in the documentation to accomplish this: https://developer.piwik.org/guides/tracking-javascript-guide#multiple-piwik-trackers The tracking code I'm using:

`<!-- Piwik -->
<script type="text/javascript">
  var _paq = _paq || [];
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//piwik.domainxy.de/";
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', '1']);

    // Include second tracking
    var websiteIdDuplicate = 6;
    _paq.push(['addTracker', piwikUrl = null, websiteIdDuplicate]);

    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<noscript>
<p><img src="//piwik.domainxy.de/piwik.php?idsite=1" style="border:0;" alt="" /></p>
<p><img src="//piwik.domainxy.de/piwik.php?idsite=6" style="border:0;" alt="" /></p>
</noscript>
<!-- End Piwik Code -->`

But only the first Website gets tracked.

It's the same behaviour in PIWIK 2.16.5.

@mattab commented on February 20th 2017

Could you send us your website URL where you have put this code?

@mattab commented on February 21st 2017

Thanks for the report, I could reproduce this issue.

The solution is to explicitely set the piwik URL as the second parameter.

So replace _paq.push(['addTracker', piwikUrl = null, websiteIdDuplicate]);

by _paq.push(['addTracker', u+'piwik.php', websiteIdDuplicate]);

I'll fix now the documentation

@mschmitz89 commented on February 21st 2017

Thank you Matt, works perfectly! :)

@tsteur commented on February 21st 2017

BTW we could likely make that work by changing order in piwik.js of

var applyFirst = ['addTracker', 'disableCookies', 'setTrackerUrl', 

to

var applyFirst = ['setTrackerUrl', 'addTracker', 'disableCookies',

but haven't tested it

This issue was closed on February 21st 2017
Powered by GitHub Issue Mirror