• Courses
    • Courses
    • Course bundles
  • Blog
  • Services
  • Resources
    • Youtube channel
    • E-books and Guides
    • GTM Recipes
    • View All Resources
    • GTM Community
    • GA4 community
  • About
    • About
    • Contact
  • Login
  • Courses
    • Courses
    • Course bundles
  • Blog
  • Services
  • Resources
    • Youtube channel
    • E-books and Guides
    • GTM Recipes
    • View All Resources
    • GTM Community
    • GA4 community
  • About
    • About
    • Contact
  • Login

March 13, 2020

Subdomain Tracking with Google Analytics and Google Tag Manager

Note: In July 2023, Universal Analytics stops working. It is no longer recommended to do new implementations with Universal Analytics (GA3). Use Google Analytics 4 instead. GA4 also automatically handles subdomains.

If you are working with a business that operates on multiple subdomains (e.g. blog.business.com, support.business.com, www.business.com, etc.), you will most likely want to track website visitors with Google Analytics across all these websites.

If yes, what kind of configurations do you need to have a proper setup? The good news is that this is usually much easier to implement than cross-domain tracking. But nevertheless, there are several things to keep in mind.

In today’s blog post, I’ll show you how to implement subdomain tracking with Google Analytics and Google Tag Manager.

 

Table of Contents

  • Before we start: Subdomains DO NOT require cross-domain tracking
  • Subdomain tracking with Google Analytics and Google Tag Manager: The Short Version
  • Subdomain tracking with Google Analytics and GTM: The Long Version
  • It’s all about the cookie
  • #1. cookieDomain parameter
    • #1.1. Universal Analytics (analytics.js)
    • #1.2. gtag.js
    • #1.3. Google Analytics via Google Tag Manager
    • #1.4. Check the actual cookie and its domain
  • #2. You must use the same GA property across all subdomains
    • #2.1. What about VERY large businesses?
    • #2.2. What about the GTM container?
    • #2.3. How do you decide which subdomains should be tracked in a single GA property?
  • #3. Check the referral exclusion list
  • #4. Showing full URL in your GA reports
  • Bonus: Create a GA view just for a particular subdomain
  • Test the entire implementation
  • Subdomain Tracking with Google Analytics and GTM: Final Words
Subscribe and Get the Ebook - Real Book Img - GTM for Beginners

Before we start: Subdomains DO NOT require cross-domain tracking

Sometimes I see forum threads or chats where people are asking how to implement cross-domain tracking for their project/websites when it turns out that the business operates on a single domain (just different subdomains).

So before we dive deeper into the actual details, here’s a public social announcement:

YOU DO NOT NEED CROSS-DOMAIN TRACKING FOR SUBDOMAINS OF THE SAME DOMAIN

If you are dealing with subdomains like:

  • www.example.com
  • blog.example.com
  • support.example.com

Then you DO NOT need to implement cross-domain tracking because all of them belong to the same example.com domain

However, you WILL HAVE to implement cross-domain tracking if you’re working with separate domains, e.g.:

  • www.mainwebsite.com
  • blog.example.com
  • support.someotherdomain.com

And that’s about it. Now, let’s move to the subdomain tracking with Google Analytics.

 

Subdomain tracking with Google Analytics and Google Tag Manager: THE SHORT VERSION

There are several things to check/configure (and keep in mind) while tracking subdomains with Google Analytics. Let’s start with the short version (for those who are in a hurry). If you find some tips confusing, please read the long version).

1. First, configure/check the settings of cookieDomain parameter (set it to auto). By default, Google Analytics Settings Variable in GTM already uses that.

2. Then you will need to make sure that you use the same GA tracking property across all subdomains you are interested in.

3. You will need to add your main domain to the GA referral exclusion list. Go to GA Admin > Property Column > Tracking Info > Referral Exclusion List > Add Referral Exclusion. Enter your top domain there (if it isn’t there already).

4. Finally, you will need to (optionally) implement the Show Full URL filter in the GA view. This way, you will see both the Domain and the Page Path in your reports.

Go to GA Admin > A view where you want to implement this > Filters and create the filter with the configuration displayed in the screenshot above. In the long version of this blog post, I’ll show the settings in a bit greater detail.

 

 

Subdomain tracking with Google Analytics and GTM: THE LONG VERSION

Now, let’s move on to the longer version with a thorough explanation.

 

It’s all about the cookie

Google Analytics tracking is based on first-party cookies. Whenever a visitor lands on a page, the Google Analytics tracking snippet is activated on a page that stores a cookie (called _ga) with a randomly generated ID.

When you continue browsing the website, GA keeps checking that cookie. If it exists, GA reuses the ID from that cookie and then understands that you are the same person who has just made a page view a couple of minutes ago.

If you return to the website and still have that _ga cookie, GA will continue to use that.

However, if the cookie is not present (or is not available for that particular domain (or subdomain), then a new _ga cookie will be created.

I highlighted several words in the previous sentence for a reason.

You see, it is possible to set a cookie just for a particular subdomain. In that case, only that subdomain (and subdomains of that subdomain) will be able to access the cookie. This can also apply to the _ga cookie.

Here’s an example of a cookie that is set for all .example.com. This means that any subdomain of example.com will be able to access that particular cookie.

Subdomain Tracking with Google Analytics

 

However, if the _ga cookie is created only for demo.example.com, then its value can be accessed only by:

  • demo.example.com
  • v1.demo.example.com (or any other subdomain that is on the lower level of demo.example.com)

But www.example.com will NOT be able to access the cookie (because www and demo are different subdomains of the same level).

But don’t worry. This limitation can be easily circumvented with a setting called cookieDomain in Google Analytics.

 

#1. cookieDomain parameter

If you want to track the same user across multiple subdomains that belong to the same business, the cookieDomain parameter is exactly what you need.

If that parameter is set to auto, GA will always set the _ga cookie on the main domain, for example, if a visitor is browsing support.example.com,  then the cookie will be set on .example.com). This means that any other subdomain of example.com (e.g., www.example.com or blog.example.com) will be able to access the same cookie and reuse it for tracking.

How can you know whether cookieDomain is set to auto? The answer depends on how your Google Analytics is implemented on a site.

 

#1.1. Universal Analytics (analytics.js)

If your website is using the older version of Google Analytics tracking code (a.k.a. analytics.js), then the code snippet (that must be added to a site) might look like this (this is the default snippet):

<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->

Take a look at this line:

ga('create', 'UA-XXXXX-Y', 'auto');

See the “auto”? That means that the cookieDomain parameter is set to auto.

If you see it, you’re all set. This means that the _ga cookie will be set on the main domain. If instead of “auto”, you see “.maindomain.com” (obviously, this is just an example and I meant the “main domain”), then this will also work. This means that the cookie will be set on the main domain and all subdomains will be able to access it.

If, on the other hand, instead of “auto” you see an exact subdomain, like “www.example.com“, this means that a cookie will be set only on that particular subdomain and other subdomains of the same level will not be able to access it.

If you have added the analytics.js snippet a long time ago and didn’t do any modifications, most likely, your setup is ok (regarding the _ga cookie). Nevertheless, you should still check that.

 

#1.2. gtag.js

If you are using the newer version of Google Analytics tracking code (a.k.a. gtag.js), then you should be ok. By default,  gtag.js has automatic cookie domain configuration enabled. When enabled, gtag.js will set cookies on the highest level domain it can.

However, there is still a possibility to limit cookies to just a particular subdomain with a parameter called cookie_domain. Here’s an example:

gtag('config', 'GA_MEASUREMENT_ID', {
   'cookie_domain': 'blog.example.com'
});

In this case, the _ga cookie will be set on blog.example.com. If you see this, have a discussion with your webmaster/developer and ask to remove that parameter.

 

#1.3. Google Analytics via Google Tag Manager

By default, Google Analytics (implemented via GTM) DOES NOT have a cookieDomain set to auto. Meaning that if you just fire a regular pageview tag, the cookie will be set just for that particular subdomain.

However, it can be easily solved by adding a cookieDomain field set on at least one tag on a page (Pageview tag is your best bet) and setting its value to auto.

If you are using a Google Analytics Settings Variable (recommended), then you will see that the variable (most likely) already contains the cookieDomain field set to auto. That’s because every time you create a new GA Settings Variable, it contains that configuration by default.

If you are working with an older GTM/GA implementation (pre-2017), then you will definitely need to check whether cookieDomain is set to auto.

If you want to learn more about the cookieDomain settings and how different settings affect your tracking, you can read this guide by Simo. Also, feel free to check the official GA documentation here and here.

 

#1.4. Check the actual cookie and its domain

You can also go to the Developer Tools of your browser and check the domain of the _ga cookie there. I’ll show the example with Google Chrome. Go to the browser’s menu (click three vertical dots) > More Tools > Developer Tools.

Then go to Application > Cookies > Choose your website’s domain.

Finally, in the search field, enter “_ga” (without quotation marks) and you will find all the cookies with that name that are stored from your website in your browser.

In the Domain column, you will see on which domain’s (or subdomain’s) behalf was the cookie stored.

Note: you might see multiple different domains. This happens if 3rd party tools installed on your website use their own Google Analytics tracking code to track their own usage.

Back to the domain.

If you see, for example, .mydomain.com, this means that ALL subdomains of mydomain.com will be able to access that cookie. That’s what you need.

If you see www.mydomain.com, then the cookie can be accessed by the tracking code that is implemented on www.mydomain.com, dev.www.mydomain.com, and other sub-sub-domains that belong to the www.mydomain.com.

 

#2. You must use the same GA property across all subdomains

If you want to track how visitors are behaving on your online ecosystem (across multiple subdomains), you will need to use the same property for all subdomains.

It does not matter what domain or subdomain have you entered in the GA Property’s settings:

What matters is that your subdomains are sending data to the same bucket, a.k.a. property. If you want to split that traffic later (in your reports) based on a subdomain you might want to create separate GA views for each subdomain.

 

#2.1. What about VERY large businesses?

However, just like the majority of situations we do, there are some “it depends” moments.

If you are working with a huge project where there are hundreds of subdomains, 25 GA views will not be enough for you (because that’s the limit).

If you plan to have multiple subdomains as separate properties in Google Search Console and then try to connect them with your single Google Analytics property, you will hit the wall. Why? Because you can connect only one GSC property with a Google Analytics property.

At least for now, you cannot connect multiple GSC properties with a single GA property. And that’s a bummer.

What’s the solution? One of the possible things could be tracking each subdomain as a separate GA property and then also duplicating hits to another (master) GA property. That way each subdomain will be isolated but you will still have an opportunity to have a rollup view of what is happening.

Simo has written a guide on how to duplicate hits and send the info to a rollup property. Read that guide very carefully as there are multiple gotchas you need to be aware of.

Google Tag Manager Ebook Bundle

#2.2. What about the GTM container?

Should you use the same for all subdomains? Or should you create different containers for each subdomain?

The answer is: it does not matter. Your GTM account and container structure have no direct impact on subdomain tracking in Google Analytics.

Here is my rule of thumb:

  • If you have multiple subdomains and all those websites are VERY similar, you can use a single GTM container for all of them.
  • If your websites on those subdomains are quite distinct and serve different purposes (e.g. a blog, the main website, a support center, etc.), then I would recommend using separate GTM containers.

However, once again I’d like to emphasize this — what matters is that data must be sent to the same GA property if you want to track the same people across multiple subdomains. So, if you have multiple GTM containers, all of them must send the data to the same GA property. Simple as that.

If you are still not sure about how many GTM containers you need, read this guide.

 

#2.3. How do you decide which subdomains should be tracked in a single GA property?

Answer this: do you want to see your visitors of an X subdomain in your GA reports together with other subdomains? If yes, then you need to track that subdomain in the same property.

That’s it. We have just decided that together with you 🙂

 

#3. Check the referral exclusion list

Usually, this is already configured properly when you create a new property in GA but it’s still a good practice to check.

First of all, a quick reminder (or maybe a lesson?) about what a referral exclusion list is.

Google Analytics tracks traffic sources based on various parameters, such as UTM tags, gclid parameter in the URL or a document.referrer (a.k.a. Referrer).

Let’s focus on a Referrer for now. Its purpose is to show the URL of the previous page. Sometimes it might show the full URL, sometimes just the domain, and sometimes be empty (depends on website’s and browser’s configuration).

If a visitor is browsing the web and navigates from one website to another, Google Analytics will check whether the domain has changed. If a domain was example.com and now I’m on a mybusiness.com, the value of the Referrer will contain example.com (but sometimes even that info is stripped (depends on browsers, websites, etc.).

Since the referrer’s domain is different from the website’s domain that I’m currently on (mybusiness.com vs example.com), GA starts a new session (because the traffic source has changed).

However, subdomains can also be treated as a distinct traffic source (because the domain of the previous page might be blog.mybusiness.com and my current page’s domain might be www.mybusiness.com).

blog.mybusiness.com is different from www.mybusiness.com.

And that usually, is not a good thing — you’ll end up with seeing self-referrals in your GA Acquisition reports.

Anyway, by default, Google Analytics handles this issue fairly easily if you entered the correct info in your Property’s settings when the property was created. Why? Because that domain is added to your referral exclusion list.

A referral exclusion list informs Google Analytics that if a visitor came to your site from XXX domain, this will not be treated as a traffic source and will be turned into a (direct) session. If the visitor already has an active GA session, it will be continued.

In your GA account, go to the Admin and in the Property column, go to Tracking Info > Referral Exclusion List.

What should you expect here? There might be one domain or there might be multiple domains entered there. That depends on your website’s ecosystem, payment gateways you use, etc.

However, if your main domain is, say, mybusiness.com, then the very same domain should be entered in the Referral Exclusion List.

Referral Exclusion List matches domains with as CONTAINS. So if a visitor comes from another domain (or subdomain) that contains mybusiness.com, that hit’s traffic source will be treated as (direct), therefore, you won’t be facing self-referral issues.

There is no need to enter each subdomain separately here. Just enter your top domain and that will cover all subdomains.

 

#4. Showing full URL in your GA reports

If you have followed all the tips above, you should now be seeing data flowing into Google Analytics from different subdomains.

However, if you haven’t done any URL manipulations with GA filters, it will be tough to identify from which subdomain did the hits come.

For example, if you go to your Content reports (Behavior > Site Content > All Pages), you will just see Page Paths but not the subdomain.

Of course, you can add a secondary dimension Hostname to see but workaround takes away the possibility to add some other meaningful secondary dimension in standard reports.

I would much rather see the domain (subdomain) together with the Page Path. Luckily, that is possible with a GA View Filter. We’ll configure it to show the full URL.

In GA Admin, go to Filters (in the View column) and enter the following settings:

  • Filter Type: Custom filter > Advanced
  • Field A: Hostname
  • Extract A: (.*)
  • Field B: Request URI
  • Extract B: (.*)
  • Output To: Request URI
  • Constructor: $A1$B1

From the moment you save this filter, it will take the Page Hostname of every request that is sent to GA and combines it with the Page dimension. Then the result is stored in GA as a Page dimension.

WARNING: this will NOT fix your past data. Your historic data will remain without a hostname, therefore, the sooner you implement the Show Full URL filter, the better.

 

 

Bonus: Create a GA view just for a particular subdomain

If you want to see the data only of a particular subdomain in your GA reports, one of the options is to create a separate GA view for that.

To do that, go to Google Analytics Admin and press Create View, enter all the information that is required.

Then (in that very same view) go to Filters and enter the following configuration:

  • Filter type – Predefined
  • Include only
  • Traffic to the hostname
  • That are equal to
  • subdomain.yourdomain.com (obviously, you need to enter your actual subdomain)

 

Test the entire implementation

Now, it’s time to test. If you implemented everything as I have explained above, this is the scenario you should test.

First, I would suggest copying the current GA view (where all the subdomain data should be gathered) and create a new filter “Include – my IP”(it’s like this one — but you need to INCLUDE you IP). Or you could just use the Test view if you have one.

When you do that, open GA real-time reports.

Browse your websites, navigate between subdomains.

You should be seeing only one active user — yourself. If you are browsing from the company’s IP address, most likely, you will see multiple people (your coworkers). Then you can try adding “?testing=true” (without quotation marks) to the URL of each page. That way, you will be able to identify yourself in the real-time reports.

Your goal here. You should see only one person who is browsing the page where the URL contains “?testing=true”. Just keep in mind to manually add that parameter to every pageview. I tried testing with UTMs in the URL (to isolate myself if traffic medium is “testing”) but real-time reports deal badly with traffic source debugging.

After you have isolated yourself in reports, if you see two users, something is incorrect. Re-read my guide once again. If you don’t see yourself on a particular subdomain, most likely, that subdomain is sending data to another GA property.

You can also check whether the _ga cookie has the same value on all subdomains (check Application > Cookies > yourdomain) in Chrome Developer tools. If you are using a different browser, you’ll need to find a way on your own. I have mentioned developer tools in greater detail in one of the above chapters.

If everything is OK, you can then check the non-test GA view by applying the same “?testing=true” technique.

 

Pro tip: don’t tag links between your subdomains with UTM parameters

Sometimes, I see people tagging links on their blog (e.g., blog.example.com) that redirect to their main website (www.example.com) and those links are marked with UTM parameters (e.g. www.example.com?utm_medium=referral&utm_source=blog&utm_campaign=blablabla).

This is a bad idea because if the visitor clicks this link, Google Analytics will start to track a new session. So if someone landed on your blog from Google Search, then went to a site and signed up/converted, your traffic source report in GA will attribute that conversion to your blog, not the Organic traffic.

Also, your session metrics will be very inaccurate.

 

Subdomain Tracking with Google Analytics and GTM: Final Words

Looks like we’ve reached the end. Here are the key takeaways from this blog post:

  • If you are tracking visitors on different subdomains but they all belong to the same main domain, you DO NOT need to implement Cross-domain tracking.
  • Make sure that your cookieDomain value is set to “auto” or at least to “.yourdomain.com” (that should be replaced with your actual domain). That way, all subdomains will have access to the same _ga cookie.
  • Use the same GA property for all subdomains. Or at least have a rollup property implemented.
  • Make sure that your main domain is entered in the Referral exclusion list
  • Implement the Show Full URL filter in the GA view where you want to check the data coming in from various subdomains.

Even though this is much simpler than Cross-domain tracking implementation, there are still some nuances. If you just skimmed the content and landed at the end of this summary, I suggest you scroll up and read the longer version.

Any questions? Is there anything missing? As always, the comment section is at your service.

Google Tag Manager Ebook Bundle
Julius Fedorovicius
In Google Analytics Tips Google Tag Manager Tips
58 COMMENTS
Amber Kim
  • Mar 14 2020
  • Reply

My company’s GA has different properties for each subdomain now, and all implemented by GTM. If i create one property for all subdomain using GTM as well as using existing separated ones. Do you think it’s a good idea?

    Julius Fedorovicius
    • Mar 14 2020
    • Reply

    It's totally doable. You'll need to duplicate hits. One hit to subdomain property and the same hit to the property for all subdomains. I've mentioned this solution in this blog post.

Aliaksei
  • Mar 15 2020
  • Reply

Hi Julius! Great article and I would like to ask a small question.

I guess it is possible to install subdomain tracking without GTM, isn't it? But how to setup cookies to auto in this case (I mean in Analytics)?

Thanks in advance!

    Julius
    • Mar 15 2020
    • Reply

    Of course. Read the chapter about how to identify whether cookieDomain is seto to auto (universal analytics and gtag). That is all you need to do.

Michael Chiaro
  • Apr 6 2020
  • Reply

This post was very helpful. Thanks for all the great information.

I have one domain with several subdomains, all with the same UA code implemented. I followed the blog post and am experiencing one problem....if I use a hostname filter in order to see the data from one specific subdomain, the URLs DISPLAY correctly in the report but when I click on the icon to take me to the actual page, the link is broken. The report links to the page as if it was part of the domain rather than a page from the subdomain.

Thanks for any help you can provide!

    Julius
    • Apr 6 2020
    • Reply

    Yes, those links will get broken. That is a sacrifice you need to make in order to see convenient data in your reports. Not a big deal.

john
  • Apr 30 2020
  • Reply

Very helpful post. I followed your post and URLS display correctly in the report but when I click on the icon to take me to the actual page, it shows me a double URL.
ex example.comexample.com
example.comexample.com/abc
example.comblog.example.com

Looking forward to hearing from you. Thanks in advance.

    Julius
    • Apr 30 2020
    • Reply

    This is the price you pay for the "show full url" filter. No fix for this.

Marko
  • May 10 2020
  • Reply

Hi Julius!
Thanks for sharing this super post. It's very helpful :)
I would like to share a problem which is freaking me out.
I've created two subdomains and each one has its own ID track, also two containers in TM with their triggers and tags. But I have a problem, I don't know why, a user is registered in Analytics only when he does an action which I set up in TM, not when he arrives. What do you think is happening?
Thanks for your help and time.
Marko.

    Julius
    • May 10 2020
    • Reply

    I don't understand your question. Please elaborate.

      Marko
      • May 10 2020
      • Reply

      Sorry Julius, I'll try to explain it better.
      The problem is I only registered visitors in my GA subdomains when they make an action which I set up in Tag Manager: register, click a button, scroll and so on. So I don't register traffic that only visit my page.
      Have you experienced a similar problem before?
      Hope that is more clearer
      Thank you for helping me.
      Marko.

        Julius
        • May 10 2020
        • Reply

        Sounds like you haven't implemented GA pageview tag or it is not firing properly. That is all.

    Marko
    • May 10 2020
    • Reply

    I also want to add that I thought that the problem could be due to cookie implementation and I've trying to change my cookie domain set as auto with the name of subdomain, but it didn't have any effect.
    Thanks again for your post and time.
    Marko.

Pablo
  • May 13 2020
  • Reply

Hi there! Nice article, I was actually wondering if I have to use the same gym code in every subdomain I'll use.

    Julius
    • May 13 2020
    • Reply

    Hi, that does not matter

      Joshua Haire
      • Aug 1 2022
      • Reply

      Hi Julius,

      I am implementing GA4 for a client and know that GA4 "automatically" collects traffic from subdomains. However, the subdomains are explicitly tracked using different GTM containers and different GA4 measurement IDs. Even though they are using different GTM snippets on the site, the cookie for the domain will track across regardless, if I am reading this right?

Andrea
  • May 14 2020
  • Reply

Hi,

This post is very useful.

Two questions for my use case

mydomain.com
blog.mydomain.com

1) "#1. cookieDomain parameter"

If I understood it correctly, I shouldn't add the tracking code of my GA domain in the head code of my subdomain, correct? I have GTM with cookie domain "auto"

2) " #1.4. Check the actual cookie and its domain"

I checked the _ga cookies at my subdomain (blog.mydomain.com) as you described but I have listed the ga cookie twice with different info for the same domain. What does imply?

(cookie) Name
_gat_UA-xxxxxx-x
_ga

Value
1
GA1.2.XXXXXXXX

Domain
mydomain.com
mydomain.com

Any help would be much appreciated. Thank you!

Bartu Isiklar
  • May 20 2020
  • Reply

Hi Juilus,

Thank you for the great article. I am having a problem and i would be very appreciate if you could help me.
I have a website and a test domain (www.example.com and test.example.com) I have created a new view for my test domain and also created a filter which you have mentioned on "Bonus" part but i still can not see any active users on my test site, even though i am on that test domain. What could be the problem here? Can you please help me.

Thanks a lot,
Bartu.

    Julius Fedorovicius
    • May 20 2020
    • Reply

    Many possible problems, like:
    - you are sending data to the wrong GA property
    - you have some other filters
    - that view has User-ID features enabled

    Keep digging https://www.analyticsmania.com/post/google-analytics-real-time-reports-not-working/

Carl
  • May 29 2020
  • Reply

Hi Julius,

I was wondering, is there a way to exclude self-referrals yet still see how much traffic you get from a subdomain?

For example, right now we haven't excluded our own domain (which I would like to) and thus we can see how much traffic we get from blog.example.com.

Is there a way to continue being able to see that when we have excluded self-referrals?

Many thanks,
Carl

    Julius
    • May 29 2020
    • Reply

    Yes, google "referral exclusion list"

Dnyaneshwar
  • Jun 2 2020
  • Reply

Hi Julius,
I have blog website, example.com and a shop subdomain, shop.example.com. Do I need to install same GTM tracking codes on both the sites to subdomain tracking work? As both have different WordPress themes and databases.

Thank you

    Julius
    • Jun 2 2020
    • Reply

    Yes, as it was already explained in this blog post, you need the same GA tracking ID/code.

      J
      • Aug 3 2021
      • Reply

      Hey Julius,

      Can I check this - the same GTM container code on all subdomains OR if each subdomain has different GTM containers, then we just need GA tags to the same properties in the different GTM containers?

      Will both of these work:
      1) Same GTM container code with tags using the same GA UA ID fired on all sub domains;
      2) Different GTM container code / different GTM accounts on each sub domain, each with tags for the same GA UA ID

      Thanks

Pedro
  • Jul 21 2020
  • Reply

Hey there Julius,

Reading about your post, specially 2.2 and 2.3.

- I have a website and a subbdomain, which basically work as 2 different "products" for the company - totally different in reality.

From what I have understood, I should be using a different GTM container for the main site and subdomain. But what about the GA accounts/proprieties ? The same account with 2 different properties or 2 separate GA Accounts? I want future data separated as much as possible...

    Julius
    • Jul 21 2020
    • Reply

    If you want to have data separate, both options that you mentioned will work. No big difference here.

Brian
  • Sep 11 2020
  • Reply

Hi Julius,
Long time reader and subscriber, thank you for sharing your wealth of knowledge! I'm looking for help in doing the opposite of this article -- force GA to treat subdomains as different sites and start a new session when crossing over. We host sites for many clients, each of which is on a different subdomain of our main domain. In our aggregate GA Property, I've implemented Simo's session ID as a custom dimension set to session scope and using GTM have set the cookie domain to {{Page Hostname}} instead of auto. But I'm still seeing the same session ID across subdomains in some cases (there are legit use cases for users to cross to different client sites but still want GA to treat them separately). Would you by any chance be able to provide any guidance on how to force GA to start a new session when crossing to a new subdomain and treat each subdomain as a stand alone site within an aggregate GA property?

    Julius
    • Sep 11 2020
    • Reply

    Hi, remove all of your domains from the referral exclusion list in the GA property settings.

      Brian
      • Sep 15 2020
      • Reply

      Hi Julius, thank you so much for the response! After your reply I made that change, but am still seeing instances of the same session ID carry across subdomains. I confirmed the following:

      1. that the custom dimension for session ID is set to session scope in the GA Property

      2. that the session ID dimension is getting set properly as part of the pageview tag (all executed according to Simo's instruction)

      3. that the cookie domain in the pageview tag (via GTM) is set to Page Hostname

      4. that now the GA Property referral exclusion list is empty

      Is there anything else you might be able to think of that I'm missing or maybe somewhere else to focus my troubleshooting efforts?

        Julius Fedorovicius
        • Sep 16 2020
        • Reply

        Your configuration should work. Clear GA cookies and try again.

Krystal Kenlan
  • Sep 29 2020
  • Reply

Hi there! I noticed a typo in the first section of your article that I wanted to point out.

You mention that you do not need cross-domain tracking if the subdomain is on the same domain (using blog.example.com as the example), but then you go on to state that you will need cross-domain tracking if the site is blog.example.com.

    Julius Fedorovicius
    • Sep 30 2020
    • Reply

    Hi, the context matters here. In the 2nd example, blog.example.com is compared to other totally different domains and none of them are related to example.com.

    www.mainwebsite.com
    blog.example.com
    support.someotherdomain.com

    These are 3 totally different domains. Cross-domain tracking is needed here. If you noticed the typo in some other place, please mention the number of the chapter where this has occurred.

Sandeep Ranjan
  • Oct 7 2020
  • Reply

After reading this, I am double sure that this precisely written articles will help get me into action mode to implement Google tag manager and analytics. Subscribing the GTM checklist to learn it faster.

Gratitude Julius! for the awesome information.

Alex
  • Oct 22 2020
  • Reply

Hey Julius,

I have my main domain as www.example.com and a sub domain as test.example.com

But both of them have separate GTM codes as we were not aware and created separate GTM accounts.

Is there a way to still link the domain and the sub domain even if the tracking code is different

    Julius
    • Oct 22 2020
    • Reply

    GTM does not matter here. Just use the same GA ID

      Alex
      • Oct 22 2020
      • Reply

      Hey, Julius so basically what I am saying is in GTM I created 2 different projects so I have 2 separate sets of header and footer codes.

      One set is placed on the main domain & another on the subdomain.

      And in Google Analytics also we created two separate accounts for domain & sub domain

      What can be done to solve this now?? Any suggestions so that we can attribute the source from the Main domain to subdomain also

Alex
  • Oct 22 2020
  • Reply

Hey, Julius so basically what I am saying is in GTM I created 2 different projects so I have 2 separate sets of header and footer codes.

One set is placed on the main domain & another on the subdomain.

And in Google Analytics also we created two separate accounts for domain & sub domain

What can be done to solve this now?? Any suggestions so that we can attribute the source from the Main domain to subdomain also

    Julius Fedorovicius
    • Oct 22 2020
    • Reply

    The number of GTM accounts and contains does not matter. But you should use one GA property for both domain and subdomain.

Brian Piper
  • Oct 29 2020
  • Reply

Julius,

Fantastic article and spectacular site and content! So informative!

I work at a large institution with numerous sub-domains, all set up with different GA accounts and I'm just trying to track how much traffic goes from our sub-domain to other sub-domains (for now).

Should I just set that up using link tracking to those sub-domains in GTM since they're in different GA IDs?

Thanks!

Rajesh
  • Nov 6 2020
  • Reply

Hi Julius,
Thank you for the insights, I will be implementing the same this week, however, I have a doubt if you can help me clarify it.

My subdomain is parked in a different server & CMS and the main domain is in a different server and CMS, say Subdomain in WordPress and main domain in Magento, and both are parked in different servers. Can I still follow the above steps mentioned by you OR are there any additional steps? (Assuming I have to install the same property tracking codes in both the sites separately).

Patrick Cheung
  • Nov 9 2020
  • Reply

Great article. I have a question about best practices though.

I have a saas app, and I'm not sure if I really want to track marketing visitors with our paid users. Here are our domains:

example.com
blog.example.com
app.example.com

The first 2 above are my marketing site domains, and app.example.com is where my user's login and use. My question is, is it good practice to keep Visitors and Paid Users separate by keeping 2 separate GA Properties?

My follow up question is, I do want to track if visitors eventually convert to paid users on app.example.com, using Google Conversion Tracking. Do you have a good article that walks through how this is Conversion Tracking is setup in the context of multiple subdomains using GA, GTM, and Conversion Tracking?

Sorry, that was a mouthful. Thanks!

shahriar
  • Nov 9 2020
  • Reply

how you can do this for ga4? there is not any Tracking Info > Referral Exclusion List > Add Referral Exclusion in ga4.

Rajendra Krishna
  • Nov 9 2020
  • Reply

Is it possible for GTM to read other cookies from subdomain to subdomain other than _ga cookie. For example, if I define a first party cookie in GTM.

EH
  • Nov 9 2020
  • Reply

I have a site with one domain and 50 subdomains (one subdomain for each state in the USA). Visitors to the site are redirected to their appropriate state's subdomain based on their IP address. Visitors will not cross between subdomains. I want to track each subdomain's traffic separately. How would you advise setting up GTM & GA in this scenario?

Ben
  • Nov 14 2020
  • Reply

Hi Julius,

any idea how to deal with this in GA4? is this even possible at the moment?

Marc
  • Dec 18 2020
  • Reply

Hi,

How can we implement cross-subdomain tracking on GA4?

Kingsley Felix
  • Feb 2 2021
  • Reply

Hi,

So after doing the exclusion, subdomain VIEW only I should just add my GTM code to all the sub domains? i use GTM to add my tracking code.

Will this work for GA4? how do we go about GA4?

Remi
  • Feb 2 2021
  • Reply

Hi Julius,

Just to make sure, if cookie domain is correctly set up and domain added to referral exclusions list, users and sessions will be counted as 1 but is it still possible to keep an eye on the traffic from subdomain or will we only see direct? My point is to correctly track users and sessions but also monitor thé trafic from subdomain.

Thanks!

J
  • Jul 31 2021
  • Reply

To add to my other comment - presumably you can programmatically remove UTMs in GTM to avoid any session issues?

Matt
  • Oct 25 2021
  • Reply

Hello,

Question for you Julius.

The main website was on its own GA property and Sub was too.

Now the Main and Sub sit on the same - Great!

I had an analytics goal on the sub-property that I've switched to the main one but it isn't working. Would you know why this is?

I search the URL on the live data and it comes through but the goal isn't recording a conversion.

yana
  • Dec 22 2021
  • Reply

hi,how to do this in GA4?

    Julius Fedorovicius
    • Jan 4 2022
    • Reply

    GA4 does this by default. Just use the same measurement ID for all subdomains.

Jo
  • Mar 3 2022
  • Reply

Thanks for the article, very helpful.
Is it possible to configure the filter to show the full URL for only the subdomain?

Adi
  • Mar 25 2022
  • Reply

Hi Julius,

Thank you for your article. It clarifies quite some things for us.

We have the following setup:
* Main website - example.com
* App website (SaaS) - app.example.com

GA Setup:
* One Property with 3 views:
1. Master View with just one filter that also shows up the domain in the Page reports
2. Website view that has one filter which excludes traffic from the hostname app.example.com
3. App view which only includes traffic to the hostname app.example.com

GTM setup:
* Two containers - one for Website, one for app & both send hits to the same GA Property above

Referral exclusion list contains example.com

Now, the issue we're facing is that we would like to track the visitor journey from specific marketing campaigns (e.g. a post on social media linking to example.com?utm_source=soucre&utm_medium=medium) to the app website via the website. So, a user clicks on a link from Facebook, for example, lands on example.com with utm_ params tracking, then clicks on a button from example.com and goes to app.example.com.

For app.example.com we would like to have some goals created based on custom events and then see Goal completions by source/medium.

The issue is that the moment the visitor clicks on the button from example.com and goes to app.example.com, the source/medium is not the initial one, but goes to direct.

How could we fix this? I could not find anything related to this custom tracking.

Thank you very much,
Adi

Lexie
  • Jun 14 2022
  • Reply

Hey Julius,

Our e-commerce activities are still being attributed only to direct traffic and most of our site shows as data coming from only direct traffic.

Scenario:

1. domain.com
2. experiences.domain.com
3. portal.domain.com

All using the same GTM/UA-ID with e-commerce enabled. Cookie domain in GTM variable is set to auto, self referral exclusion list does include all three listed above but even when it just included domain.com all of the e-commerce tracking was being attributed to direct.

We are using UTMs on our marketing campaigns and they are being mostly sent to the experiences.domain.com. The _ga cookie is set to the correct domain when I check it.

Not sure why we cannot see the data being attributed to any of the other campaigns.

Joey Krefetz
  • Jul 16 2022
  • Reply

This is a terrific blog post. Thanks for sharing it!

Nika
  • Aug 1 2022
  • Reply

Hi. I found out that there is another GTM container implemented on the registration subdomain (account.domain.com), and asked the developer to remove the code snippet. But I don't see the main domain's container in the code. Should I now ask dev to paste the code to the subdomain manually?
Thanks

Ian Dombroski
  • Aug 26 2022
  • Reply

This is a outstanding post. Many thanks for sharing it!

Leave a comment Cancel reply

Your email address will not be published. Required fields are marked *

 

Hi, I'm Julius Fedorovicius and I'm here to help you learn Google Tag Manager and Google Analytics. Join thousands of other digital marketers and digital analysts in this exciting journey. Read more
Analytics Mania
  • Google Tag Manager Courses
  • Google Tag Manager Recipes
  • Google Tag Manager Resources
  • Google Tag Manager Community
  • Login to courses
Follow Analytics Mania
  • Subscribe to newsletter
Recent Posts
  • Track Videos with Google Analytics 4 and Google Tag Manager
  • Debugging Incorrect & Missing Google Analytics 4 Transactions
  • A Guide to Referrer in Google Tag Manager
Analytics Mania - Google Tag Manager and Google Analytics Blog | Privacy Policy
Manage Cookie Settings