Advanced Guide To Cross Domain Tracking – Universal Analytics

Here, we’ll be understanding the concept of Cross Domain Tracking.

In this guide, I’ll also explain behind the scenes processes.

Simply put…

The main goal of Cross Domain Tracking is

when the user goes from siteA to siteB, we want the result to be

USER : 1 & SESSION : 1 

I will consider different scenarios so that we can understand how the metrics would be reported in each.

Some Questions answered here would be:

  1. How do cookies work across domains?
  2. How to do Cross Domain Tracking for sub-domains?
  3. How to do Cross Domain Tracking for 3rd party domains?
  4. When does the Cross Domain Tracking won’t work?
    & more 

I’ll explain each step as to why you should implement it & what it will result into.

So.. let’s dive in

Understanding Google Analytics Cookies

and it all starts with cookies…

I am assuming the code installed is analytics.js, also known as Universal Analytics.
You can also check for the following red line for confirmation.

(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

ga(‘create’, ‘UA-89611791-1’, ‘auto’);
ga(‘send’, ‘pageview’);

So, when a new user lands on your website, say, the analytics code will store a cookie in their browser.

This cookie is represented as



  • Name of the Cookie = ‘_ga’
  • Value of the Cookie = ‘GA1.2.1737304625.1491863707’
  • ClientID = ‘1737304625.1491863707’

This ClientID is used by google analytics to distinguish between users.

Want to check the cookies stored in your browser?? Sure..

You can open your console (Ctrl+Shift+I) & paste the following code to check these values.

  • GA Cookie = /_ga=[^;]+/i.exec(document.cookie)[0] 
  • ClientID = ga.getAll()[0].get(‘clientId’)

If the cookie is written on It can be read by all its subdomains. Eg:

  • & so on.

But CANNOT be read by

  • & so on
Cross-Domain-Tracking - Subdomain

Google Analytics by default writes cookies on the hostname.

For Eg:

You can verify by opening the console & pasting – ga.getAll()[0].get(‘cookieDomain’)

These cookies can be read across sub-domains. ( ,, etc)

cookieDomain google analytocs - Digishuffle

Google Analytics Cross Domain Tracking for Subdomains

There is not much to do while tracking across subdomains as I have already mentioned that the cookies are shared.

Just follow these 2 steps below.

Step – 1

  • If you are using analytics.js manual code placement, the cookieDomain part should be set to ‘auto’ (which is already there by default) in the line
    ga(‘create’, ‘UA-12345678-1’,‘auto’)
    It will make sure the cookie is stored on the hostname itself. (
  • If you are using Tag manager, make sure include cookieDomain to ‘auto’ in fields to set.

Step – 2

  • Make sure the property ID is same across domains. (UA-12345678-1)
  • In Google Analytics, Referral Exclusion already contains your domain name by default. ( It will exclude all the subdomains automatically. 
    There is nothing to modify here.

Subdomain Tracking Scenario

Just to understand the process, let us look at the following scenario:

  • A user lands on for first time.
  • The analytics.js stores a new cookie on the user’s browser at (So it can be read across all, where xxxxx is variable)
  • When user goes to, the analytics.js code searches for the ga cookies. It extracts the ClientID & uses the same.
Cross-Sub-Domain-Tracking - Digishuffle


Google Analytics Cross Domain - Other/3rd party Domains Scenario

If you have different domains like &, the cookies set by one cannot be read by other.

Scenario #1 - Same anaytics.js code on two different domian (without Cross Domain Tracking)

Lets us see what happens in this scenario:

  • A user lands on for first time.
  • The analytics.js stores a new cookie on the user’s browser at
  • Now, when user goes to, the analytics code there will search for the ga cookies.
  • The domain will not be able to read the cookie stored by (remember same-origin policy)
  • It will treat this user as new user & store new ClientID in its browser.


Cross-Domain-Tracking-Different-Domains - Digishuffle

Solution By Google:

The solution here by google is to attach the clientID to the destination domain URLs in the source domain & then fetch it when a user lands on destination domains.

So, when a user clicks a link on to The clientID will be appended to as the parameter. Eg:

On destination domain, ‘allowLinker’ will be used to fetch the clientID from URL & use it.

Simple, isn’t it…

Step 1 - Use Linker Plugin

Google has provided a plugin to automate this work. You need to install the following code on

  • Linker plugin
    • Linker Plugin code :
      ga('require', 'linker');
      ga('linker:autoLink', [''], false, true);

      The above code will simply append the clientID parameter to all URLs on ( pointing to ( . 

      ga('require', 'linker');
      ga('linker:autoLink', ['',''], false, true);

      For multiple domains, use the above format.

    • Format:
      ga('linker:autoLink', Array of Domain, useAnchor, decorateForms);


  • To Test it out, Open your console (Ctrl+Shift+I) & paste the following code:
    ga('linker:autoLink', [''], false, true);

    Now, click the below button

  • You will see the parameter attached at the end of URLs.  This should happen to all the URLs pointing to the destination domain.
Cross_Domain_Tracking_ClientID - Digishuffle
  • You can use the above code to test your website too. Just replace the in the code with your destination domain & paste it in the console.
  • Now try clicking on the destination domain link. The _ga parameter should get appended
  • This setup does not work in iframes.

Step 2 - Set AllowLinker To True

On destination domain, modify the following code

ga('create','UA-1234551-1','auto', {'allowLinker': true})

 This will result in the destination domain using the clientID in the URL.

Cross-Domain-Tracking-plugins - Digishuffle

Step 3 - The Final Code

The code on Souce Domain. (


(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','//','ga');

ga('create', 'UA-XXXXXXX-Y', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', [''], false, true);

ga('send', 'pageview');


The code on Destination Domain. (


(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','//','ga');

ga('create', 'UA-XXXXXXX-Y', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', [''], false, true );

ga('send', 'pageview');


Step 4 - Referral Exclusion in Google Analytics

  • Lastly, Go To Google Analytics > Property Settings > Tracking Info > Referral Exclusion List > Add Your Destination Domain.

Scenario #2

Now that we have completely setup cross domain tracking, lets look at the following scenario:

  • When a new user lands on, analytics stores a new clientID.
  • The same user clicks on the link to Due to linker plugin, analytics will append the clientID to all links on
  • The user lands on Now due to allowlinker set to ‘true’, analytics will check the URL for clientID & use the same. This will result in User identified as the same throughout 2 domains.


Cross-Domain-Tracking-Other Domains - Digishuffle
  • Lastly, make sure you have source & destination domain as referral exclusion in analytics interface
    it will create a new sessions when the user migrates from domain to domain.

Before Adding Referral Exclusion.


After Adding Referral Exclusion


Verify Cross Domain Tracking in Google Analytics

The best way to check is to go step by step. Start by verifying

  1. The links you click to destination domain have clientID appended to it.
    (Check above example by clicking the button to
  2. Then make sure when you land on destination domain the clientID matches the source domain’s clientID.
    You can use network tab in browser debugger. Filter the requests by ‘collect’ to get hit data sent to analytics.
    cid & tid must be same for both the domains for a single user. 
  • Lastly, In analytics reports you should see User : 1 & Session : 1 , for the process we followed now.
  • If you see Sessions : 2, make sure to add destination & source domain in referral exclusion list.

Some of the reasons Cross domain tracking will not work with this method if..

  • You have destination site embedded in an iframe.
  • You have a server side redirect to the destination domain.
  • You have an event based redirect to the destination domain.
  • Query parameters are stripped off in the destination domain before analytics fires,
  • & so on

Here’s a guide to tackle iframes cross domain tracking by Simo


  • It is important to understand the concept behind the cross domain tracking.
  • If nothing works, you can manually implement cross domain tracking by tagging the URLs on source domain with clientIDs & use them on 
    You can use this concept for other tracking tools too.
  • You can even use advanced view filter to combine the hostname + pagepath in analytics reporting interface.
Hostname_PagePath_Google Analytics - Digishuffle
  • Lastly, don’t forget to share with your friends & colleague. 

Ritwik is a Web Analyst & Product Marketer. He loves to write technical & easy to understand blogs for Marketers & Entrepreneurs. Focused on Google Analytics, Facebook Analytics, Tag Management, Marketing & Automation Scripts & more. Google Certified Professional. A Firm Believer in Teaching -> Learning -> Growing. :)