There are many cases where you want to use “or” condition when using Google Analytics view filter. For example, imagine that you want to create a view that targets two specific directories. This can be done using regular expressions, but it would be extremely easy if you could simply say Directory A “OR” Directory B. These can be solved by using regular expressions.
On the other hand, let’s say that you want to construct a view filter returning the domestic IP address “OR” the domain of the staging environment. Since the first condition handles IP addresses while the second deals with domains, such a condition seems unattainable even with regular expressions.
In this article, I would like to show you how to create such a view filter.
Website Domains and IP addresses
Note: These IP address should be set in a custom dimension.
Google Analytics View conditions
Let me show you how to create the production view and the test view to meet these conditions.
These view settings cannot be achieved by just using view filter information introduced in blog posts and articles out there. However, a little-known feature called “Custom Field” makes it possible.
What is a “Custom Field”?
Fields that can be used in the view filter setting include “IP address”, “Host name”, and “Page path”. This is where the “Custom Field 1” and “Custom Field 2” actually showed.
This custom field is rarely discussed, so many marketers may not be familiar with the existence of the field. When I was thinking about how to realize the above use case with view filter, I decided to investigate the behavior of this custom field.
As a result of various tests, we’ve soon learned that this field seems to have a “role of memory (temporary memory)” in performing a series of processing of the view filter. In other words, a view filter that uses this field does not make sense by itself, but it can be used by using multiple view filters.
Steps to take
First, let’s create custom field filters
Then, create filters which
And here’s one thing you need to remember: these filters need to be adopted in this order because view filter would follow this order.
Another benefit of using this method is the ease of maintenance.
With the conventional method, it was necessary to create a “view filter for production” and a “view filter for testing” and regular expression like below is needed because this filter should match with multiple IP addresses.
To represent all these IP addresses with a regular expression;
This kind of technological mumbo-jumbo would be represented in regular expression as
So when the IP address of the company was changed, it was necessary to change both filters which uses a complicated regular expression, but with this method, only one change for a specific IP address custom field filter would be required.
This might NOT be the only case that this custom field filter comes in handy.
When you need some kind of view filters with complicated conditions, that might be when you should consider to use it.
As a marketing analytics consultancy, Principle helps brands get the tools, resources, and best practices in place to stay on the leading edge of Marketing Data, Analytics, System Integrations, and Performance Optimization.
Clients include global companies like Adidas, Coach, Shiseido, Nestle, and Red Bull, as well as fast growing Direct-to-Consumer brands focused on optimizing eComm performance across the funnel.
To learn how to best optimize your in-house marketing analytics approach for 2020, reach out to schedule a free, customized assessment from our marketing analytics experts.
Senior Data Engineer
Google Marketing Platform expert with experience working with enterprises deploying marketing analytics capabilities. Guy is focused on delivering marketing technology and supports companies drive their marketing execution through data.