Here is the step by step on how to track a subdomain in Google Analytics. This will work for anything like blog.domain.com etc which may be set up for strategic purposes.
How to add a subdomain as a new profile:
This is the easiest way to track a subdomain. Creating a separate profile for each subdomain allows you to track traffic in Google Analytics for each subdomain separately.
- When you are in the analytics overview/profiles section (where you see your URL, view report option and some overview stats) there will be an option (within the gray area) on the right to click “+ add a new profile” … choose that
- Add a Profile for a new domain and enter “subdomain.example.com” as the domain. (note you do not want to add www. for a subdomain at all)
- Just copy the new code that is then provided into your HTML footer.
How to track a subdomain within your existing Google Analytics profile:
This option is to track subdomains within the same profile as the domain. (this is more complex) In order to do so, you’ll need to add a line to the tracking code on each page of your site. The instructions below assume that this profile was set up with the primary domain as the listed website (e.g. .example.com)
- Add the following line (in bold) to the tracking code on all pages of your subdomain and your main 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>
<script type=”text/javascript”>
try{
var pageTracker = _gat._getTracker(“UA-xxxxxx-x”);
pageTracker._setDomainName(“.example.com”);
pageTracker._trackPageview();
} catch(err) {}
</script>






