How to use “OR” condition in Google Analytics view filter without regular expression

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.

Google Analytics View Filter Example

Use case

Website Domains and IP addresses

  • Production environment domain: “www.example.com”
  • Staging environment domain: “staging.example.com”
  • IP address of the company
    • Los Angeles Headquarter: “100.2.1.100-100.2.1.199”
    • Silicon Valley branch: “100.3.1.201”
    • Tokyo branch: “100.4.3.301”
  • IP address of Website developer company: “100.1.1.100-100.1.1.199”
  • IP address of Ad agency : “100.5.4.401”

Note: These IP address should be set in a custom dimension.

Google Analytics View conditions

  • Production view:
    • Includes access from the production domain
    • Excludes access from IP addresses of
      • The company (Headquarter and all branch offices)
      • Website developer company
      • Ad agency
  • Test view:
    • Includes access from the staging environment
    • Includes access from IP addresses of
      • The company (Headquarter and all branch offices)
      • Website developer company
      • Ad agency

Let me show you how to create the production view and the test view to meet these conditions.

Implementation method

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

  1. That returns “insider” if the access is to the staging domain
  2. That returns “insider” if the access comes from the IP address of
    • Los Angeles Headquarter
    • Silicon Valley branch
    • Tokyo branch
    • Website developer company
    • Ad agency

Then, create filters which

  • Exclude the access if the custom field matches with “insider”.
    • This is for the “Production View”
  • Include the access if the custom field matches with “insider”.
    • This is for the “Test View”

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.

For example:
To represent all these IP addresses with a regular expression;

“100.2.1.100-100.2.1.199”
“100.1.1.100-100.1.1.199”
“100.3.1.201”
“100.4.3.301”
“100.5.4.401”

This kind of technological mumbo-jumbo would be represented in regular expression as

^100\.((1|2)\.1\.1[0-9][0-9]|3\.1\.201|4\.3\.201|5\.4\.401)$

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.

Example View Filter Settings

Google Analytics Custom Field Example

Google Analytics Custom Field Example 2

Summary

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.

 

About Principle

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.

Do you need to enable the right marketing data to grow your business?

Good data practice starts with good data collection. At Principle, we enable, integrate, and manage your marketing data. Click here to learn more about our agency services for:

Share this article:

Ready to discuss your data needs?

We're ready. Let's Talk.

Get in touch

Or call us now: (424) 218-9752