SubDomain Tracking Implementation in Google Analytics Using Google Tag Manager

Subdomain Google analytics tracking can be easily implemented using the Google Tag manager. If not done right, you might lose a lot of valuable analytics data if you have multiple subdomains within a domain. Here is a guide on implementing subdomain tracking in Google Analytics (GA) using Google Tag Manager (GTM) by following some simple steps given below.

Looking for Analytics Audit & Enhancement: Connect to me by Sending an EMail.

Subdomain Tracking & GA Views

Here is a snapshot of what Subdomain and main domain tracking will look like for me:

GA Views for my site

Let me explain, what I am trying to achieve here and what different views stand for:

Blog (Subdomain view)

This view represents all the traffic that goes to the subdomain on my blog. The subdomain is blog.trekkerpedia.com. This view would not keep track of any traffic from the main domain of trekkerpedia.com

Master view

The master view represents the filtered traffic on my main domain. It does not include the subdomain traffic from blog.trekkerpedia.com. It only contains the traffic on trekkerpedia.com main domain. This view is also referred by the name of the filtered view.

Raw Data View

The raw data view represents the entire traffic on my main domain as well as on mine subdomain. In short, it includes every traffic. This view is also referred by the name of the unfiltered view. I am going to ignore the test view that is out of scope in terms of subdomain tracking.

Implementing SubDomain Analytics Tracking Using GTM

Before setting up the subdomain tracking, you also have to make sure that the main domain, as well as the subdomain, have the same GTM container ID as well as the Google Analytics ID present on both of the websites.

1. Set up Google Analytics Variable

Login to Google Tag Manager -> Click on Variable from the left-hand panel -> Click User-defined variable -> and click on variable configuration

Name your variable

Step 2. Select Google Analytics Settings as Variable Type

Choose “Google Analytics Settings” from the right-hand side under “Choose Variable Type”

Choose Google Analytics Settings

Many a time people also select “Constant” as the variable type but if constant is chosen then we would not get Google analytics settings configuration options which you will see in the next step.

Step 3. Set Google Analytics Settings

Fill in the Google analytics settings as shown below in the picture:

Google analytics settings asvariable

  • Fill in the Universal Analytics tracking ID
  • Then set Cookie Domain as auto. By default, it will be auto only
  • Under fields to set, set allowLinker and set its value as true
  • Under cross-domain tracking, put in the URL of both of the domain as well as the subdomain.
    • In the picture above, I have put the domain and sub-domain URL of my blog

Step 4. Create a Tag and a corresponding trigger

Universal Analytics settings

Step 5. Add Referral exclusion in Google Analytics

  • Go to your Google Analytics settings, under property settings click on Tracking info -> Click on Referral Exclusion List -> Add Referral exclusion in the right pane
  • Add the URL of your main domain.

Why we are doing this?

If we do not add the main domain in the referral exclusion list, then the traffic coming from blog.trekkerpedia.com to trekkerpedia.com will become referral traffic. Even though in the true sense, it is direct traffic and vice versa. If we add the main domain the referral exclusion list then traffic originating from any subdomain or main domain to any sub-domain and main domain will not be counted as referral traffic. For example, traffic from blog.trekkerpedia.com to trekkerpedia.com and vice versa will not be counted as referral traffic.

 

Referral exclusion list

Subdomain View Settings in Google Analytics

Now, we will explore and implement right view settings under each view that was mentioned at the beginning of this article.

Blog (Subdomain view tracking)

This view represents all the traffic that goes to the subdomain on my blog. The subdomain is blog.trekkerpedia.com. This view would not keep track of any traffic from the main domain of trekkerpedia.com. So, add a filter under the view.

  • Under Settings, go to view -> Click Filters -> Name your filter -> Choose filter type as custom and fill in the details as shown below
  • Save your filter

This filter on this view will only include the traffic that is coming to your subdomain. Until this point, subdomain tracking is done. However, there is more that can also be done and is beneficial for you.

Subdomain tracking view

Master view Settings

The master view represents the filtered traffic on my main domain. It does not include the subdomain traffic from blog.trekkerpedia.com. It only contains the traffic on trekkerpedia.com main domain. This view is also referred by the name of the filtered view.

  • Go under the master view settings.
  • Follow the steps as shown above in the blog view. Instead of including the traffic from a subdomain, this time you shall have to exclude the traffic and everything is set.

Raw Data View Settings

The raw data view represents the entire traffic on my main domain as well as on mine subdomain. In short, it includes every traffic. This view is also referred by the name of the unfiltered view. Follow the steps below for the raw data view.

  • Under Settings, go to view -> Click Filters -> Name your filter -> Choose filter type as custom and fill in the details as shown below in the picture
  • Save your filter

filter

  • Select hostname under Field A -> Extract A and fill in as (.*)
  • Select request URI under Field B -> Extract B and fill in as (.*)
  • Select request URI under Output -> Constructor and fill in as ($A1$B1)
  • Tick mark the two boxes at the bottom and now you are good to go.

What does the above step do here?

The above filter will add the hostname to the beginning of the Request URI for every pageview hit, and then overwrite the Request URI with this new format. Once you have applied this view, if you go to all-domain default page view, you will see that all the pages have their URI with corresponding hostnames.

Validate the implementation

Go to Behaviour -> Site content -> All pages and you will see pages from domain and subdomain with full path.

source: .ericmobley.net/guide-to-tracking-multiple-subdomains-in-google-analytics

Case Study: Multiple domain tracking

What happens when we put the same GA code on multiple domains?

  • In the GA report, we would not be able to differentiate between the page name with same pages exist on both of the websites.
  • For example “/” will appear for the first domain as well as the second domain home-page in Google Analytics.
  • If the landing page is on the first domain and thank-you page after the conversion is on the second domain, Google would not be able to track through the actual source of the conversion such as different advertising platforms like Google, Bing, Quora, etc.
  • In the above case, even if you are tracking the conversion as a goal in Google Analytics, there will be goal conversions but the source will be mostly referral traffic from the first domain.

Other Complications that may arise

  • You might have to create different properties to your Google Ads account in order to import the audience from Google Analytics to Google Ads Account in order to create an audience for retargeting
  • If your audience interact with the main domain as well as the subdomain then, subdomain tracking becomes really necessary so that you can retarget the audience right without breaking their cookie

Looking for Analytics Audit: Connect to me by Sending an EMail.

Have a Question? Get in Touch!



7 Replies to “SubDomain Tracking Implementation in Google Analytics Using Google Tag Manager”

    • DigiAshva Post author

      It would add the hostname to the beginning of the Request URI for every pageview hit, and then overwrite the Request URI with this new format. After applying this filter if you navigate to your Cross-Domain View, in All Pages report, you will have all pages with their corresponding hostnames.

      Reply
  1. Rob

    Thanks, great guide. Can I just ask, if I now want to leave the first auto-generated view as it is for full coverage, but then create 3 additional views in GA that only showed traffic to Site A, Site B and Site C respectively, what would be the best way to do this? Duplicate the view and then change the filter somehow to exclude/include particular hostnames?

    Thanks in advance!

    Reply
    • DigiAshva Post author

      If by Site A, Site B, and Site C, you mean three different sub-domains of the same domain – Yes, you can create a separate view for separate sub-domains as well by duplicating the view and changing the filters as you have mentioned above. Let me know if you need some help.

      Reply
  2. kaynat Nasir

    Thanks, I really found your post helpful and implemented the method as well. But, when I am checking my data in Raw view and other views that’s appending 2 domains in the beginning and hence new URLs are generating in GA which are going dead. How can I resolve that now?

    Thanks
    KN

    Reply
      • kaynat Nasir

        What will happen if I will delete All website data filter from Raw View? Is there really a need for that? As mentioned above in one of the comments “After applying this filter if you navigate to your different Views, in All Pages report, you will have all pages with their corresponding hostnames”. Aren’t we going to see the hostnames in any way coz we have also applied the filters for including and excluding the domains?

        Reply

Leave a Reply

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