Cross Domain and Subdomain Tracking using Google Tag Manager

Cross Domain and Subdomain Tracking using Google Tag Manager

Many websites today are made up of several smaller sites, often with different domains and subdomains. Your organization may have a main www.example.com, along with blog.example.com, careers.example.com, or shop.example.com. You may also have distinct domains for different brands or campaign microsites, like goodexample.com or counterexample.com.

When it comes to configuring analytics tracking for your family of websites, proper handling of different domains and subdomains is critical to ensuring the quality of your data. Otherwise, you will have fragmented sessions, inflated metrics, and unattributable conversions.

If you are tracking multiple domains or subdomains in the same Google Analytics property, you must properly configure cookie settings, referral exclusions, and cross-domain tracking in order to connect a visitor’s session across domains. Luckily, Google Tag Manager makes subdomains and cross-domain tracking easy to implement.

Subdomain Tracking

Tracking across subdomains requires only a simple configuration, which you may already have enabled by default:

  1. In GTM, set the Cookie Domain field to auto.
    • This tells Google Analytics to set its cookie on the primary portion of your domain. Why is this important? Well, if you have www.example.com, shop.example.com, and blog.example.com, a cookie set on example.com will apply to all of them. This means that Google Analytics will be able to continue tracking a visitor no matter which subdomains they visit within their session.
    • The cookie domain is set to auto by default if you are using a Google Analytics Settings variable:
    • If you are not using a Google Analytics Settings variable, you should be! If however you need to quickly update an existing implementation, you can set cookieDomain to auto by adding a field under Fields to Set in your base Google Analytics page view tag:
  2. In Google Analytics, update the Referral Exclusion List.
    • Ensure that your primary domain is on the Referral Exclusion List (Admin > Select a Property > Tracking Info > Referral Exclusion List).
    • Adding the primary domain to the list (e.g. example.com) will also cover all subdomains. Alternatively, you can add each subdomain individually (e.g. www.example.com, blog.example.com, shop.example.com):

Cross Domain Tracking

Tracking across distinct domains with Google Analytics requires a few more steps, but can still be implemented through Google Tag Manager. The following should be done in your Google Analytics Settings variable (or within your base Google Analytics page view tag, if you are not using a GA Settings variable):

  1. Set the Cookie Domain to auto.
    • This ensures that GA will select the best domain for the cookie.
    • If you are using a GA Settings variable, the cookie domain is set to auto by default:
    • If you are not yet using a Google Analytics Settings variable, you can add a Field to Set which sets cookieDomain to auto on your base GA page view tag:
  2. Enable Cross-Domain auto-linking by entering a list of domains.
    • Enter a comma-separated list of domains into the Auto Link Domains field under the Cross-Domain Tracking section (e.g. example.com, goodexample.com, counterexample.com):
    • This tells GTM to transfer the GA cookie information between domains when the user clicks from one domain to another. This is what adds the _ga= parameter to the URL.
  3. Set the Allow Linker field to true
    • Add a field for allowLinker and set to true:
    • This enables GA to retrieve cookie information from the _ga parameter in the URL.
  4. Update the Referral Exclusion List in Google Analytics
    • In GA, you should ensure that all domains added to the cross-domain list in Step 2 above are also on the Referral Exclusion List (Admin > Select a Property > Tracking Info > Referral Exclusion List):
      Referral Exclusion List

Have you experienced issues with cross-domain tracking? Are your own domains showing up as referral traffic? Let us know in the comments below. We’re happy to help!

—–

Photo credit: Matt Wiebe, CC BY 2.0

By |2019-05-17T11:57:13-04:00November 22nd, 2017|28 Comments

28 Comments

  1. Elod January 22, 2018 at 4:10 am - Reply

    Hi, I have a blog on a different domain. Is it possible to measur it together? My website is “example.com”, and my blog is example.greatblogservice.com. Is it possible to use the above mentiones method to ttack these?

    • Marc Soares January 23, 2018 at 9:35 am - Reply

      Yes, you would need to implement the cross-domain tracking method described above.

  2. Adam January 28, 2018 at 8:59 pm - Reply

    We are definitely seeing self referrals. Our site is shoreline.edu
    We recently upgraded from the old legacy analytics (before universal) to the new Gtag.gs
    We installed the code manually into the head include file for our site and then on the various sub domains . When I look at our report – I see the referral is shoreline.edu and when I click on that referral , I see / as the top referring page. We have shoreline.edu in exclusion list.
    Would love any input you can provide.
    Thanks
    Adam

    • Heather Murphy January 29, 2018 at 1:29 pm - Reply

      Hi Adam,

      If you have recently upgraded from Classic GA to gtag.js, it is likely that you will still see self referrals in your reports. The Referral Exclusion List is a feature of Universal Analytics, and as such, the referral campaign may be persisting from before the upgrade. Campaigns have a time out period of six months, therefore we would expect the volume of self referrals to decline over time.

      A simple way to ensure self referrals are no longer an issue is to look at the number of new users – we would expect to see no new users with a self referral after the upgrade happened.

      Heather

  3. Adam January 29, 2018 at 2:48 pm - Reply

    Thank you Heather. One last question – do you advise we just deploy the universal snippet code from gtm if we plan on using that – instead of using the gtag.js snippet? or should we use the new gtag.js and then also use GTM to deploy our tags? I know there are benefits to deploying analytics tracking code using GTM – but not sure if it matters with the new gtag.js.

    • Heather Murphy January 30, 2018 at 10:04 am - Reply

      Hi Adam,

      If you are planning on using GTM, we would recommend deploying your GA code through here as well. A tag management system will allow changes to easily be made to your analytics configuration without needing to regularly modify code directly on your site.

      Thanks,

      Heather

  4. Anna February 21, 2018 at 3:15 am - Reply

    Hi! Thank you for addressing the topic of cross-domain and subdomain tracking.

    I have the following case: my main domain http://www.example.com and the subdomain http://www.blog.example.com are set up as different properties in GA. I am using Global Site Tag (gtag.js) tracking code for each property, and I have added the main domain to the Referral Exclusion List for the main domain property. I would like to track conversions (e.g. sign-ups) from traffic originated at the subdomain. So, my questions are:
    1. Will I be able to track conversions (e.g. sign up) from subdomains on my main domain property, if, in GTM, I set the Cookie Domain field to auto?
    2. Should I use UTM tracking code on my subdomain links, if subdomain tracking is set to “auto”?

    • Heather Murphy February 23, 2018 at 9:50 am - Reply

      Hi Anna,

      Thanks for your comment.

      Given your current set up, we would recommend modifying the Referral Exclusion List on the main domain property to include the prefix of www (i.e. www(dot)example(dot)com). With this specification, blog.example.com will be considered a referral to the main property. You will then be able to see blog referrals without needing to modify any settings in GTM, or using UTM tags.

      You may also wish to consider having an additional “roll-up” property, populated with data from both the main and sub domain. With proper subdomain tracking, having the two domains in the same property would allow you to more precisely track a user journey.

      Heather

  5. Anna February 27, 2018 at 1:58 am - Reply

    Thank you for your comment, Heather!

    so, if I add www(dot)example(dot)com) to the Referral Exclusion List in my main property, the other Subdomains (e.g. http://www.blog.example.com) will be considered as Referrals, and I will be able to track the visits and conversions from that subdomain, right?

    • Heather Murphy February 27, 2018 at 9:10 am - Reply

      Hi Anna,

      Yes – by specifying the www. in front of your primary domain on the Referral Exclusion list, you will be identifying that specific URL. Therefore, the blog. subdomain will be considered a referral.

      Heather

  6. Anna February 28, 2018 at 5:52 am - Reply

    Thank you Heather! You helped me a lot!

  7. liad June 7, 2018 at 3:52 am - Reply

    I’m using Gtag.js and currently my site vistors on mydomain.com first visit my site, then move to lpages.com and complete my form and then return to mydomain.com/thank-you. This is tracked in google analtics on both domains but referral exlclusion list isn’t working and lpages.com is being treated as the source of my traffic. how do i tell ga that lpages.com is my site too. i want GA to show me the true source of traffic.

    • Heather Murphy June 8, 2018 at 10:47 am - Reply

      Hi Liad,

      Thanks for your comment!

      If you recently added lpages.com to the Referral Exclusion List, it is possible that individuals are returning directly, and the campaign is persisting – GA campaigns have a 6 month timeout by default. You can look at “New Users” with this campaign to confirm.

      Alternatively, have you confirmed that the Cookie Parameters are being appended as expected between domains? You may need to turn on “Decorate Forms” in the Cross Domain Tracking settings, assuming it is a standard form submission.

      Heather

  8. Ronald June 7, 2018 at 10:47 pm - Reply

    Hi Heather,

    Would really appreciate some help as I am needing to cross-domain across various properties with a mixed GTM and GA snippet implementation and have never had to do do it on messy implementation across a silo’d organisation. Some properties are a different domain, others are subdomains managed by other business units with separate direct GA implementations. So here are my questions:

    1) Even though some sites are subdomains, they are separately hosted from the main domain and have their own GTM or GA implementation. Do I then just follow the cross-domain instructions in addition to the subdomain instructions?
    2) OR, subdomain instructions are sufficient?
    3) as we have a multitude of subdomains that do not have tracking implemented (not required), but still has users traverse through them, should I be explicitly declaring each subdomain in each properties referral exclusion list instead of just the main domain?

    Thanks in advance.

    • Heather Murphy June 8, 2018 at 5:31 pm - Reply

      Hi Ronald,

      Cross-domain tracking is only effective if all domains are tracked in the same GA property. Assuming this, you will need to set up the cross domain tracking in each GTM containers.

      When following the cross-domain instructions, you can declare the primary domain (ex. mysite.com) in the list of domains, which will cover all subdomains. It is not an issue that they are separately hosted. If you wish to link only some of the subdomains, however, you will need to declare each subdomain in your list of domains to auto-link (ex. http://www.mysite.com, subdomain.mysite.com, …).

      Similarly, you will want to put the primary domain, or each individual subdomain in your Referral Exclusion List depending on how you want to treat the non-tracked sites.

      Cross-domain tracking set up in GTM will not apply to the sites that have a hard-coded GA implementation. Both the cookie domain and autolink settings will have to be hard-coded in the GA snippets.

      Heather

  9. Ronald June 10, 2018 at 9:10 pm - Reply

    Thanks for clarifying Heather. Unfortunately, the way the organization is structured (University/College), different teams have complete ownership of different domains and each one is structured completely differently to the main site as they are purpose specific, ie. some are student/study portals, some are course registration pages. This is also the reason why some are in GTM, and others in GA.

    But just to be 100% on your advice above, this is a representative scenario of what we have going on.. it is not best practice and it won’t be fixable/consolidatable anytime soon…

    http://www.maindomain.com (Account 1, GA Property 1 via GTM)
    subdomain1.maindomain.com (Account 2, GA Property 2 via GTM)
    subdomain2.maindomain.com (Account 1, GA Property 3 via GTM)
    http://www.otherdomain1.com (Account 1, GA Property 4 via GTM)
    http://www.otherdomain2.com (Account 3, GA Property 5 via GTM)
    subdomain3.maindomain.com (Account 4, GA Property 6 via direct GA Snippet)
    subdomain4.maindomain.com (Account 4, GA Property 7 via direct GA Snippet)

    As for the gtm / ga implementations not cross-domaining… I was under the impression this would all work if the additional config settings in GA snippet (linker,domains,accept_incoming, decorate_forms, etc) were identical to the GTM equivalent of GA Settings variable (cookie domain, allowLinker field, autolink domains, decorate forms, etc)?

    • Heather Murphy June 11, 2018 at 3:59 pm - Reply

      Hi Ronald,

      Cross-domain tracking unifies a users journey across different sites, allowing you to see how they navigate between these sites within the same session. That being said, if the sites are in different GA properties, GA does not allow you to view these as the same session.

      The paid version of GA, Google Analytics 360, would allow you to create a roll-up property between these different properties. Without 360, we would recommend creating another GA property, and deploying this across all assets, effectively creating your own ‘roll-up property’. With the proper settings, you would then be able to see the full user journey across sites.

    • Ronald June 12, 2018 at 8:46 pm - Reply

      Thanks for all the clarification Heather. This public conversation trail may be what I need to get things fixed properly.

  10. abdul July 31, 2018 at 7:47 am - Reply

    does this work with the following example:

    subdomain1. example . com > subdomain2. example . com > then go back to subdomain1.example . com/welcomepage

    is this trackable? to track conversions (Sign ups). is your method mentioned above applicable for this example. please help

    • Heather Murphy July 31, 2018 at 10:13 am - Reply

      Hi Abdul,

      Yes, the subdomain tracking would be applicable in this particular scenario!

      Heather

  11. Kamil September 5, 2018 at 1:05 am - Reply

    Hej. Can you show more detail where is it in google analytics? I don’t seethe option to set up cookiedomain.

    • Heather Murphy September 5, 2018 at 9:59 am - Reply

      Hi Kamil,

      If you are using GTM, the setting for cookieDomain will be set on the pageview tag, or set by default if you are using a GA Settings Variable.

      The only configuration required in Google Analytics is updating the Referral Exclusion List.

      Heather

  12. Peter Graber October 24, 2018 at 3:40 pm - Reply

    Here’s my simple scenario: xxy.domain.com => http://www.domain.com/xyz via a directive in a vhost.conf file. I have many many many sub-domains.

    Using Universal GA.

    How can all redirects from various sub-domains be counted individually?

    • Heather Murphy October 25, 2018 at 11:00 am - Reply

      Hi Peter,

      In your scenario, adding subdomain tracking to your analytics implementation will not be beneficial.

      You may consider adding an additional query parameter to your redirected URL to be able to differentiate the redirect in Google Analytics.

      Heather

  13. Peter Graber October 25, 2018 at 2:12 pm - Reply

    Heather — Thank you so much for quick response!!! All examples I’ve seen hadn’t covered by scenario. Really appreciate your insight.

    For parameters, I assume you mean GA Custom Campaign parameters. Do you mean something like this in term of redirect URL (:

    https://www.domain.xyz/page?utm_source=vhost&utm_medium=all&utm_campaign=campaign_name

    • Heather Murphy October 26, 2018 at 11:15 am - Reply

      Hi Peter,

      GA Custom Campaign parameters would work, yes. Do consider how you would like to classify this campaign, and any other impacts this may have on your implementation.

      Alternatively, you could also test adding a non-UTM parameter (eg. http://www.domain.com/xyz?vanity) depending on your needs.

      Heather

  14. Mrinal Mondal January 10, 2019 at 7:39 pm - Reply

    This article was amazing and informative! Thank you so much

Leave A Comment