• Home  / 

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

  1. Open up Google Tag Manager and Choose your Container.
  2.  Chose your Google Analytics Tag (If you are not using Google Tag Manger to deploy your analytics tag you should migrate it over).
  3. Click Configure Tag Section
  4. Choose Advanced Settings
  5. Click Field to Set
  6. Under Field Name, choose  allowLinker and under value, type true.
  7.  Next Go to Cross Domain Tracking, add your two domains, i.e. domainA.com, domainB.com
  8. Under Hash Delimiter, leave False and Under Decorate Forms, leave False.

 

Cross domain tracking with allowLinker

After setting the allowLinker field, you can set the cross domain tracking for the two domains that are needed.

add domains to your cross domain settings