Posted by: Marshall Sponder | March 1, 2008

Tracking SubDomains within Google Analytics

I saw a question on the Yahoo Message Board about Tracking Sub domains using Google Analytics – and yes, it can be done well, provided you take a few steps – I’m writing this post to make sure I remember them too – I write as much to keep track of information I come up with and make sure I have it when needed.

The question came from David Culbertson over at  LightBulb Interactive and the answer I left included a reference to this page on AnalyticsTalk Tracking Sub Domains with Google Analytics

This is a issue that come up often – a lot of sites use sub domains – (where I’m currently working) uses a lot of sub domains, btw.   We even have some GA stuff we’re playing with and this very issue has come up.

 “…What if you want to track one group of sub domains in one profile and a different group of sub domains in another profile? Or what if you want to create new profiles for a different groups of sub domains in the future?”

Justin, who I’ve met a couple of times, over at EpikOne, is one of the foremost Google Analytics experts out there  – EpikOne probably has done more variety of GA Installs and Support than most Google Analytics Channel Partners.  Here’s what he has to say about the Sub domain issue:

1. Create Profile for The Primary Domain

The first step is to create a master profile. All other profiles for the website, including profiles for the various sub domains, will be based on this profile. When you enter the domain for the website use the primary website domain. In the example below, I’m using as the website domain.

Google Analytics Master Profile Settings.

After creating the profile GA will display the tracking code for the site. Before you add it to your pages it must be modified. You need to force GA to use the primary website domain for the cookie domain. This modification will let you track each unique visitor across all sub domains. This in turn let’s us collect all site data in a single profile and do ‘roll up’ reporting.

Old urchin.js tracking code:

<script type="text/javascript">
_uacct = "UA-XXXXXXX-1";
_udn = "";

New ga.js tracking code:

<script type="text/javascript"> var pageTracker = _gat._getTracker("UA-XXXXXX-1"); pageTracker._setDomainName(""); pageTracker._initData(); pageTracker._trackPageview(); </script>

Note: Use the new tracking code if you can as it enables Site Search tracking and Rich Media Tracking along with outbound links.

2. Create Profiles for All Sub Domains

Once you have created the master profile you can start creating profiles for each of the sub domains. Remember, each sub domain profile is based on the master profile, that we created in step 1. Here’s how to set up the new profile:


Now that you’ve created the profile, make sure you add the tracking code to the pages on the sub domain. The tracking code for the sub domain is the same as the tracking code that goes on the primary domain (it’s the code from step 1).

3. Add Filters to Sub Domain Profiles

The next step is to add a filter to the sub domain profile so it only contains data for the appropriate sub domain. This is done using an include filter based on the hostname. Once this filter is in place you’ll have the master profile which will contain data for all sub domains, and this profile that will contain data for a specific sub domain.

Filter to create a GA sub domain profile

To create additional profiles for other domains just repeat steps 2 and 3. Obviously the settings for the filter used in step 3 will depend on the sub domain that you want to include in the profile.

Creating Additional Profiles

Let’s say you need to create a profile for two sub domains: and This can easily be done because the same tracking code is on both sites. All you need to do is add an include filter with the following settings:

GA Filter settings for 2 sub domains.

While Google’s documentation describes a good way to track sub domains, I think this approach is better due to it’s flexibility. Plus, because the same tracking code is used all all sub domains you don’t need to worry about placing the wrong tracking code on a sub domain.

Good point – you want to think about flexibility and long term use at the very onset of installing anything.



  1. What if you already had the unmodified code installed on all pages on the main domaing, and you just added the modified code to the pages on the subdomains?

  2. Thanks, this looks far more useful than the info Google provided!

  3. Good advise, I more or less found out this method by using epikone’s guide, and some tinkering with the new GATC 🙂

  4. Your instructions involve primary and sub-domains. Can you advise if it is possible to track (separately), a primary and a parked domain that both view the same website and pages?

  5. my subdomain is a wordpress blog. Any idea how which plugin works best with the process you described? Thanks in advance for your help!

  6. […] Original source :; […]

  7. I am working on a project that I would like to use google analytics for. So any help would be appreciated.

    I want be able to create a lot of sub domain and give each user information about how many people come to that page and from where, etc. On there own page.

    But if I understand how the setup works for each sub domain I will have to create a new profile in GA for that sub domain and then have GA email the reports XML. And then I will have to parse each XML file for each site.

    I don’t mind doing the work to create a script that parse the XML data and stuff but having to create a GA profile for each sub domains is a lot of work. If the site I am working on has over 10,000 users or 10,000 sub domains.

    Thanks for your time.
    I am not that good at English so please let me know if I am confusing.

  8. Does anyone know how to configure GA to show keywords to transactions. currently GA is on reporting transactions. I need to report which keywords are converting into the most sales – kamagra UK



  9. Does anyone know if this works if you are using Urchin Webstatistic? We are using webstatistic to get more data.


  10. […] (quer dicir, por usuarios distintos) un sitio e os seus subdominios baixo esta ferramenta. Existen xeitos de salvar esta limitación pero requiriría dun administrador único, o que nos levaría a partillar entre varias persoas unha […]

  11. I installed the code for tracking across subdomains. But I notice my utmr resets when I go across subdomain. Do i have a problem with my subdomain setup? and

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: