Archive for March, 2009

Sub Domain Tracking with Google Analytics

Thursday, March 26th, 2009

There are 2 ways to track sub domains with Google Analytics, you can track all sub domains in a single profile or track sub domains in separate profiles.

Step 1: To track all sub domains in a single profile, add the following line of code (in bold) to the tracking code on all pages of sub domain and main domain:

<script>
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>

<script>
var pageTracker = _gat._getTracker(“UA-xxxxxx-x”);
pageTracker._setDomainName(“.maindomain.com”);
pageTracker._trackPageview();
</script>

This change will allow you to track sub domains within one profile.

Step 2: To track sub domain in separate profiles.

  • Create new website profile.
step1 300x193 Sub Domain Tracking Google Analytics Tracking Google Analytics Sub Domain Tracking Google Analytics Analytics

New GA Profile Creation

  • Add Filters

    step2 300x245 Sub Domain Tracking Google Analytics Tracking Google Analytics Sub Domain Tracking Google Analytics Analytics

    Applying Filter in GA

This way you can track each sub domain in a separate profile.