4
votes

I have a website where each user registers as subdomain (username.domain.com). I'm tracking all subdomains with the folllowing code:

var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXXX-X']);
  _gaq.push(['_setDomainName', '.domain.com']);
  _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);
  })();

I want to show custom statistics for each user using the GA API. Since i'm using only one GA account for tracking all "subdomains", how can i filter the data in order to show only the data for each user (subdomain)?

Thanks.

1

1 Answers

3
votes

setDomainName is only relevant for the cookies that Google Analytics uses for tracking sessions. That is, setting it as you are makes it such that all traffic across those subdomains will be tracked consistently.

However, that doesn't change the domain data that gets sent to Google Analytics. All hits are sent to Google Analytics with the hostname (document.domain in JavaScript) of the pageview. That value is accessible in the API under the dimension ga:hostname. You can either use it as a dimension for a query, or use it as a filter for data (ie, say "only return the data I'm querying for this specific filter.)

So, regardless of the setDomainName configuration, you'll be able to access and segment on a subdomain level basis using the Google Analytics API.