How to Exclude Multiple IP Addresses in Google Analytics

Written on January 16, 2020 by Caterina Lyng

How to exclude multiple IP addresses in Google Analytics? On support.google.com, you can find examples on how to exclude a subnet of IP addresses, IPv6 addresses, and how to use regular expressions for more complex filters.

In this blog post, I show how I entered and tested IP address exclusion using regular expressions (regex) on Google Analytics.

Summary

  • Go to admin in Google Analytics
  • Create a new filter
  • Enter a filter name
  • Select filter type "Custom"
  • Select Exclude
  • Select "IP Address" in the filter field dropdown
  • Enter your filter pattern. E.g. ^111\.135\.186\.256|40\.177\.726\.99$
  • Select where to apply the filter
  • Save

Regex to Exclude Multiple IP addresses

In the image below, you can see how my Google Analytics looked, right before I saved the filter with two IP addresses.

Multiple IP addresses with regex / regular expression in Google Analytics filter

Example of filter with multiple IP addresses

Why Regex / Regular Expression Pattern?

Since I am only excluding two IP addresses, could I not just have made two filters following the steps of "Exclude a single IP address"? I could, but I chose to use regex to keep my IPs in one field.

I like regex because it can let you create more flexible and efficient definitions of what you are looking for. This is an example from support.google.com:

...you could use a regular expression to exclude any data from the entire range of IP addresses that serve your employees. Let’s say those IP addresses range from 198.51.100.1 - 198.51.100.25. Rather than enter 25 different IP addresses, you could create a regular expression like 198\.51\.100\.\d* that matches the entire range of addresses.

You can find much more information about regex on support.google.com: About regular expressions (regex).

How to Test Regex

You can find quite a few regex / regular expression testers and debuggers online. I used this one at freeformatter.com: regex-tester.

Enter your regular expression and the entry or entries you want to test against. Everything should be great, if you get a match.

Successful test a regular expression with multiple IP addresses

Successful test of a regular expression with multiple IP addresses

Failed test of a regular expression with multiple IP addresses

Failed test of a regular expression with multiple IP addresses

How to Test an IP Filter?

To test your IP filter, you can use the browser extension "Google Tag Assistant" for Chrome. The extension can record a flow on your website that sends hits to your property on Google Analytics, and it has a report that can show the effects of your filters.

If you want more details, you can find a description on support.google.com under the headline Make sure the filter works.

Below you can see the 5 steps I made in my test:

1. Run Tag Assistant on your site, stop and click Show Full Report.

Run Tag Assistant on your site, stop and click Show Full Report

2. Go to Google Analytics Report.

Go to Google Analytics Report

3. Change location in the report.

Change location in the report

4. Set an IP or your location and update.

Set an IP or your location and update

5. Go to Page hits and See if the hit was dropped by the filter.

Go to Page hits and See if the hit was dropped by the filter
Powered by
TRIMIT Portal Software