Why it is important to test your Google Analytics filters
Filters are an excellent way of polishing your Google Analytics, they allow you to re-organize your real user data or block junk traffic like spam. However, if they are incorrectly configured they can ruin your Analytics.
So before you hit the save button it is important to make sure your filter work as expected. Here are some reasons why:
- Lets you see the effects of your filter live. It takes time (as much as 24 hours) before filter effects become visible in your data, so you won't know instantly if the filter is working as desired.
- Prevents data loss. Filtered data cannot be restored or changed in any way. Filter verification can help you catch errors before you save the filter and possibly impact real data in undesirable ways.
- Makes trying out variations of your filters much more convenient.
In summary, it will save you time and protect your data by making sure your filters are correctly configured before going live.
3 ways of testing your Google Analytics filters
There are three ways of verifying your filters:
- Built-in Verification tool; fast but inaccurate in some cases.
- Using an online REGEX tool tester; not only can help you test your filter but also can help you improve your REGEX skills
- Using an in-table temporary filter; takes more time to prepare, but it's a lot more accurate.
Option 1: The built-in filter verification tool in Google Analytics
This feature allows you to test your filters quickly right in the view filter window, however, it has some limitations:
- The built-in Filter verification tool uses only a small sample of your data.
- You cannot verify filters for IPs or Geo-based fields.
- You cannot test advanced filters.
How to verify from the filter window
To verify a filter in Google Analytics using the built-in feature:
- Create a filter at a View level (Creating it the account level won't show this feature)
- Configure your filter (Not available for advanced filters and IP filters)
- Click Verify this filter almost at the bottom of the window and analyze the “Before” and “After” table as explained below.
Understanding the filter verification table
- Only data that will be affected by the filter will be shown in the table,
- The left side of the table shows the rows that would be excluded from your reports after the filter starts working,
- The right side of the preview table shows data that will be included again only if it was excluded previously,
- For Include Filter: the rows on the left side will show records that don't match your filter parameters,
- For Exclude Filter: the left side will show the records that match your filter parameters.
Error: "This filter would not have changed your data"
If you don't see the verification table you will likely get this message:
This filter would not have changed your data. Either the filter configuration is incorrect, or the set of sampled data is too small.
This happens when the filter verification can't find a match in the sample data. That doesn't necessarily mean that your filter is incorrectly configured. There are three possible reasons for this to happen:
- Incorrect filter configuration: Maybe you made a mistake defining the filter. Check your filter pattern for misplaced or extra characters or spaces. You can use any of these online free tools to check your regular expressions: regex101 or regexr
- The filter (or a similar filter) is already saved: If you save the filter and then try to verify it, Google Analytics will consider that there is already a filter saved with the same configuration so this "new filter or version" won't change anything. If you want to verify the filter, you will have to delete it first and then try again.
- No match in the sample data: If you ruled out the other 2, then it just means that the filter verification tool didn't find any match in the sample data. If this is the case, you should use the second method to verify your filter Quick Segment.
Option 2: Verify the filter using a quick Segment
When your filter is more complex or the built-in filter verification gives you an error, you can use a quick segment to verify your filter. It takes a little more time, but the results will be more precise a sampled data won't limit you.
Segments are similar to filters; the difference is that segments are not permanent, and they can be applied retrospectively to any date range.
How to test a filter with a quick segment?
To test a filter in Google Analytics using a quick segment:
- Go to the corresponding report for example, if your filter is:
- For referrals/campaign source go to the referral report,
- For hostnames go to the hostname.
- Once you are in the correct report, select a year worth of reporting then click on the blue text that says advanced (at the top of the report next to a search box)
- Configure the fields as follows and then click Apply
- 1st dropdown: Whether you are including or excluding in the filter select Include
- 2nd dropdown: Leave it as it is (the dimension of the report is selected by default)
- 3rd dropdown: Select Matching RegExp
- Text box: Enter the expression you want to verify.
- Click Apply. Now the report below should show all the entries you added to the expression only. If you see more or fewer entries than you want then check for typos, extra characters or extra spaces. TIP: a common mistake is leaving a pipe | at the end of the expression.
- [Optional] If your filter is complex and you want to make sure that you don't forget any entry, click again on the blue text advanced and select Exclude this time, without changing anything else. Now go through the report and if you see any entry on the list
- For example, if you are creating a Hostname filter for Spam, you shouldn't see any valid hostname in the report.
- Once you are happy with the results, you can create the filter.
A simple demonstration of the filter verification
Let's say that I want to create a filter to:
- Exclude all the data coming from the Desktop version of Facebook.
I will use the different Facebook referrals for mobile and desktop:
Note: Facebook sometimes adds a letter "l" shows like l.facebook.com this is some kind of protection for the privacy of the users.
The first approach of the filter to exclude Facebook referrals from Desktop will look like this:
- Admin in GA > Select a View > New Filter > Select Custom Filter > Campaign Souce.
Note: The pipe character | means OR in a REGEX
So let's verify if the filter will do what I want.
Using the built-in feature to test the filter
So after configuring the filter with the first expression facebook.com|l.facebook.com, we click on verify this filter. On the preview table, we see that all the Facebook referrals will be filtered not only the desktop ones. 🙁
This happens because custom filters work with regex so even a partial match will count as a match.
To fix it, we have to adjust the filter pattern like this ^facebook.com|^l.facebook.com (The caret character ^ means "begin with" in REGEX)
After changing the regex and verifying again, we get the desired result! So we can apply the filter safely.
But what if there is not enough data and the verification gives you an error. In that case, you can use the quick segment
Using a quick segment to test the filter
Following the quick segment verification instructions with the same Facebook example (exclude Facebook referrals from a desktop)
1. We go to the report Referral (Source) report
2. Now we test the expression.
- The First expression facebook.com|l.facebook.com (The pipe character | means OR in REGEX)
When we check the report we see the referrals for Mobile so the expression is not ok. 🙁
- So we try the second expression ^facebook.com|^l.facebook.com (the caret character ^ means "begin with" in Regular Expressions)
After fixing the expression the verification shows only the desktop version so that means that the filter will work as we expect.
Wrapping it up
By verifying your filters, you will be safe in the knowledge that you aren't losing any valuable data.
If your filter is simple and you know what you are doing, a quick test with the built-in feature Filter verification. If you are getting the message "This filter would not have changed your data", don't worry! there is a big chance that the sample data used by the tool is not enough.
On the other hand, if the filters are complex, you are getting the error above, or you simply want to be 100% sure that your filters are correctly implemented using the quick segment is the solution.
Help me, help you
I would love to hear your thoughts, criticisms, and experience with this topic and this guide. Help me to help others with similar issues.
Follow me on my next blog for more valuable information!