Integrating Google Analytics into a subdirectory site isn’t difficult. All you need to do, is make the necessary considerations; take a few simple steps to integrate Analytics; create new views in Analytics and apply filters to the respective views, depending on your setup.
This post will guide you through the process step-by-step.
Possible Subdirectory Scenarios
Scenario 1: Subdirectory as an independent site, possibly hosted on a large site
A site can be “hosted” on another website, without being connected to it in any way concep-, topic-, owner- or strategy-wise. This is often the case of small blogs, hosted for free on websites as WordPress.com. They are usually “nested” under subdomains or in subdirectories, depending on the business strategy of the provider.
In such cases, the following applies:
- You do not have access to the main site’s Analytics account
- You cannot track web traffic for the whole property
- You can track web traffic for the subdirectory site (if the provider allows analytics to be implemented)
Scenario 2: Subdirectory as a Site’s Subdivision
A site or landing page, installed in a subdirectory, can be a part or division of the main site under the domain. This is the case for many sites, serving content that cannot or should not be served via one and the same site, publishing special offers, or serving content in different languages.
A decade ago it was much more popular to use subdomains for such purposes but due to a long list of technical advantages connected to using subdirectories, this approach is now widely adopted.
In the case of subdirectory sites closely related to the main site, the following applies:
- You do have access to the main site’s Analytics account
- You can track web traffic for the whole property
- You can track web traffic separately for the main site and each of its subdivisions
If you are interested in this type of Analytics integration only, please scroll down to the section Integrating Google Analytics into a Subdirectory Site: Scenario 2.
Integrating Google Analytics into a Subdirectory Site: Scenario 1
If your website resides in a subdirectory of a domain that you don’t own or control, setting up Google Analytics is quite straightforward: you have to open an account and add the code snippet to your site’s pages’ head. Here is how you can do it step by step:
- Go to Google Analytics’ home.
- Sign in with your Google account or create a new account
- On the next screen, click on Sign up to the right.
- Fill out the form to create your new account
- Accept the terms and conditions
- You are now led to a screen displaying your GA tracking code and instructions on how to integrate tracking into your website.
- Copy the snippet
- Save your settings. That’s it. Check the status of your integration after 24 hours to make sure everything works.
Integrating Google Analytics into a subdirectory site that isn’t connected to the main site is simple, as it doesn’t require any customizations of your Analytics views in order to work. By installing a separate tracking code (different than the one on the main site), you get webtraffic data only for your subdirectory site and disable data leaks to the main site’s Analytics account.
Integrating Google Analytics into a Subdirectory Site: Scenario 2
When a large website concept requires that you branch the site and create subdirectories, you end up in a sort of confusion, wondering how to implement Google Analytics in order to be able to correctly track data for the main site and its subdirectories.
It is, however, a simple nine-step procedure. Here’s what you have to do:
- Find the tracking code or ID you use on your main site and insert it into the subdirectory as described in Scenario 1. Alternatively, you can insert the code snippet manually in the head of each page of your site that you wish to tack. Remember to place it as close to the opening head tag as possible.
- In Google Analytics, click on Admin and find Create new view
- Choose the appropriate settings and a name for the new view and click on Create view. Create two views: one for tracking traffic to the subdirectory only and one excluding traffic to the subdirectory.
- Navigate to the view excluding traffic to the subdirectory and click on Filters in Admin.
- Click on Add filter
- Fill out the fields as shown in the screenshot below, replacing subdirectory with the actual subdirectory name, to create a filter excluding traffic to the subdirectory from reports.
- Verify filter and click on Save
- Navigate to the view showing only traffic to the subdirectory. In Admin, click on Filters->Add filter again and fill out the fields as shown in the screenshot below to create a subdirectory-traffic-only view in Google Analytics
- Verify filter and click on Save
Remember that you should always leave your All Website Data view unmodified. If you want to use filters, you should always apply them to custom views!
Note: If your website has multiple subdirectories, Google Analytics integration might be more complicated, as it will require the creation of multiple filters and views, making traffic tracking intricate and incredibly time consuming.