Search code examples
google-analyticssubdomaingoogle-tag-manageruniversal-analytics

Sub-domain tracking with Google Tag Manager


I'm trying to set up tracking with GTM between the main domain and its subdomain. I've read a lot on this topic already, including this Google guide (it's about different domains but not sub-domains) and guide from Lunametrics. But still I can't find the answer.

So what I have now:

  1. site.com and blog.site.com
  2. Two separate containers for each of them
  3. Two different properties in Universal Analytics.

What I need is tracking the domain with it's subdomain. I assume I'll need to create a separate view with filters in GA. Please let me know how to configure that tracking right. I wouldn't like to use one single container for the domain and its subdomain.


Solution

  • What you need is a single property. Implement the same code on domain and subdomain.

    Set the cookie domain to "auto" (or do not set it all). This means the Google code sets the cookie for the highest accessible "level" from the domain (i.e. Google cannot set a cookie for the .com TLD, so it will use the next level, in your example site.com). It also means the cookie is available on the subdomains for your url.

    That's basically it - your property will report users from domain and subdomain and will maintain the session when they switch between domain and subdomain.

    However if you have pages of the same name on both domain and subdomain - say site.com/index.html and blog.site.com/index.html - they will be lumped together in the reports. To separate them you can set the hostname as second dimension, or apply a filter to your data view that adds the hostname to the url path (here is randomly googled tutorial on how to do this).