Knowledge Base

How to Set Up a Filter in Google Analytics to Track Subdomains

Setting up a custom filter in Google Analytics allows you to view and analyze your subdomain traffic separately from your main website. This type of custom filter is very useful for websites with a blog, landing page, or wholesale site that is part of an existing domain. Here’s a quick and easy guide on how to set up a filter in Google Analytics to track subdomains.

Step 1: Make sure Google Analytics is set up on your subdomain and that both domains are using the same UA code

This may seem pretty simple, but it’s important! If both websites are not using the same UA property, you will not see any data when you create the filter. You can use the Google Tag Assistant to check and make sure the code is installed correctly. Once the Universal Analytics code is set up for both websites, you’re ready to move on to the next step.

Step 2: Create a new view in Google Analytics

Creating a new view in Google Analytics is simple. Once you are logged into your Google Analytics account, click on Admin and make sure you have selected the right account and property from the drop down menus. Once you have completed this step, click on view, select create new view, and give this view a name. It can be as simple as “blog”, the actual web address of your subdomain – e.g. blog.subdomain.com, or whatever is easiest for you and your team to remember. As you can see in our example, I named the view “all blog traffic”.

How to set up a filter in Google Analytics for subdomains - first add a new view in the correct UA property

If this is your first time creating a view for your Google Analytics traffic, it is a good idea/best practice to first create a test view with no filters applied. This ensures if you make a mistake, you will still have access to your unaltered, raw traffic data. Filters can be turned off, but they cannot be deleted and filtered data is permanently changed, so proceed with caution!

Final tip – make sure your time zone on your new view matches the time zone of your analytics property, otherwise you will get inconsistent data.

Step 3: Click on the new view you created for the subdomain and apply a custom filter

Now that you have created your view, make sure it is selected from the drop down menu on the admin panel and click on filters, + new filter, and select the create new filter radio button. Name your filter something that is easy to identify. Under filter type, select custom filter and click the include radio button. Under filter field, select hostname from the drop down menu and add your subdomain with backslashes before the periods. For example, if your subdomain is wholesale.testviewsite.com – enter it as wholesale\.testviewsite\.com

Adding a new custom filter to track subdomain traffic in Google Analytics.

Once the previous step is completed, you can click the verify filter button to make sure it is working correctly, but this step is not necessary. Once you click save, your filter will begin collecting and displaying data within the next 24 hours.

Step 4: Add a referral exclusion to your Google Analytics property

Adding a referral exclusion on your website property will prevent the subdomain traffic from showing up as a self-referral and skewing your reports. To apply the referral exclusion, return to the admin menu in Google Analytics. Once your property is selected, click on tracking info and then referral exclusion list. Add your subdomain URL and click create.

Create a referral exclusion in Google Analytics

And that’s it! Please let us know if you have questions and for more information on view filters, visit Google’s help section.

Also, if you need help using Google Analytics in general, we provide ongoing Analytics support for our clients. Contact us to learn more about how we may be able to assist you with tracking and interpreting your data.

Reader Interactions

Comments

  1. Jet Jet says

    Hi guys,

    This was really helpful. Thanks. I’m left with one more question. I set up the filter for my subdomain. Will the data from this subdomain be visible amongst the data in my main domain? In other words, do I need to create a filter for my main domain too, in case I want to see data from solely my main domain?

    Hope you can help!

    Thanks already.

    M.

  2. GizTech PUBG says

    Hi, in the referral exclusion list, fill with root domain or subdomain? cause many tutorials put the root domain in this form.

  3. Satwik Sanand says

    Hey, I created the filter as illustrated but once I click to verify it shows error as ” Resource is not available. Please try again later” Please tell me how can I rectify it. Thanks.

  4. Kumarpal says

    Hi,

    I saw different posts online regarding sub domain tracking. I found this post helpful and clear.

    I’m just confused about “Referral Exclusion”. Some posts are suggesting to use domain (example.com) while some suggesting to use subdomain (blog.example.com) in Referral Exclusion.

    I want to know does it make any change if I use domain name (example.com) in Referral Exclusion?

    – Kumarpal

    • Alan Milner says

      Hi Kumarpal, you need to have both domains in your Referral Exclusion list, but your main domain will have been automatically added when you create your Google Analytics account.

  5. Eric says

    Good article thanks. Using standard google analytics code, can I track sub sub domains? We have a system where we need to track xyz.abc.sample.com – Meaning I need to know traffic for xyz. Is this possible?

  6. Ken Guie says

    Great article, been working with basic GTM and GA set up at work but I usually don’t handle that but got intrigued about my own site as I am going through a redesign.

    I set up the subdomain tracking just now but on the main page, when I visit my homepage or subdomains, it seems to register as a visit to the root page.

    Is there a way to get that tracking correct so in real time, if i visit the subdomain, it tracks me as visiting the subdomain and not ‘/’ ?
    Thanks!

  7. Liz Grajeda says

    Hi Emily,

    You would still use an include filter, only you would do it for both views. Let’s assume the dev site URL is http://www.site1.com and the Analytics view is called “View 1” – your include filter on “View 1” would be www\.site1\.com. If your splash page is http://www.site2.com and the Analytics view is called “View 2”, then your include filter on “View 2” would be www\.site2\.com. Then on “View 1”, your referral exclusion would be wwww.site2.com and on “View 2”, your referral exclusion would be “www.site1.com” – you might possibly have to add the non-www versions of these as well.

    Does that make sense? Please let me know – thanks for the comment!

  8. siva says

    Thanks for a step by step clean approach. Was mislead by many so called seo specialist by not giving the clean steps. Good Job.

  9. Kasey Larsen says

    Hi Sunil,

    Sorry for the overdue reply. You can set up customer filters in your view to include the Field filter of “Country”. Go to Admin, then go to Filters in the right hand column with the correct View selected. Click +Add Filter. Then, choose “Custom” for your filter type. Make sure you have “Include” selected, and search for “Country” in the drop down.

  10. Cody says

    Hi Liz,

    Could you explain / elaborate on a couple of points for me:

    1. In Step 3, why is it important to add the backslashes before the periods?

    2. In Step 4, if the users aren’t counted as referral traffic, are they counted as whatever metric preceded the referral?

    • Liz Grajeda says

      Hi Cody,

      According to the Google Analytics associate I spoke with last time, you don’t need the back slashes anymore. They were necessary to tell Google Analytics that you meant “.” and not a wildcard expression. You can read more about regular expressions here: http://www.analyticsmarket.com/blog/regular-expressions-for-google-analytics

      Once this is implemented, users will be attributed to the previous / actual step they took to find your website.

      • Avinash says

        Hi Liz,

        After adding the sub-domain in the referral exclusion list also, I am seeing the traffic on main domain as “referral” from the sub-domain. The initial source/medium (google/organic) is not being shown. Any idea why this happens?

        Also, will it take a day or two GA to take exclusion list into consideration?

        • Michele Moody says

          Hi Avinash,

          Adding your subdomain to the referral exclusion list should prevent traffic on the main domain from recording as a self referral for all future traffic. The referral exclusion list should be immediate, but isn’t retroactive. So any past traffic from your subdomain will still show as referrals.

          However, since GA uses the last-non-direct-click attribution model, returning visitors might show up as subdomain referrals after you set the exclusion. For example, let’s say a user comes to your main domain via referral from your subdomain (session A) before you set the referral exclusion, then returns directly (session B) to the site after you’ve set the exclusion. Session B will show up as a referral from the subdomain, since Analytics attributes to the medium immediately before a direct click. More information here.

          If you suspect that the referral exclusion isn’t working at all you may want to try adding your entire domain as a referral exclusion, since referral exclusions use CONTAINS matching. So exclude “testurl.com” instead of “blog.testurl.com”

Leave a Reply

Your email address will not be published. Required fields are marked *