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 www.my-A-site.com for first time. The analytics code stores a cookie on my-A-site.com.
  • When the user goes to shop.my-A-site.com, the analytics code there reads the cookie stored by my-A-site.com & 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 www.Asite.com & www.Bsite.com we have a problem here.

The cookies (clientID) stored by Asite.com cannot be read by Bsite.com 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 destination.com URLs with clientIDs within source.com
These clientIDs would then be fetched by destination.com.

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: Asite.com, Bsite.com, Csite.com
  • 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. 
Cross_Domains_Tracking_Settings_-_Digishuffle

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.
Cross_Domain_Settings_-_Digisuffle

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 www.my-A-site.com for first time. The analytics code stores a cookie on my-A-site.com.
  • When the user clicks on the link to goes to www.my-B-site.com, he lands on www.my-B-site.com/?_ga=xxxxxxx.xxxxxxxxxx.
  • The analytics code on www.my-B-site.com 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 source.com to destination.com, there should be clientID attached to it. For Eg: www.destination.com.?_ga=xxxxxxxx.xxxxxxxx
  2. Also, the clientID on source.com should match the clientID on destination.com 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. 

Conclusion

  • 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 Web Analyst & Growth Hacking Consultant. He loves to write technical & easy to understand blogs for Marketers & Entrepreneurs. Focused on Google Analytics, Tag Management, GScripts & more. Google Certified Professional. A Firm Believer in Teaching -> Learning -> Growing. :)

Comments (2)

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

Leave a Reply

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