How to set up google analytics profiles for domain and sub-domain tracking

[Update Feb, 2016: This article is based on old version of Google analytics and is now deprecated. Please visit Google cross domain tracking page for latest documentation.]

Google analytics can be used to track a domain and its one or more subdomains. This is pretty useful if you are having one or more subdomain sites in addition to main site. Here are the steps to set up google analytics profiles for subdomains.

  1. Go to google analytics admin page and create new account as shown below.
    google-analytics-new-account
  2. Next screen will show tracking id and few options along with subdomain on-off option. Click on it to turn it on.
    google-analytics-subdomain-on
    After turning it on you should see this kind of code:

    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
    _gaq.push(['_setDomainName', 'infoheap.com']);
    _gaq.push(['_trackPageview']);

    Please note the presence of _setDomainName

  3. Click save and proceed to the property we just created. It is created with a default profile. The profile will show the analytics data for the main domain infoheap.com and all its subdomain if nothing is done. We need to add a filter so that the subdomain data is not captured by the main profile.
  4. Click on new filter. And create a sobdomain include only filter as show.
    google-analytics-filter-include-only-hostnameThat’s it. Now this profile will only contain analytics data for infoheap.com and not its subdomains. To create a subdomain profile, create one more profile and a subdomain hostname include only filter for it.
  5. In case you are using wordpress and google analytics plugin by yoast, you can enter subdomain for tracking purpose in plugin settings as shown below:
    google-analytics-wordpress-plugin-subdomain-tracking
  6. Please note that each profile can have any number of filters and each filter can have any number of profiles. In case you need to view/manage your filters later,  you can go to your account page (Admin home -> account name) and click on filters. This is how the list will look like:
    google-analytics-filters-list

How to check is all profiles are working fine

To see if profile and filters are working fine follow these steps:

  1. go to real time reporting page of that profile and click overview sub option.
  2. Visit that domain or subdomain preferably on a specific url from a new browser window. The page you are viewing should show up in real time tracking in few seconds. If not then you need to review the setup.
    google-analytics-real-time-subdomain-tracking
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments