Cross Domain Tracking in Google Analytics and GTM
Google Tag Manager makes it very easy to set up cross domain tracking. Traditionally, without a tag management platform, the Google analytics code had to be altered to share data between the two domains. If you don’t have a tag manager you modify your existing code script by adding.
You can access the code by entering your admin console.
<script>
(function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,’script’,’https://www.google-analytics.com/analytics.js’,’ga’);
ga(‘create’, ‘UA-XXXXXX-1’, ‘auto’);
ga(‘send’, ‘pageview’);
</script>
Then you can modify the code with the below.
{‘allowLinker’: true});
ga(‘require’, ‘linker’);
ga(‘linker:autoLink’, [‘otherwebsite.com’] );
The final version of the code should look like:
<script>
(function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,’script’,’https://www.google-analytics.com/analytics.js’,’ga’);
ga(‘create’, ‘UA-XXXXXX-1’, ‘auto’, {‘allowLinker’: true});
ga(‘require’, ‘linker’);
ga(‘linker:autoLink’, [‘otherwebsite.com’] );
ga(‘send’, ‘pageview’);
</script>
Now that you understand how the code will be modified. It’s very important that you have your analytics code installed on both domains
Cross Domain Tracking with Google Tag Manager
- Open up Google Tag Manager and Choose your Container.
- Chose your Google Analytics Tag (If you are not using Google Tag Manger to deploy your analytics tag you should migrate it over).
- Click Configure Tag Section
- Choose Advanced Settings
- Click Field to Set
- Under Field Name, choose allowLinker and under value, type true.
- Next Go to Cross Domain Tracking, add your two domains, i.e. domainA.com, domainB.com
- Under Hash Delimiter, leave False and Under Decorate Forms, leave False.
After setting the allowLinker field, you can set the cross domain tracking for the two domains that are needed.