An essential part of using Google Analytics is to filter out traffic that skews your data. There are several types of traffic you may want to filter. The most obvious one is your own. This includes from your home, your office, and anywhere else you hit your site. It may also include your co-workers, unless one of your target audiences is your co-workers.
Filtering a single IP address is easy and takes just a matter of minutes to set up, if that. However filtering a range of IP addresses may be a bit more challenging, but is definitely doable.
1. To begin, log in to Google Analytics at https://www.google.com/analytics/settings/home
2. Click Admin at the top right of the page.
3. Select the account for which you want to create the filter.
4. Click the Filters tab.
5. Click + New Filter.
6. Enter a name for the filter. If you’re adding several filters that relate to each other, such as your home IP address and work IP address, get the filters a name that distinguishes them.
7. Select Predefined filter to select from the predefined filter types. From there your filter can exclude or include only certain traffic based on ISP, IP, requested subdirectories, or requested hostname. If you’d like to make a more advanced filter, such as to filter a range of IP addresses, skip this step.
8. To make an advanced filter, such as to filter an IP address range, select Custom filter.
9. Select Visitor IP Address in Filter Field.
10. In Filter Pattern enter the IP address as a regular expression. Regular expressions are special characters that match the data and perform an action when a match is achieved.
- If the single IP address is 220.127.116.11, then enter 18.104.22.168
- If the range of IP addresses is from 22.214.171.124 to 126.96.36.199. Enter 3.12.71.[1-9]
- Here’s an even more complex example. You may need to brush up on your regular expression skills to accomplish this. If the IP addresses range is 188.8.131.52-25 and 10.0.0.1-14, then enter ^176.168.1.([1-9]|1[0-9]|2[0-5])$|^10.0.0.([1-9]|1[0-4])$
11. From the Available profiles list, select the profiles to which you want to apply the filter, then click Add, and lastly Save changes.
Congratulations! You’re now filter an IP address range. One way to test your filter is to browse to a private page that no one else would have access to, and see if any traffic to that page gets recorded in your Google Analytics account.