Welcome to Josh Baker's Practical Advice for Optimizing Your Internet Marketing blog. Here you will find internet marketing optimization and online strategy articles full of tips, tricks, discussions, and thoughts to help you take your marketing and business to the next level of success.

Tracking & Separating Subdomain Data under One Profile Using Filters in Google Analytics


If you have one Google Analytics profile tracking multiple subdomains (or you want to do so); for example, one profile tracking:


when you view your Google Analytics data in the profile that is tracking all 3 subdomains it won’t by default separate out the data for each actual subdomain. You’ll need to add some additional code to your tracking script and also set up an Advanced Filter.

If each of your subdomains has pages that are named the same, you will see the data reported as aggregate for all them under that page name, therefore the data for those page names will be inflated and not actionable. For example:


will all be rolled up under /contact.html and you will not know what the true data is for the contact.html page on each subdomain. Instead, you will have one entry of /contact.html displaying the data for all traffic to contact.html on all 3 of the subdomains. Not good!

What you will want to do is see it by subdomain so you can attribute the correct data to the correct subdomain.

Luckily, this is easily fixed!

If you already have your pages tagged with the Google Analytics tracking script, just add the line in bold to your existing Google Analytics code (replace MyCoolWebsite.com with the actual domain, not the entire subdomain and of course make sure all of the sites have the same profile tracking number (seen below as UA-xxxxxx-x, the x’s will be replaced by your own account number and profile number).

 If you haven’t added the Google Analytics tracking script to your pages add the entire code below – again with your own specific Google Analytics account number and the profile number, and your actual domain:

<script type=”text/javascript”>
var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.” : “http://www.”);
document.write(unescape(“%3Cscript src='” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E”));

<script type=”text/javascript”>
var pageTracker = _gat._getTracker(“UA-xxxxxx-x”);

Next, you will need to set up an Advanced Filter, this will actually separate out the subdomains so that they will be reported separately under that profile:

The finished result is that instead of just 1 instance of /contact.html, you will see it reported in your reports with each subdomain added to /contact.html as follows:


Here is how to set up the Advanced Filter for Tracking and Separating out Subdomains:

  1. First log-in to Google Analytics.
  2. Select edit from the profile you created that will track all of the subdomains.
  3. Select edit in the Filters Applied to Profile section.
  4. Fill in the below information and Save.

First, here is the actual information for you to copy and paste, then below that is a screenshot of how it should look before you save and apply it to that profile.

Filter Type: Custom filter > Advanced
Field A: Hostname
Extract A: (.*)
Field B: Request URI
Extract B: (.*)
Output To: Request URI
Constructor: /$A1$B1


google analytics advanced filter for tracking and separating subdomains

Categories : Analytics



[…] view subdomains data full paths in your reports; […]


Worked like a charm, thanks! Too bad Analytics doesn’t have an easier way to breakdown domains.

Leave a Comment