One of our clients created an application located on the subdomain app.theirwebsite.com. On their main website, theirwebsite.com, they had multiple links to the application on the subdomain. Although we installed the same tracking code on both the main domain and the subdomain, Google Analytics recorded traffic for those website as traffic to two separate websites.

The problem was that the Google Analytics cookies were not shared between the main domain and the subdomain. Luckily, this problem was easy to solve: both on the main domain and the subdomain we needed to set the cookie domain to .theirwebsite.com (the starting dot is very important). This way the cookies are shared between the website and the application on the subdomain.

Note: When you use one or more of the methods described below, you need to apply it to every tag used on the main domain or subdomain. If you mix cookie domains both with and without the dot, your sessions may become lost during a visit, resulting in incorrect numbers in your analytics.

If you’re using Asynchronous syntax, you can add the following line to your tracking code on both domains:

_gaq.push(['_setDomainName', '.theirwebsite.com']);

If you’re using Google Tag Manager and your tag type is Classic Google Analytics, you can use the following steps:

subdomainswithGA2

If your tag type is Universal Analytics in Google Tag Manager, you can use the following steps:

subdomainswithGA3

The last thing you need to do when you’re using Universal Analytics (whether or not you’re using the Google Tag Manager), is to add referral exclusions. You can do this in the following steps:

subdomainswithGA4

Once you’ve completed the steps above, visits to your subdomain should be tracked the same way as visits to your main domain.

written by David Peeters

Tags: