Setting up Google Analytics for multiple subdomains

Posted by Andrew G. Johnson on Pro Webmasters See other posts from Pro Webmasters or by Andrew G. Johnson
Published on 2012-03-31T22:34:15Z Indexed on 2012/03/31 23:43 UTC
Read the original article Hit count: 414

Filed under:

so first here's a snippet of my current Analytics javascript:

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-30490730-1']);
_gaq.push(['_setDomainName', '.apartmentjunkie.com']);
_gaq.push(['_setSiteSpeedSampleRate', 100]);
_gaq.push(['_trackPageview']);
(function() {
    var ga = document.createElement('script');
    ga.type = 'text/javascript';
    ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(ga, s);
})();

So if you wanna have a quick peak at the site the url is ApartmentJunkie.com, keep in mind the site is pretty bare bones but you'll get the idea -- basically it's very similar to craigslist in the sense that it's in the local space so people pick a city then get sent to a subdomain that is specific for that city, e.g. winnipeg.mb.apartmentjunkie.com.

I put that up late last night then had a look at the analytics and found that I am seeing only the request uri portion of the URLs in analytics as I would with any other site only with this one it's a problem as winnipeg.mb.apartmentjunkie.com/map/ and brandon.mb.apartmentjunkie.com/map/ are two different pages and shouldn't be lumped together as /map/

I know the kneejerk response is likely going to be "hey just setup a different google analytics profile for each subdomain" but there will eventually be a lot of subdomains so google's cap of 50 is going to be too limited and even more important I want to see the data in aggregate for the most part.

I am thinking of making a change to the javascript, to something like:

_gaq.push(['_trackPageview',String(document.domain) + String(document.location)]);

But am unsure if this is the best way and figured someone else on wm.se would have had a similar situation that they could talk a bit about.

© Pro Webmasters or respective owner

Related posts about google-analytics