Guide To Tracking Multiple Subdomains In Google Analytics

Thursday, August 9, 2012

Copied From:

Tracking multiple subdomains is rather easy.

Viewing your traffic for each subdomain is a little trickier. If all you
do is set up the code and do not create the profiles and filters as
described here, you will have one Google Analytics account tracking all
of your subdomains, and absolutely no way to know which subdomain to
attribute the traffic to.

The Code

The analytics code that you place on each subdomain will be the same.
See the code below.

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-xxxxxxxxxxx-1']);
  _gaq.push(['_setDomainName', '']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);


Notice there is only one new line of code in this example.

_gaq.push(['_setDomainName', '']);

You can also get this code if, in Google Analytics, you go to Settings
-> Tracking Code -> One domain with multiple subdomains.

The Profiles

Do not create a new Google Analytics account for each subdomain. Sure,
it would technically work. There is nothing in the world to stop you.
But there is a better way.

Create one Google Analytics account, and then create a profile for each
subdomain plus another profile that tracks all subdomains collectively.
So if you have two subdomains (www and mobile) you will want three
profiles total. One for www, one for mobile, and one to track both
subdomains. This will take some time to set up, but will be well worth
it in the end.

Once you have created each profile, it’s time to apply the filters.

Filtering Subdomain Traffic In Profiles

We need to apply a filter to ensure that we track only traffic for the
profile’s designated subdomain. Go to Admin -> Profiles -> Filters ->
New Filter and refer to the screenshot below.

Google Analytics Profile

It’s that easy. Applying this filter to your profile will ensure that
this profile only tracks traffic for the specified subdomain. In this

Main Profile

When tracking multiple sub domains in one profile, you will not be able
to differentiate between your subdomains in your pages list in Google
Analytics unless you create a filter.

To illustrate this, go to your page list in analytics, Content -> Site
Content -> Pages. You can’t see the hostname at all! See screenshot


By default, Google Analytics does not show the hostname or subdomain in
your reports. You will not be able to see which home page the back slash
above refers to (/). It could refer to www or it could refer to mobile,
there is no way of knowing. That’s why we need a filter to apply to this

Filtering Main Profile

In your main profile for google analytics, go to create filter. Refer to
the screenshot below to see how to apply filter.


After applying this filter, the subdomain should appear in your page
list, and you will be able to differentiate between traffic for each

Wrap Up

In this guide, you should have learned how to 1) install Google
Analytics code for subdomains 2) filter traffic to ensure that profiles
track the traffic for it’s designated subdomain and 3) filter traffic in
your main profile to display the subdomain.

This entry was tagged ga

comments powered by Disqus

© 2009-2013 All rights reserved. Powered by Pyramid

go to Top