Google Analytics for Subdomains
Adding Google Analytics to a site is relatively straightforward. You create an account, get the tracking code, and add it to your site. I know that my site is a low-traffic site. So, tracking page views isn’t critical. But I find it interesting regardless.
I noticed that the domain name wasn’t showing in the reports. So, page views from this site and one of my subdomains used for scheduling meetings showed together. It would be great if Google Analytics would show the domain to disambiguate the traffic.
- Fortunately, I found it was pretty easy to implement:
- In Google Analytics, click the Admin link.
- In the View column, click the Filters link.
- Click the + Add Filter button to bring up the Add Filter to View page.
- Enter a filter name. I picked “Show Subdomain.”
- Set the Filter Type to “Custom.”
- Select “Advanced.”
- In Field A –> Extract A, select “Hostname” and enter
(.*)
. - In Field B –> Extract B, select “Request URI” and enter
(.*)
. - In Output To -> Constructor, select “Request URI” and enter
$A1$B1
. - Click the Save button.
The above filter essentially rewrites the URI shown in Google Analytics to include the hostname. Instead of seeing “/tag/technology,” for example, it will show “acegayhart.com/tag/technology.”
Note that this filter does not apply retroactively. I was able to verify it shows correctly in real-time reports; it may take a day or so for data to accumulate for it to replicate to the other reports.