Cross Domain Tracking via Google Tag Manager.

On the previous post for cross domain tracking in google analytics, I had explained some of the following points like

  • How do cookies work in cross domain tracking?
  • How to implement cross domain tracking in subdomains via analytics.js
  • How to implement cross domain tracking in 3rdparty domains via analytics.js
  • When cross domain tracking won’t work 
    & more..

Do have a look:

As I have explained in the last post,

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 

Once we verify the metrics are getting captured correctly, we’re all good.!!

Google tag manager really speeds up the implementation work as compared to analytics.js manual placement.

We’ll look at step by step implementation of Cross Domain Tracking for subdomains & 3rdparty domains.

Cross Domain Tracking for Subdomain

Well there’s not much to add here because it’s just a one step setup.

Step – 1

  • In fields to set > Field Name, add cookieDomain to ‘auto’.

Step – 2

  • You’re done.!!

Here’s a scenario just to understand what happens exactly.

  • User lands on for first time. The analytics code stores a cookie on
  • When the user goes to, the analytics code there reads the cookie stored by & recognises the same user using clientID.
Cross-Sub-Domain-Tracking - Digihsuffle

Result = User : 1 & Session : 1

Cross Domain Tracking for 3rd Party/Other Domains

Now if you have sites like & we have a problem here.

The cookies (clientID) stored by cannot be read by due to same-origin policy.

I have explained a bit detail about cookies at

Advanced Guide To Cross Domain Tracking – Universal Analytics

The solution is to tag the URLs with clientIDs within
These clientIDs would then be fetched by

Follow the steps below

Step 1 : Create variables in Google Tag Manager.

  • In GTM, Go To Variables > Create New Variable of type ‘Google Analytics Settings’
GA_Settings_GTM_Variable - Digishuffle
  • Enter your Property ID
  • Cookie Domain should be ‘auto’. (default)
  • In Fields to Set, insert ‘allowLinker’ to ‘true’
Cross_Domain_Tracking Settings - Digishuffle
  • In Cross Domain Tracking Settings > AutoLink Domains > Enter all domains (which you want to track) with commas as separator
    For Eg:,,
  • Use Hash as Delimiter {optional) : If you want add clientID as a parameter using ‘#’ instead of ‘?’. Set it True
  • Decorate Forms (optional) : If you have a form which migrates the user to other site, on submitting. Set it True.
  • Save the variable. 

Step 2 : Create Universal analytics tag & use the cross domain setting variable.

  • Create a new Analytics tag & use the Analytics Settings Variable you saved in previous step.

Step 3 : Exclude Referrals in Google Analytics

  • In Google Analytics > Property Settings > Tracking Info > Referral Exclusion List > Add all the Source & Destination Domain.

Here’s a scenario just to understand what happens.

  • User lands on for first time. The analytics code stores a cookie on
  • When the user clicks on the link to goes to, he lands on
  • The analytics code on reads the clientID from the URL & uses it.
  • This results in User being counted as same thoughout all the domains.
  • Make sure to exclude referrals in analytics else the result would be User: 1 & Session : 2
Cross-Domain-Tracking-Other Domains - Digishuffle

Result = User : 1 & Session : 1

Cross Domain Tracking Verification

We’ll start with step by step verification of cross domain tracking.

Make sure.. 

  1. Whe you click on the link on to, there should be clientID attached to it. For Eg:
  2. Also, the clientID on should match the clientID on 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. 


  • If you want to understand the process in detail do check here 

    Advanced Guide To Cross Domain Tracking – Universal Analytics

  • The setup does not work if
    • You have iframes
    • You have server side redirect to destination domain
    • Query paramters are stripped off on destination domain as soon as user lands.
    • etc
  • If you want to have page path in analytics UI as Hostname+pagepath, then you can use advanced view filters. check below settings.
Hostname_PagePath_Google Analytics - Digishuffle
  • You can even implement cross domain tracking manually, check here for more info

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. :)

Comments (2)

  1. Hi! usefull post! if i have for example,,… are considered as a diferent domains?

Leave a Reply

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