Tracking subdomains in Google Analytics is a little tricky since there is no “easy” button to push. You will need to configure analytics properly to track and display data correctly.
In this guide you will learn how to:
- Install Google Analytics for each subdomain
- Set up profiles for each subdomain
- Display subdomains in the main profile
Install Google Analytics for Subdomains
Google Analytics tracks one domain or subdomain by default. You need to modify GA’s installation in order to allow proper tracking of your subdomains. If you do not, session information will not be shared across your subdomains and your data will be unreliable when users visit more than one of your subdomains in one visit.
An example is if you have your shopping cart on a separate subdomain. Your data for the shopping cart will be unreliable because once a user accesses the cart it will start a new session. You will lose data about the conversion because your installation is not configured to share cookies across subdomains.
To correctly install Google Analytics to track multiple subdomains, see the code below.
Notice there is only one new line of code in this example.
You can also get this code if, in Google Analytics, you go to Settings -> Tracking Code -> One domain with multiple subdomains.
Add this code to all of your subdomains. There is no need to alter it for every subdomain.
Set Up Profiles For Each Subdomain
Do not create a new Google Analytics account for each subdomain. Sure, it would technically work. There is nothing in the world to stop you. But there is a better way.
Create one Google Analytics account, and then create a profile for each subdomain plus another profile that tracks all subdomains collectively. So if you have two subdomains (www and mobile) you will want three profiles total. One for www, one for mobile, and one to track both subdomains. This will take some time to set up, but will be well worth it in the end.
Once you have created each profile, it’s time to apply the filters.
We need to apply a filter to ensure that we track only traffic for the profile’s designated subdomain. Go to Admin -> Profiles -> Filters -> New Filter and refer to the screenshot below.
Applying this filter to your profile will ensure that this profile only tracks traffic for the specified subdomain. In this case, www.yoursite.com. Remember, www is a subdomain itself. Repeat this filter for each profile that you created where you need to isolate a subdomain.
Display Subdomains in the Main Profile
By default, Google Analytics does not show the domain or subdomain in your reports.
This poses a problem when tracking multiple subdomains in one profile because you will not be able to tell the difference between your subdomains in your page list unless you add a filter to display the full domain.
In the screenshot below, this is the default view of pages in Google Analytics. Note how it only shows the path and not the domain name or subdomain. You can see this for yourself by going to your page list in analytics, Content -> Site Content -> Pages.
So we need to create a filter that will show us the subdomain, domain name, and path.
In your main profile that has multiple subdomains, go to create filter. Refer to the screenshot below to see how to apply filter.
After applying this filter, the entire domain and path will appear in your page list, and you will be able to differentiate between traffic for each subdomain.