[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.
- Go to google analytics admin page and create new account as shown below.
- Next screen will show tracking id and few options along with subdomain on-off option. Click on it to turn it 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
- 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.
- Click on new filter. And create a sobdomain include only filter as show.
That’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.
- 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:
- 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:
How to check is all profiles are working fine
To see if profile and filters are working fine follow these steps:
- go to real time reporting page of that profile and click overview sub option.
- 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.