February 14, 2018
Sometimes our websites are so vast that they stretch across couple of different domains. For example our blog platform is on one domain while our ecommerce platform is on the other. Of course we could track those two platforms separately as two different websites in Piwik PRO. But what if we want to check the whole path of our visitors, from the start on a blog article until a purchase.
That’s where cross-domain tracking comes in handy. It allows you to track same visitor path through multiple domains. Normally Piwik PRO would create a new visit each time a domain change because visitor ID cookie are created in the website domain. However the method I’ll show below allows you to overcome this obstacle.
The easiest way to implement the cross-domain tracking is to use Piwik PRO Tag Manager which is part of Piwik PRO Marketing Suite.
What you need to do first is create a new asynchronous custom HTML tag
Into the HTML editor of your new tag paste the standard Piwik PRO tracking code
For refference the code will look something like this:
<!-- Piwik -->
var _paq = _paq || ;
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script');
<noscript><p><img src="//example.piwik.pro//piwik.php?idsite=XXXX-XXXX-XXXX-XXXXXXXX&rec=1" style="border:0" alt="" /></p></noscript>
<!-- End Piwik Code -->
Just make sure to switch the XXXX with real UUID of your websites (two occurences)
and the example.piwik.pro to your own *.piwik.pro URL (2 occurrences).
Now you’ll need to add two lines to the code which are responsible for the cross domain tracking:
_paq.push(['setDomains', ['https://shop.com', 'https://blog.com']]);
Of course again you’ll need to switch the domains in the above code with your own domains.
Final code will look like this:
Now all you need to do is add the trigger to the tag. I suggest using the same trigger that you used for your standard tracking (ex. “All Pageviews”)
Remember to hit “Save” button when you’re done.
Now you’ll need to disable your standard Piwik PRO tracking tag.
To do that, locate it in the tag list and toggle the on-off switch
Now it’s time to publish your changes. Hit the publish button and proceed to test your new solution.
To test cross-domain tracking simply visit your website and walk from one domain to the other. You should see that when you move from domain A to domain B your URL will contain an additional parameter
this parameter will pass the visitorID when moving from one domain to the other and ensure that Piwik PRO recognizes the same visitor.