Tracking Subdomains In Google Analytics

By July 19, 2010 Analytics No Comments

I am writing this piece just because the instructions provided by Google are hidden away among the instructions for various other things, and also because it stops (in my opinion) just short of what I wanted them to explain.

So, I hope this is a helpful and comprehensive explanation on how to track subdomain traffic when using Google Analytics.

In my example, Suzy’s shoe shop www.suzyshoes.com, has some
subdomains – www.stiletto.suzyshoes.com and www.slipper.suzyshoes.com.

Each of these subdomains has a contact page, as does the main domain;

www.suzyshoes.com/contact
www.stiletto.suzyshoes.com/contact
www.slipper.suzyshoes.com/contact

The problem with this is that in Google analytics, reports show only
the trailing slash page. E.g. if each of these pages got a visit, then
in Google Analytics, Suzy will see 3 visits to the page “/contact”, but
this is in fact 3 different pages

To improve on this reporting, Suzy needs to make changes both to her Google analytics code, and her Google analytics settings.

Changing Your Google Analytics Code
First step, the code changes. You need to add a snippet of code into
the existing code. Note here I am using the old code, not the new
asynchronous one. If you are using the new asynchronous code, check out
the instructions here. So, below is a bit of the code which is on Suzy’s site already, and the red line is the new bit she needed to insert to track the subdomains separately.

<script type=“text/javascript”>

try {
var pageTracker = _gat._getTracker("UA-XXXXXXX-X");
pageTracker._setDomainName(".suzyshoes.com");
pageTracker._trackPageview();
}catch(err){}
</script>

Changing Your Google Analytics Setup
Now that this tracking is in place, you need to make some changes in your GA settings.

First, make duplicate profiles of the one you are working on. So, Suzy will leave her existing one as is, and also make three more profiles;
1. Excluding subdomains
2. Stiletto Subdomain
3. Slipper Subdomain.

Then, in each of these three new profiles, she will implement the following filter;
Filter Type: Custom filter -> Advanced
Field A -> Extract A: Hostname -> (.*)
Field B -> Extract B: Request URI -> (.*)
Output To -> Constructor: Request URI   
/$A1$B1
Field A Required: Yes
Field B Required: No
Override Output Field: Yes
Case Sensitive: No

The result of this is that in each of these profiles, her page reports will now show the visits to her contact page like this;

.suzyshoes.com/contact
.stiletto.suzyshoes.com/contact
.slipper.suzyshoes.com/contact

So she can see exactly what contact pages got the visits.

Now, the last step is to include/exclude the traffic in each of the
different profiles, so as to make them just for one particular
subdirectory.

You need to install a filter on each of the profiles, which looks something like this;

Filter Type: Custom filter -> Include
FIlter Field: Hostname
Filter  Pattern:  ^stiletto\.suzyshoes\.com$
Case Sensitive: No

Suzy would then repeat this for the slipper profile, but for the other
profile (which is excluding the two subdomains), she would implement
two filters, making each of them ‘exclude’ instead of ‘include’.

For more information or specific help, call us about our web analytics consulting.

One New Idea To Help Achieve Your Sales Goals REQUEST YOUR FREE SPARK