Google Analytics
Cross Domain Tracking in Universal Analytics
May 31, 2015
5
Google Analytics

Cross Domain tracking is used when you send a user to another 3rd party website to complete your website desire goal such as completing ecommerce transaction through 3rd party checkout or to complete registration process on another domain etc.

When you send a user from your website to other website the user session ends and Google Analytics count that user as an exit. In this case you will not be able to track what your user do on other domain.

Examples of Cross Domain Scenario:

Suppose you run an ecommerce store with the domain abcstore.com with a checkout/ cart on a different domain let suppose abcshoppingcart.com

Your store sends users to abcshoppingcart.com to complete transaction. If you don’t implement the cross domain tracking you will not be able to track the user activity on abcshoppingcart.com in Google Analytics.

How to implement Cross Domain Tracking?

In Order to track user across different domain we pass the visitors cookie information to other website so that the session don’t ends. We can do this by doing some modifications into Google Analytics default tracking code.

Setup Cross Domain Tracking in Universal Analytics:

In order to setup cross domain tracking in universal analytics you need to make the following changes into your code.

On your website for example on abcstore.com place the following code within your Analytics default code

ga(‘create’, ‘UA-XXXXXXX-Y’, ‘auto’, {‘allowLinker’: true});

ga(‘require’, ‘linker’);

ga(‘linker:autoLink’, [‘ abcshoppingcart.com’] );

Here is how the full code will looks 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’,’//www.google-analytics.com/analytics.js’,’ga’);

 

ga(‘create’, ‘UA-XXXXXXX-Y’, ‘auto’, {‘allowLinker’: true});

ga(‘require’, ‘linker’);

ga(‘linker:autoLink’, [‘ abcshoppingcart.com’] );

ga(‘send’, ‘pageview’);

 

</script>

 

And on other website for example on abcshoppingcart.com place the following code

ga(‘create’, ‘UA-XXXXXXX-Y’, ‘auto’, {‘allowLinker’: true});

ga(‘require’, ‘linker’);

ga(‘linker:autoLink’, [‘ abcstore.com’] );

Here is how the full code will looks 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’,’//www.google-analytics.com/analytics.js’,’ga’);

 

ga(‘create’, ‘UA-XXXXXXX-Y’, ‘auto’, {‘allowLinker’: true});

ga(‘require’, ‘linker’);

ga(‘linker:autoLink’, [‘ abcstore.com’] );

ga(‘send’, ‘pageview’);

 

</script>

 

Note: Make sure that you use same UA no. UA-XXXXXXX-Y on both domains.

The changes we made into code enable the linking between both domains. Whenever there is a link to abcshoppingcart.com the cookie will get passed through that link.

You can confirm that the cookies are being passed by client on the 3rd party domain link. You will be able to see the cookie information in the url as you can see bellow.

cross domain

If your website send visitor to another website through a form submission than in this case you have to change the

ga(‘linker:autoLink’, [‘ abcshoppingcart.com’] );

with the bellow one

ga(‘linker:autoLink’, [‘ abcshoppingcart.com’], false, true);

Just add the false, true at the end of the code. This will automatically decorate the all the forms that exist in the website. It work on both “POST” and “GET” forms.

 

If you are using the old version of Google Analytics than the above mention code will not work for that the cross domain tracking code is different.

You can find the details on how to setup cross domain tracking in classic analytics on this post http://www.optimizesmart.com/cross-domain-tracking-google-analytics-works/

About author

Nouman Tariq

Nouman is Google Certified Digital Marketing Specialist. He is specialized in Search Engine Optimization, Pay Per Click Management (Google Adwords, Facebook, Bing and other Ads Networks), Google Analytics, Social Media Marketing, Conversion Rate Optimization, Display Advertising and Email Marketing.

There are 5 comments

  • Mark says:

    Based on your example, what if abcshoppingcart.com already had its GATC? How could we use its original GATC and combine with abcstore.com’s GATC?

    • Nouman Tariq says:

      Hi Mark,

      If 3rd party domains already have GATC than still you need to add your GATC in order to track your visitors in your own analytics using the methord explain above.

      You don’t have to replace the original analytics code with yours the other domain can have 2 codes with different UA numbers.

      Thanks,

  • John says:

    Hi,

    Thanks for that. Do you have an example of a store doing that please?

    I looked at your portfolio and it looks very impressive.

    Regards,
    John

  • John says:

    Hi,
    Thanks for that. I went to that Japanese site and can see the code in action. The source and destination link appear to be alike.

    Do you have another example please?

    Thanks

  • Leave a Reply

    Your email address will not be published. Required fields are marked *