Semetis Power Tip: Tracking subdomains with Google Analytics | Articles

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:

    • Click the tag name to go to the tag editor.
    • Click More settings to open the menu
    • Click Domains and Directories
  • Check Domain Name and enter a dot, followed by the main domain name in the text field:

subdomainswithGA2

    • Click Save
  • Repeat these steps for all tags, both on the main domain and the subdomain. From now on, a visitor starting their visit on theirwebsite.com will still be recoginized as the same visitor when they go to app.theirwebsite.com.

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

    • Click the tag name to go to the tag editor.
    • Click More settings to open the menu
    • Click Cookie Configuration
  • Enter a dot, followed by the main domain name in the Cookie Domain text field:

subdomainswithGA3

    • Click Save
  • Repeat these steps for all tags, both on the main domain and the subdomain.

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:

    • Log in to Google Analytics
    • Go to the website and click Admin
    • Go to Tracking Info - Referral Exclusion List
    • Click + Add Referral Exclusion
  • Type the sub domain:

subdomainswithGA4

  • Click Create

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:

Get in touch

Semetis | Rue de l'Escaut 122, 1080 Brussels - Belgium

welcome@semetis.com

Connect with us

Cookie Policy

This website uses cookies that are necessary to its functioning and required to achieve the purposes illustrated in the privacy policy. By accepting this OR scrolling this page OR continuing to browse, you agree to our privacy policy.