Google Analytics SubDomains Tracking Part One

So I have recently been setting up a rather large implementation of Google Analytics as part of a holistic SEO strategy and had the joy of doing this over a site with a large number of sub domains. There are a number of things to keep in mind when implementing Google Analytics tracking for sub domains:

The basic setup of this site is

What makes this an even more interesting implementation is the conversion process. A user can search for a product on the sub domain sites but is then redirected back to the conversion steps on the main site:

– User searches for product on
– User is referred to
– User goes through steps to

I also had a problem where by the steps on the conversion process were dynamic URLs, so it was a little more complicated to create goals.

Set up our Sub domain Tracking and Funnels

To Do

1. setDomainName: First you need to add the following tracking code to all pages of your subdomains and main domains.

<script type=”text/javascript”>
try {
var pageTracker = _gat._getTracker(“UA-XXXXXX-X”);
} catch(err) {}

2. Virtual Pageviews: You can then setup virtual pageviews for steps in your conversion process that have dynamic URLs


NOTE: Be careful with the above. If you have trackPageview twice on the same page, your referral will be reset and all conversions will show as direct.

3. You need to set up an advanced filter to attach the sub domain to the front of each page. If you don’t do this and you have the same page on both your main site and sub domains, you will not be able to distinguish between either i.e.

will just appear as /page_1

So the custom advanced filter will be as follows:

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

This will now make your sub domain pages appear as

4. Trying to break down the funnels by sub domain proved another obstacle altogether as each sub domain refers back into the main sites conversion process. So for example I have one funnel setup to track the conversion process as follows:

– Step 1 (On main site – required step)
– Step 2 (On main site)
– Confirm Booking (On main site)
– Thank You Page (On main site)

But to break this funnel down by sub domain you need to be a little more inventive. You can do a lot of different things:

a. Create Advanced Segments to do the following
– Track users who landed on a particular page (your sub domain) and went on to convert (using the Ecommerce Affiliation field).

b. Create a funnel using the advanced filter used above. This will allow you to create goal steps as follows:

– The first required step will check to see if a user is on any page of your sub domain (as a regexp) i.e. /subdomain_1\.mainsite\.com/.*
– Step 1 (On main site – required step)
– Step 2 (On main site)
– Confirm Booking (On main site)
– Thank You Page (On main site)

This is not the whole Google Analytics story on sub domains. There is the case of tracking between multiple domains with sub domains and also tracking conversions when users are redirected to a third party shopping cart. I will add these in Part 2.

Any questions on the above .. please ask away …

About Kieran Flanagan

Online Marketer who implements both inbound and paid strategies to help companies grow internationally. Lover of content marketing, SEO, analytics, CRO and strategy. A highly motivated marketing geek high on data crack.