Google Analytics Subdomain Tracking Tutorial

Table of contents for Google Analytics subdomain tracking tutorial 

  1. What is a subdomain and why should you track it in Google Analytics?
  2. Setting up a cookie domain
  3. Setting up a referral exclusion list
  4. FAQ

In this article, I am going to talk about how to track subdomains in Google Analytics. 

What is a subdomain and why should you track it in Google Analytics?

A subdomain is an additional part of the main domain. For example, if you have ‘example.com’ as the main domain, then ‘blog.example.com’ and ‘shop.example.com’ will be called subdomains. 

Even though these subdomains are subsets of your website, you still want to track the users across all of these websites. 

Let’s understand it with an example. Let’s suppose you have the website ‘example.com’ and the following is the sample user journey:

  1. User arrives at http://www.example.com/
  2. Clicks on the article link and then navigates to http://blog.example.com/
  3. After reading the article he clicks on a product link and navigates to http://shop.example.com/ 

Now, if you haven’t set up subdomain tracking, then every time the user navigates to a different subdomain, he will be considered a new user and a new session will begin. So, in the above example, we would have three users and three sessions for each website.

However, if you have set up subdomain tracking then there will be only one user and one session for the above example. 

When a user visits your website for the first time, Google Analytics sets cookies to identify unique users and unique sessions. When the user is navigating between the subdomains of the website this cookie value is shared so that Google identifies the user across the subdomains and does not set a new cookie or new session. 

To learn more about cookies you can read this post: Google Analytics cookies: _ga cookie, _utmb, _gat – Tutorial

To set up subdomain tracking in Google Analytics there are two major steps, as below:

  1. Setting up a cookie domain
  2. Setting up a referral exclusion list

Now let’s look into these steps in more detail.

62 point checklist 
Get the E-Book (50 Pages)
Google Analytics 4 thumb 
Get the FREE E-Book (50+ Pages)

Setting up a cookie domain

The first step in setting up subdomain tracking is to configure cookie domain parameters to ‘auto’. 

When you set the cookie domain parameter to ‘auto’, Google analytics will set ‘_ga’ cookie on the main domain and it will be accessible by all the subdomains for reuse. 

For example, if the user lands on a website, let’s say ‘blog.example.com’, the cookie will be set on ‘.example.com’ and can be reused by other subdomains such as ‘shop.example.com’ or ‘checkout.example.com’.

Setting up a cookie domain depends on how your analytics is implemented.

For Google Analytics Tag (analytics.js)

If you are using analytics.js for analytics implementation then you must have the below line of code in your main tracking code.

ga(‘create’, ‘UA-XXXXX-Y’, ‘auto’);

Your final code will look like below:

<!– 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 –>

By default, the cookie domain is always set to ‘auto’ and if you see this code in your main tracking code then you are fine and it means the cookie will always be set on the main domain.

For Global Site Tag (gtag.js)

If you are using ‘gtag.js’ for analytics implementation, then you do not need to modify the code. 

‘gtag.js’ by default has the cookie domain parameter set to ‘auto’.

But in the case that your main tracking code is modified and sets a cookie on a particular domain only, then you need to remove the code line which sets the cookie:

gtag(‘config’, ‘UA-XXXXX-Y’, {

   ‘cookie_domain’: ‘blog.example.com’ // remove this code line to set cookie domain parameter to ‘auto’.

});

For Google Tag Manager

If you are using Google Tag Manager for analytics implementation, then the cookie domain parameter is not set by default to ‘auto’ and you need to do the configuration settings in the Tag Manager console. 

Follow the below steps to set cookie domain parameters in Google Tag Manager.

Step-1: Navigate to your Google Tag Manager account and click on ‘Tags’ in the left-hand side menu.

tags 1

Step-2: Now select your page view tag which is set to fire on all pages.

pageview tag

Step-3: A new overlay will appear like below. Click on the pencil icon to edit the tag configuration.

pageview tag pencil icon

Step-4: Now click on ‘More settings’.

moresettings

Step-5: Now click on ‘Fields to set’.

fields to set

Step-6: Now click on ‘Add Field’.

add field

Step-7: You will get a screen like below, now in the input box available under ‘Filed Name’ type ‘cookieDomain’.

field name

Step-8: Now in the input box available under ‘Value’ type ‘auto’.

field value

Step-9: Click on ‘Save’ .

save 2

Congratulations! You have successfully configured your analytics pageview tag to set the cookie domain parameter to ‘auto’. Your final tag configuration will look like below

tag configutration

Another way to set the cookie domain parameter to ‘auto’ is by defining it in the analytics variable settings which you use for every tag while sending data to Google Analytics.

Just navigate to ‘Variables’ in the Tag Manager console.

Variables tab 1

Select the ‘Analytics configuration variable’ under ‘User-defined Variables’.

analytics setting variable

It will open the ‘Variable configuration panel’. Now under the input box named ‘Cookie Domain’ type ‘auto’ and save the variable.

Google Analytics Subdomain Tracking

Setting up a referral exclusion list

The second step in setting up subdomain tracking is to update the referral exclusion list in the Google Analytics admin console. 

Now let me tell you why this is necessary. When the user navigates from one subdomain to another one, the analytics tracking code will pass the referrer details and, if these details are available, Google Analytics will start a new session with the referrer source information. 

To avoid this we have already set the cookie domain to auto and now we need to add all the subdomains to the referral exclusion list. Once added to the list, Google Analytics will not consider any of your subdomain’s referrers as new, and will continue with the original session.

To set a referral exclusion list, follow the below steps:

Step-1: Navigate to your Google Analytics account and click on ‘Admin’ on the left-hand navigation menu.

admin

Step-2: Under the ‘Property Settings’ column, click on ‘Tracking Info’.

tracking info 1

Step-3: Now click on ‘Referral exclusion list’.

refrerral exclusion list

Step-4: An overlay will appear like below, now click on ‘+ Add Referral Exclusion’.

add to list

Step-5: A new configuration panel will appear, like below. Now under the ‘Domain’ add the domain name which you want to exclude and then click on ‘Create’.

domain and create

Note: You do not need to specify the individual subdomains here. Since we have set our cookie domain to ‘auto’, just adding the primary domain (highest domain) will be sufficient here. 

You can see the domain list excluded in the admin panel.

domain list 1

And that’s it, you are done setting up subdomain tracking in Google Analytics. 

Other articles on cross-domain tracking

Frequently asked questions about Google Analytics Subdomain Tracking Tutorial

What is a subdomain?

A subdomain is an additional part of the main domain. For example, if you have example.com as the main domain, the blog.example.com, shop.example.com will be called subdomains. Even though these subdomains are subsets of your website, they are essentially tied to your primary domain.

What is the difference between subdomain and cross-domain?

A subdomain is always attached to your primary domain. For example, if your primary domain is ‘.example.com’, then ‘blog.example.com’ or ‘shop.example.com’ are the subdomains. Whereas a completely different primary domain will be considered as cross-domain, such as ‘xyz.com’. 
To know more about cross-domain tracking visit: 
Cross-Domain Tracking in Google Analytics – Complete Guide
Cross-Domain Tracking in GA4 (Google Analytics 4) Setup Guide

What is the referral exclusion list?

A referral exclusion list is the list of domains whose incoming traffic will be treated as direct traffic (instead of referral traffic) by Google Analytics. This way you don’t see the referral traffic from certain domains (like your own subdomain or from a payment gateway like Paypal) in your Google Analytics reports.
To know more about referral traffic visit:
Referral traffic vs Direct traffic in Google Analytics
How to correctly use referral exclusion list in Google Analytics

Register for the FREE TRAINING...

"How to use Digital Analytics to generate floods of new Sales and Customers without spending years figuring everything out on your own."



Here’s what we’re going to cover in this training…

#1 Why digital analytics is the key to online business success.

​#2 The number 1 reason why most marketers are not able to scale their advertising and maximize sales.

#3 Why Google and Facebook ads don’t work for most businesses & how to make them work.

#4 ​Why you won’t get any competitive advantage in the marketplace just by knowing Google Analytics.

#5 The number 1 reason why conversion optimization is not working for your business.

#6 How to advertise on any marketing platform for FREE with an unlimited budget.

​#7 How to learn and master digital analytics and conversion optimization in record time.



   

My best selling books on Digital Analytics and Conversion Optimization

Maths and Stats for Web Analytics and Conversion Optimization
This expert guide will teach you how to leverage the knowledge of maths and statistics in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.

Master the Essentials of Email Marketing Analytics
This book focuses solely on the ‘analytics’ that power your email marketing optimization program and will help you dramatically reduce your cost per acquisition and increase marketing ROI by tracking the performance of the various KPIs and metrics used for email marketing.

Attribution Modelling in Google Analytics and BeyondSECOND EDITION OUT NOW!
Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you implement attribution modelling. It will teach you how to leverage the knowledge of attribution modelling in order to allocate marketing budget and understand buying behaviour.

Attribution Modelling in Google Ads and Facebook
This book has been written to help you implement attribution modelling in Google Ads (Google AdWords) and Facebook. It will teach you, how to leverage the knowledge of attribution modelling in order to understand the customer purchasing journey and determine the most effective marketing channels for investment.

About the Author

Himanshu Sharma

  • Founder, OptimizeSmart.com
  • Over 15 years of experience in digital analytics and marketing
  • Author of four best-selling books on digital analytics and conversion optimization
  • Nominated for Digital Analytics Association Awards for Excellence
  • Runs one of the most popular blogs in the world on digital analytics
  • Consultant to countless small and big businesses over the decade
error: Alert: Content is protected !!