Site icon Search Engine People Blog

How To Setup Subdomain Tracking

Stay Connected with Us!

Google Analytics is configured to record visitor traffic only for a single domain. This is the default setup.

This means that when a visitor reaches a website -- example.com -- for the first time, Google Analytics records it as a new session from a new user.

But if that visitor travels travels to and from the site's subdomains -- blog.example.com, support.example.com -- Google starts a new session for the same user, and it lists the other part of the domain as the referral site.

This causes problems when you want to track the number of visitors and the number of sessions for your whole site, subdomains included.

Fortunately, site owners can change this behavior by following a set of simple steps.

Classic Google Analytics

With Classic Google Analytics there is a need to alter the tracking script to enable subdomain tracking.

Consider a site, example.com, with 2 subdomains; blog.example and support.example.com

The site owner would make this simple change to the tracking code:

<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_setDomainName', 'example.com']);
_gaq.push(['_trackPageview']);
></script>
  • Traditional Syntax
<script>
var pageTracker = _gat._getTracker('UA-12345-1');
pageTracker._setDomainName('example.com');
pageTracker._trackPageview();

Google Tag Manager

If your analytics is implemented via Google Tag Manager, go back into that tag and set 'cookieDomain' to auto.

Universal Analytics

The tracking code from Universal Analytics is already completely set to track subdomains. BUT -- you absolutely need to verify, and perhaps update, the Referral Exclusion List or Google Analytics will start a new sessions when switching between the subdomains.

The “Referral Exclusion List” can be accessed through the following path:

Admin -> Property -> Tracking Info -> Referral Exclusion List

Once there ensure the main, top-level domain is listed there: example.com in our case.

If it's not there, click Add Referral Exclusion and add the domain.

Optional: Filters

See Domain Name In Report

Google Analytics displays URLs without the domain name in its tracking list. This can make it hard to easily see if /page1.html was accessed on example.com, blog.example.com, or support.example.com

This can be fixed by adding a filter to the view:

  • Filters -> Add New Filter -> Custom ->Advanced
  • Choose ‘Hostname’ for Field A and enter (.*) in the field space
  • Now select ‘Request URL’ for Field B and again enter (.*)

In the third step, choose ‘Request for URL’ for Field C and enter the value $A1B1

Reporting On (Sub)domains Separately

If you want to be able to see reports for each domain and subdomain separately, you have to create views for each and one for all combined.

In our case of example.com, blog.example.com, and support.example.com we would have 4 views:

  1. All Traffic Combined
  2. example.com
  3. blog.example.com
  4. support.example.com

For each domain specific view you have to create inclusion filters that remove all traffic from the other domains.

Go to Filters -> Add New Filter -> Custom -> Include -> Hostname

For the main domain, example.com, we would enter:

When the blog.example.com view is selected we would enter: