Do you want to give your Google Analytics filters knowledge a real boost?
I know what you think, filters are a pain. Well, not anymore after your have read this guide!
As you probably know, filters are extremely important. They give you the flexibility to modify the data that is being collected in each of your Google Analytics views.On default, Google Analytics collects data from all of your visitors.
But what if you only want to store a subset of the data in a view?
That’s when Google Analytics view filters are the solution.
Filters and views are the building blocks of your Google Analytics account.
In this article you will learn everything about view filters.
From setting up basic and advanced filters to dozens of tips to effectively work with filters in Google Analytics.
Further, I’ve put together a handy bonus guide that contains the Google Analytics filters I use for my clients on a daily basis. Including examples and best practices not found in this post.
- View Filters vs. Table Filters
- View Filters vs. Segments
- Filter Types
- Filter Order
- Filter Manager
- Filters and Related Topics
- BONUS examples
- Concluding Remarks
View Filters vs. Table Filters
Google Analytics allows you to set up view filters within the admin and reporting interface.
Besides that you can work with table filters in the reporting environment.
It’s important that you understand the difference between view filters and table filters.
Take a look at the table below:
As you can see, Google Analytics view filters have a permanent effect on the data that is being collected in a view.
That’s why only users with edit rights are able to set up and configure these filters.
View Filters vs. Segments
Both view filters as well as segments can be really useful. However, they serve different needs.
It’s important you know the differences, strengths and weaknesses of both.
In the table presented below you can see the main differences between both segmentation methods:
In this post I won’t dive deeper into segments.
Read the following posts if you want to learn more about Google Analytics segments:
Google Analytics Filter Types
By now you know that you have to be really careful with filters. One mistake cannot be undone.
Let’s take a look at the different filter types before we move to an in-depth overview of useful examples.
Easily said, Google Analytics has predefined (system) filters and custom filters.
It depends on your knowledge level (will soon be increased :-)) and specific needs which ones you should use.
1. Predefined Filters
Predefined filters are easy to set up and don’t require you to be an expert here.
At the moment there are 32 (2 x 4 x 4) unique predefined filter combinations.
You can either exclude or include one of the following dimensions.
1. ISP domain filter
Most people can easily retrieve their IP addresses, but have a lot of difficulty finding their ISP domain name.
ISP stands for Internet Service Provider. Your ISP domain can be found via this URL.
Be careful if you exlude an ISP domain. You might not only exclude your own visits, but those of other visitors as well.
That is why I advise to work with IP addresses or ranges if you want to filter out your own behaviour (recommended best practice).
2. IP addresses filter
Your IP address can also be found via the URL I shared in the last paragraph.
Let’s assume your IP address equals 18.104.22.168.
This is the filter you need:I hear you think, what should I do if I have a range of IP addresses?
This is when regular expressions come in handy.
I recommend to use a “custom filter” – something I will talk about soon – if you want to exclude an IP range.
Here you see an example of an IP addresses range filter in Google Analytics:3. Subdirectories filter
Let’s take a look at LunaMetrics.com (company specialized in the field of Analytics):
Their blog is one of the main parts of the website structure.
Following the link and a recently published blogpost reveals their website structure in more detail:
What does it tell you?
All their blogposts sit in the subdirectory /blog/.
It might be a good option to use an include filter on subdirectory to enhance the insights on their blog performance:
I have used “that begin with” here.
The reason why is that Google Analytics captures hostnames (domain name) but doesn’t display it in reports on default.
You could also use “that contain” here. For the sake of this tutorial I just want to be as accurately as possible.
Use your imagination to come up with great filters for your specific situation.
A last tip here is to check out Screaming Frog if you want to spider website structures in a quick way.
For less than $15 a month you can get a full SEO spider licence, which is definitely worth it!
4. Hostname filter
Your website hostname is often also called domain name.
However, it doesn’t include http(s)://.
My website hostname is online-metrics.com.
If your Google Analytics implementation only involves one domain, I recommend to set up an include filter on this domain.
This filter prevents others from hijacking your GA tracking code and placing it elsewhere. Normally this would affect your traffic stats.
Besides that it helps counter a large part of other SPAM traffic.
Three important things to remind:
- You should use only one include filter of the same type. For example, one include filter on medium=cpc and another include filter on medium=organic will result in no data being collected. Instead, you should use one include filter with a RegEx -> cpc|organic.
- Learn all about regular expressions in Google Analytics to become a Google Analytics filter pro.
- If you are using different filters for different purposes, you need to set up a new view for each of them and apply the filters accordingly.
2. Custom Filters
Custom filters in Google Analytics can be divided into four groups:
- Search and Replace
Here is an overview of all the current custom exclude/include filter combinations:
The possibilities are almost endless here! The main categories within this filter group are:
- Content and traffic
- Campaign or adgroup
- Mobile device
Google Analytics reads lowercase and uppercase as two different characters.
This can cause data issues. Please review the following scenario:
- John tags an email campaign with utm_medium=Email.
- Peter tags an email campaign with utm_medium=email.
In this case Google Analytics would register two different media for the email campaigns. This can possibly ruin your data.
This is when lower- and uppercase filters come in handy.
I prefer to use lowercase filters over uppercase filters.
Here is an example:
Back to the scenario of John and Peter. This would fix any issues with capital letters, utm_medium would be “email” in both cases.
I recommend to set a lowercase filter on:
- Campaign Medium
- Campaign Source
- Campaign Name
- Campaign Term
- Campaign Content
- Request URI
Lower- and uppercase filters can be applied to all areas except location based filters.
Search and Replace filters
Search and replace filters can be really useful if you want to transform your data.
If another company is sending traffic with the wrong utm parameters, you can use a “search and replace filter” to correct the utm parameters before they are stored in your Google Analytics account.
Replace string is either a regular string or it can refer to group patterns in the search expression using backslash-escaped single digits like (\0 to \9).
If you want to have backslash(‘\’) in the replacement string you must use double backslashes (‘\\’) instead.
A common use case for the “search and replace filter” is to turn multiple URLs into one.
For example, to merge ‘example.com/article/running/10k.html’ and ‘example.com/article/swimming/100m.html’ so that your reports for the views for which you will apply this filter will show ‘example.com/article/’, please follow these steps:
The dot-asterisk (.*) means, take any random combination of zero or more characters.
In this case I want any characters behind /article/ to be removed from the URL.
Search and replace filters can be applied to all areas except location based filters.
Advanced filters can be really daunting at first. Before trying to set them up I recommend to learn a lot about regex first.
In short, they allow you to combine fields into new variables.
A useful example is shown below:
Here I instruct Google Analytics to take the hostname and request URI and combine them together into the request URI.
On default, Google Analytics doesn’t show the hostname in the page report.
This filter allows the hostname to actually appear in the report.
A disadvantage of using this filter is that it breaks the links to your website in the content report, i.e. you won’t be able to click on a link that leads from Google Analytics to your website.
But, it can be very useful in a multiple domain implementation to apply this filter to your data. The choice is yours!
Advanced filters can be applied to all areas except location based filters.
- It looks like Google Analytics made a mistake by only including location based filters in the include and exclude filter group.
- The number of different Google Analytics filters are literally unlimited.
It’s important to know how view filters are processed, especially if you plan to use many different filters.
Filters are applied on the view level and you can set the filter order per view.
How to get to the “assign filter order” screen:
- Navigate to the admin overview screen
- Select the appropriate view
- Click on filters (under view)
- Click on “Assign Filter Order” (it’s next to red “new filter” button)
Here is an example:There are just a few options here:
- Move a filter up (so that it is processed earlier)
- Move a filter down (so that it is processed later)
- Save settings
Include and Exclude Filters
Include and exclude filters aren’t affected by filter order if you only use these filters.
I have mentioned before that you can’t include two include filters of the same type.
Please look at the examples below:
In the first example, Google Analytics won’t collect any data where the two filters are applied.
In the second example, where a regular expression is used, Google Analytics will only collect organic and cpc tagged media.
Keep in mind that if you use a Search and Replace, Lower/Uppercase, or Advanced filter to modify the URL or other field that you are using to include or exclude, those will be affected by filter order.
Example: How Filter Order Effects Data
Let’s assume you have set up the following filters:
A company called Rainbowfilters has many external email campaigns running that are incorrectly tagged.
These campaigns show up in Google Analytics under a separate medium: e-mail instead of email.
That’s why they set up these filters to correct the issue.
What’s Wrong and How to Solve
The include filter is processed before campaign medium=e-mail is changed into campaign medium=email.
This causes the correctly tagged email campaigns not be measured in Google Analytics.
The fix is easy: simply place the Search and Replace filter before the current Include filter.
Make sure you understand how the processing part works before you go wild on Google Analytics view filters.
You can manage your filters on two different levels:
Filter Management: Account Level
On the highest (account) level you can:
- Review all filters in your Google Analytics account
- Delete or modify filters
- Create new filters
- Add or remove already created filters in one or more views
Filter Management: View Level
On the lowest (view) level you can:
- Review all filters in your Google Analytics view
- Modify view filters
- Create new filters
- Add or remove already created filters in selected view
- Assign the filter order for this view
Bare in mind that you need edit rights at the account level to create new filters.
This is because new filters are stored at the account level.
Take a look at the ultimate guide to setting up your Google Analytics account if you want to learn more about the other settings as well.
Filters and Related Topics
Filters are related to many different reports and settings in Google Analytics.
In the following chapters I provide you with a broader view of filters and how they relate to other settings.
Filters and Site Search
Google Analytics allows you to measure your internal site search and this site search report can bring you tremendous insights.
It depends on your site structure whether you need filters or not to correctly measure site search behaviour in Google Analytics.
In some cases – if the site search query is not visible in the URL, you need to modify your implementation.
Google Tag Manager will be a great help if that’s the case. This is out of scope for this article.
I will describe two screnario’s here.
- http://www.example.com/search?q=filters (filters are not needed)
- http://www.example.com/index/search/filters (filters are needed)
In the first scenario the search term “filters” can be easily extracted from the URL.
It is connected to the query parameter “q”.
Just head over to the overall “view settings” and fill in the following:
You can tick the “strip query parameters” box if you don’t want the search term to appear in your content report.
Like I mentioned in the introduction, sometimes filters are needed to process site search parameters in the correct way.
Let’s take another look at the URL:
Since there is no active query parameter in this URL, you need to set up a filter to send the site search data into Google Analytics.
These are the parameters you need:
- Field A -> Extract A: Request URI: ^/index/search/(.*)
- Output To -> Constructor: Search Term: $A1
- Select ‘Field A required’ and Override Output Field
After a couple of hours you will see the site search terms to appear in Google Analytics.
The same technique can be used to extract site search categories from the URL.
Filters and Real-Time
Already for quite some time, Google Analytics obeys your filters in the real-time reports:
In this particular data view you can see one page (the one I am visiting now).
I have only included my IP address here so visitors coming from other IP addresses are not registered.
It’s maybe not the best way to test your filter set up, but still it is great that real-time actually processes your filter set up.
So that your data in real-time will match your Google Analytics reports later on.
Filters and Sampling
I have already published a comprehensive guide on sampling in Google Analytics. Make sure to read that post as well!
In general there is no sampling problem if you are:
- Lucky to be a Google Analytics Premium User
- Only looking at aggregated reports without segmentation
- Running a website that doesn’t get ten thousands of visitors each day
You could have a data sampling problem if you are:
- Unlucky to not have access to Google Analytics Premium
- An advanced user who segments a lot to get more insights
- Running a website with loads of visitors and pageviews each month
In the example above you see that only 2,4% of the sessions are included in the sample.
Well, as you might guess, this data is far from accurate.
I always try to avoid sampling when doing data analysis.
Please aim for at least 80-90% sample rate if you want to draw any reliable conclusions from your data.
How Filters can Help
The standard reports are a great start, but sometimes you want to dig deeper in your reports.
Maybe you want to look at the page reports for just your affiliate visitors, and applying the affiliate medium advanced segment forces you into a sample.
- You can create a new view to just capture your affiliate traffic.
- Then put a filter on that view to only allow affiliate traffic.
- If you apply any segments in the view it will get sampled
- Standard reports will hold the unsampled data for just that affiliate traffic.
You can repeat this procedure to filter on region and set up several different data views.
It might be a solution for some of your sampling issues!
Besides that it is very handy if you want to give restricted access to some users.
Filters and Channel Groupings
Channel groupings are another way of looking at your traffic data/sources.
This instead of looking at the source/medium report:
One thing to remember here is shown below:
Filters are not working…
Yeah, I have seen (too) many Google Analytics accounts where filters caused real data issues.
Follow these steps to minimize potential issues with your filters:
- Always keep a raw data (unfiltered) Google Analytics view.
- Educate yourself on regular expressions before trying out advanced filters.
- Don’t apply new filters to existing views without testing them first.
- Use testing views for the sole purpose of testing your new filters.
- Use the filter verification tool that is built-in in Google Analytics.
Filters Verification Tool
What you should know:
- Filter verification is based on a subset of your available data and may not be 100% accurate in all cases.
- Currently filter verification doesn’t work on advanced and location-based filters.
- Filter combinations cannot be processed.
- Adding a filter name is required to use the verification tool.
Example of Google Analytics filter verification:
I made a fictional filter to include only organic traffic.
As you can see, this filter would impact the collected data immensely.
You would only store organic traffic data from now on.
I have already included many filter examples in this article.
There are three more filters I like to share with you.
- Remove all query parameters
- Remove slash (/) at end of URL
- Exclude internal traffic
1. Remove Query Parameters
In the Google Analytics view settings you can add one or more query parameters you like to filter out of your Google Analytics view.
But what if your website only contains technical query parameters you don’t need in your data analysis?
One option would be to separately filter them out of your Google Analytics view.
Another (maybe better) option would be to use a Google Analytics filter here:
This one will do the trick. After setting up this filter you will probably “lose” a lot of your fake unique URLs.
Please be very careful with using this filter.
You need to be 100% sure that the query parameters are not needed in your analysis.
2. Remove Trailing Slash (/) at End of URL
Very often URLs are accessible with and without a slash at the end.
For SEO purposes you need to set a canonical URL if one URL is not redirected to the other.
In Google Analytics you don’t want to see duplicate URLs here; that’s why you need to set up this filter:
3. Exclude Internal Traffic
This is not the most advanced filter to include, but it is of crucial importance.
Two factors that determine the importance:
- How much traffic do you get? (the less the bigger the influence on your data)
- How many pageviews do you, your colleagues, partners etc. generate? (the more the bigger the influence on your data)
As a best practice I recommend to filter out any IP addresses that contain artificial traffic.
Artificial traffic is traffic that impacts your numbers in an incorrect way.
Here is a fictional example on filtering out an IP address:
In the first chapters of this article I have already explained about how to filter an IP address range from your Google Analytics data.
I hope you have learned a lot about Google Analytics filters after reading this guide.
Review these eight points before putting things in practice:
- Always keep an unfiltered data view.
- Always keep a profile with an include filter on internal IP addresses (for testing purposes).
- View filters belong to a long time segmentation strategy, are future based and cannot be undone.
- Segments are useful for ad hoc segmentation, are based on your current data and don’t impact stored data.
- Apply new filters to a secondary view first before adding them to your main view.
- Filters are useful to any type of website (lead generation, e-commerce, service, blogs etc.).
- New view filters don’t work directly; it can take up to 1 or 2 hours before they actually do their job.
- Don’t overlook filter processing order if you work with different (advanced) filters.
Is there anything you like to add? Please shine in with your experience on view filters.One last thing... Make sure to get my extensive checklist for your Google Analytics setup. It contains 50+ crucial things to take into account when setting up Google Analytics.