How to filter out a subdomain in Google Analytics
Sometimes, you may want to filter out a subdomain (program.yourcause.org) or subdirectory (yourcause.org/program) from the rest of your Google Analytics data to get better insights into your audiences and their behavior. In order to do so, you don’t need to do anything complicated with two analytics codes/accounts or anything, you can just set up a separate view in your existing Google Analytics account. As an added bonus, you can assign different access levels to different people for each view. This will allow the right people to be able to easily switch between the different views / domains.
Here’s how to set up a view filter for a subdomain or subdirectory:
- Make sure you have admin/editing access to the Google Analytics account
- In the view column, create a new view for your subdomain or subfolder
- Implement any existing filters that you want to apply to this view as well (e.g. filtering out IPs from your office)
- Choose a predefined filter
- for subdomains: to include only traffic to the hostname that contain*
- for subdirectories: to include only traffic to the subdirectories that begin with*
- Add your domain or subdirectory
There are a couple of very important things to keep in mind when you filter out a subdomain:
- Filters are not retroactive. They will only apply to new data coming in. This is why it’s best to just create a new filter, and keep existing filters with all your data as is.
- Filters are destructive. You cannot reverse filters, so always make sure you have a view that contains all your clean data. If your goal is to filter out one subdomain from the rest of your data, we recommend to have at least three view filters:
- A View that has all your data
- A View that has ONLY data for your subdomain
- A View that EXCLUDES your subdomain
- Decide what match type fits your needs:
- ‘Begin with’ means nothing can come before the url you enter, but anything can come after
- ‘End with’ means that anything can come before the url you enter, but nothing after
- ‘Contains’ means that anything can come before and after the url you enter (e.g. campaign.program.yourcause.org and program.yourcause.org/campaign would both be included)
- ‘Equals’ means that it will only take data for the exact url you enter.
- If you need something more complicated (e.g. including or excluding multiple subdomains in the same View) you can create a custom filter and use regular expressions.
- Decide if you want to add a referral exclusion. If you don’t add a referral exclusion, your subdomain will show up as a referral to your own domain. If you do not want this, you’ll want to exclude this subdomain from your referral traffic in your property level > tracking info > referral exclusion list.
For more information check out Google’s resources on the topic:
If you need more help with Analytics, please get in touch. Our team would be more than happy to help.