Back to blog

Google Analytics Sub Domain And Cross Domain Tracking Explained

Gravatar Alauddin Ahmed wrote this on Aug 10 / 0 comments

Google Analytics cross-domain or sub-domain tracking explained

Have you been researching how best to set up Google Analytics for your SaaS or ecommerce site where you are using sub-domains?

Well, this post is simple.  We will address these two very specific use cases. 

Google Analytics Setup for SaaS and basic E-com sites with sub-domains!

In most cases, a business is using sub domains and not actually two separate domains. Hence, the goal is to make sure that users coming from sub-domain are not counted twice. That is the key challenge we want to solve in this post. 

If a user starts a session on and then lands on to complete the purchase, we want to make sure that user is viewed as a same user by Google Analytics and not as two different users.

Similarly, most SaaS have a setup where is where the users login and would be their marketing site.

In all the above use cases, we are using a sub domains, and not a new separate domain.

Now, after much research, here is what I found regarding sub domain tracking.

google analytics sub-domain tracking auto cookie

Yep, per Julian from Measure School,

"Technically, you don't need cross-domain tracking (for sub-domains), just make sure your auto cookie setting is true"

You need not do much of anything if you are using Google Tag Manger to fire off your Google Analytics.  

If you are still using plain old JavaScript code directly from Google Analytics - STOP.   It is time to get Google Tag Manager and make your life easier.

Using GTM, for sub-domain tracking you just need to make sure you have these things in order.

  1. Inside GTM - Create a Google Analytics Variable

Google Analytics Variable In Google Tag Manager


  1. Inside GTM - Make sure the Google Analytics Variable has Cookie Domain setting ’ which is default.

Google Analytics cookie domain auto in Google Tag Manager

  1. Inside GTM - Configure Tag to fire on all pages.


  1. In Google Analytics - add main domain to Referral Exclusion List (no sub-domains)

Google Analytics Referral Exclusion List

  1. Test - Use Chrome Tag Assistant to check the GTM and Google Analytics codes are firing and use GA Debugger to see session is maintained across sub-domains.

If you have implemented the above steps in your Tag Manager and are firing off the GTM code on your main and all sub-domains, the Chrome Tag Assistant will look something like this.

google chrome - tag assistant and debugger

Here is how to test if the userid stays the same across all your sub-domains and the main domain. 
Click on
a) GA Debugger extension to turn it on
b) right click on the page and click on 'inspect'
c) Click on 'console' tab and search for 'cid'
d) Click on a link within your page that will take user to the 'sub domain' or main domain
e) Clik on 'inspect' on this page and search for 'cid'
The 'cid' should be the same on both your main domain and the sub-domain

google analytics debugger client id check

Basically, we want to check if the user session is tracked as one user and not two if you hop from one sub-domain to another.

Yep.  that is all you need to gather accurate data if your use case involves sub-domains!

Cross-domain Tracking!

Now, if the sub-domain use case does not apply to you and you have two unique domains and need to combine your Google Analytics into one account, here is the best video I found on Cross-domain Tracking with GTM by Julian from Measure School that will walk you through the setup.


ALAUDDIN AHMED WROTE this on Aug 10 There are 0 COMMENTS.

There are no comments

Post your thoughts

Recent post's