Filtering multiple IPs in Google Analytics

Filtering an IP in Google Analytics is pretty simple (see post). But in many cases, a company will have multiple IPs to exclude, e.g. multiple office locations.

In this post I’ll cover several ways to implement such filters.

Multiple filters

One way of applying such filters is by adding a single filter for each IP. Following the instructions on my previous post, you can easily set up an IP filter and add as many as you like for each office location.

Applying multiple filters to exclude multiple locations

Pro tip:
Google Analytics filters apply in the order in which they are set, so the final input will have passed through all filter.

Combined filters

Another option, when wanting to exclude multiple IP addresses in one shot, is creating one filter that captures multiple addresses.

To achieve that, you need to create a filter of the type ‘Custom’. Select Exclude and use the Filter Field ‘IP Address’.

The Filter Pattern uses regular expression matching, so you can input multiple IP addresses separated by a pipeline | to exclude multiple IPs using one filter.

e.g. 123.123.123.123|134.134.134.134

Excluding multiple IPs with a single filter

C-Class filter

Following the solution above, in some cases the offices might use a range of IP addresses and not only one single address. This is very common for larger offices and campuses.

In this case, you can use the regular expression matching to exclude an entire range of IPs.

The most common case is excluding an IP C-Class. This is the entire range of IPs indicated by the final digits in the IP address. For example, 234 in the address below.

123.123.123.234

To exclude the entire range, we can create a filter to match 123.123.123.*

Filtering out an IP C-Class range

This will exclude all traffic that matches this pattern, e.g. 123.123.123.222

Pro tip:
This is a simplified version of the regular expression syntax that could include edge cases. The “full” syntax should actually be 123\.123\.123\..*

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts