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 subdomains?

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 from sub domain are not counted twice.  That is the main challange we want to solve in this post. 

If a user starts a session on offer.ecomsite.com and then lands on ecomsite.com to complete the purchase we want to make sure that user is only counted once not twice by Google Analytics.

Similarly, most SaaS have a setup where app.saas.com is where the users login and saas.com 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 of 'auto’ which is default.

Google Analytics cookie domain auto in Google Tag Manager

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

gtm-configure-ga-tag
 

  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 page and click on 'inspect'
c) Click on 'console' tab and sarch for 'cid'
d) Click on a link within your page that will take user to the 'sub domain' or main domain
e) Clikc on 'inspect' on this page and search for 'cid'
The 'cid' should be the same on both your main domain and the subdomain

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 start gathering 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.

 
Related:
 

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

There are no comments

Post your thoughts

Recent post's