Cross Domain and Sub Domain Tracking with Google Tag Manager

Updated: May 18, 2018

This is a typical scenario many of us find themselves: you have your own/company/client website where users can pay for something, and a second website where the same users complete those payments. This is because probably your CMS cannot handle online transactions. To track both data we use two Google Analytics properties, which means two sets of metrics, KPIs, goals and events.


It's a very typical scenario, two sets of data for two Google Analytics properties. You send traffic to the first property and receive payments on the second one.


In this case you need cross-domain tracking.


If you don't set up cross-domain tracking, you will have two different Client IDs, which means you won't be able to understand if users going from one site to another are the same ones or not. In other words, any user who used to have a Client ID of A in the first property, will have a Client ID of B in the second property, which means they are treated as completely different users.


A solution to this situation is to store the same Client ID into a cookie domain identified with _ga. Google Analytics uses "Cookie Domains" that we need to add. How is Tag Manager managing this? Here is the guide.


Before I explain you the guide, there is an important difference to make just for the sake of clarity. Cross-domain tracking is not the same as sub-domain tracking.

Cross-domain is when you have two different domains, for example www.mywebsite.com and www.mypayment.com as we have seen above. Sub-domain, instead, is when you got the same domain and two different sub domains, for example: www.mywebsite.com and www.blog.mywebsite.com.


In this post I describe both methods for tracking these two situations.


Let's start with sub-domain and then we move below to cross-domain tracking guide.


SUB-DOMAIN TRACKING WITH TAG MANAGER


STEP 1: OPEN THE GOOGLE ANALYTICS TAG AND INSERT COOKIE DOMAIN


Just edit your Pageview Google Analytics Tag:


  • Other settings> Fields to set.

  • Click on the Add field.

  • Field name: cookieDomain.

  • Value: auto.

Job done!




[Update 12th of May 2017] Since the Variable for Google Analytics settings has been released, you can actually manage the Cookie Domain directly from there.

In this case, follow the guide in which I explain how to create the Variable of GA settings and instead of following the procedure I just described in step 1 (set the Cookie Domain in Other Settings> Fields to set), do this:


  • Enter the Google Analytics Tag.

  • Google Analytics settings.

  • Select the GA Variable you just created.

What if you have cross-domain situation?


CROSS-DOMAIN TRACKING WITH TAG MANAGER


In this case you have to manage these two parameters of Google Analytics: Allow Linker and Auto-Links Domain.


STEP 1 - CREATE A CONSTANT VARIABLE WITH ALL YOUR DOMAINS

Just go to:


  • Variables> New> Variable configuration.

  • Variable type: Constant.

  • Value: write the list of domains separated by a comma. For example: mywebsite.com, yourwebsite.com, blog.mywebsite.com.

  • Name the Variable: "gaDomain".


gaDomain variable

STEP 2 - ACTIVATE ALLOWLINKER


As you did for the cookieDomain, open your GA Tag and go to Other settings> Fields to set.


Then:


The value of cookieDomain leaves cars.

Enable the allowLinker field and set it to true.



allowLinker True


STEP 3 - INSERT AUTO LINK DOMAINS


Go to:


  • Other settings> Cross-domain Tracking.

  • Automatically link domains (Auto Links Domains): {{gaDomain}}

cross domain tracking

Remember to run AllowLinker and Auto-Links Domain the same way on all domains.


If you do not want the various domains to be referrals on Analytics you should enter them in the referral exclusion list by going to your Google Analytics account and then to:


Admin > Property> Tracking Info > Referral Exclusion List



referral exclusion list

Good luck!

© 2020 by Luca Tagliaferro. All rights reserved.