How to Filter IP and IPv6 Addresses from Google Analytics

How to Filter IP and IPv6 Addresses from Google Analytics

How to Filter IP and IPv6 Addresses from Google Analytics

If you aren’t filtering out your company and vendor IP addresses from your website Google Analytics, you should be, especially for large companies. I previously worked for a company that was a large eCommerce business whose sales team used the site as a major resource for training and selling. With that much internal traffic going through the site, it made it almost impossible to get clear data on how customers were navigating the site.

Once we could filter out internal traffic in a new view, we could deliver better reporting on how customers used the website during their shopping experience. Better yet, we could create another view that just showed us internal traffic and how the sales team used the website; this was important, because the marketing team could then tell what content was working to help the sales team too.

What is an IP and IPv6 Address?

An IP address (Internet Protocol address) is what identifies your computer. It’s essentially the driver’s license number of your computer and follows you everywhere you go on the web. If you are on this website now, Google Analytics can see you IP address and then report if you’ve been to this website before, where you visit while you’re here, and how long you’ve been here. I know, it sounds creepy, but it’s been happening since you got online back in the AOL days. It’s how Google Analytics works; it’s how the Internet works. Yes, you can block your IP address using an anonymous proxy server, but that would change how you surf the web and how you view certain websites. For more on IP addresses and proxy    servers, check out this article over on How Stuff Works – Tech.

IP addresses are an IPv4 address that usually look something like this, 182.152.0.205. IPv6 is the new schema for IP addresses and usually look like this, 2521:292:c121:8a5::348e. IPv6 stands for Internet Protocol Version 6 address. IPv4 is 32-bit in size, whereas IPv6 is 128 bits in size; meaning, IPv6 has more space to support our growing population. With the demand of more IP addresses for smartphones, tablets, laptops, and desktops, IPv6 is the solution to keep up with the population of more than 7 billion people worldwide. 95% of IP addresses today are IPv4, but this will need to change to keep supporting new devices. If you want to geek out on IPv6, this Wikipedia article is great.

Blocking IP Addresses from Google Analytics

When it comes to blocking IP addresses from Google Analytics, it’s easy and quick to get done if you only have a few IP addresses to remove. Head over to Google Analytics and login to your account.

  1. Click on your profile and you should be brought to your main dashboard. From the top navigation, you should see Home, Reporting, Customizations, and Admin. Click on Admin.
  2. If you already have a view created to add different filters and goals, skip to step 5. If not, keep reading. You’ll now see three columns: Account, Property, and View. Under View, click on View Settings.
  3. When the View opens, click on the Copy view
  4. Name the new View something you’ll remember. I usually name mine Filters & Goals. Click on Copy view You should be brought back to the page with the 3 columns. We create a new view to add our filters, goals, and any other modifications so that we always have a clean version (the original View). If you end up creating the wrong filter or excluding something that should be excluded, you’ll at least have the original View to fall back on.
  5. Under View, click on Filters.
  6. Click + Add Filter.
  7. Give the filter a name like, Block [Name] IP Address. Under the Select filter type drop down, choose Exclude. For Select source or destination, choose traffic from the IP addresses. For Select expression, choose that are equal to. In the IP address box, paste the IP address you want to exclude – you can only paste one IP address. If you need to find your IP address, simply Google ‘what is my IP address.’ Your IP address should appear at the top. Click Save and you’re done! This works for IPv6 too.
  8. If you want to block multiple IP addresses, you can do step 6-7 multiple times, OR learn how to do reg-ex (see below).

Filtering out Multiple IP Addresses from Google Analytics

How to Filter IP and IPv6 Addresses from Google Analytics

If you have multiple IP addresses that need to be excluded, it’s much easier to use a regular expression (reg-ex) under one filter. To do this, follow up to step 6 above and then follow the steps below.

  1. Give the filter a name like, Block IP Addresses. Switch the Filter Type to Custom. The first radio button should already be checked for you, but if it is not, make sure to check Exclude. For the Filter Field dropdown, search for IP Address. In the Filter Pattern, you’ll copy and paste your IP addresses, but first you need to make sure that before each period is a \ and between each address is a |. Let’s do this in excel (if you’d rather do it by hand, skip to step 10).
  2. Go to excel, and copy and paste all your IP addresses, for ease of use in this tutorial, paste starting in A1. Click CTRL + F. In the Find what: box, type a period. In the Replace with: box, type \.. Click the Replace All All your IP addresses should now have the \ before the period. Close out the boxes that tell you the number of instances the replacement was made and the Find and Replace box. You should just see your IP addresses in excel now.Excel Find and Replace
  3. To get the | at the end of each of the IP addresses, we’re going to put a | in the cell next to each of the IP addresses (starting in B1), except not for the last one. In reg-ex, the | is never at the end.
  4. Starting in cell C1, put in this formula: =CONCATENATE(A1,B1). Click enter. You should now see your IP address with the | at the end – no spaces (another rule with reg-ex, no spaces are involved or it won’t work).
  5. Now we want to combine all our IP addresses into one cell so we can copy and paste over in Google Analytics. To get this done, we need to transpose and concatenate (if you’re a visual person, make sure to check out this video to see it easily done). Click in D1, type in =TRANSPOSE(A2:A75). You can quickly select the range of cells by clicking in A2, and then clicking CTRL+SHIFT+↓. Do not click enter.
  6. Before clicking enter, click the F9 button.
  7. At the beginning of the formula, delete TRANSPOSE{ and replace it with CONCATENATE(. Go to the end of the formula, and replace the } with ). Your formula should look like this now: =CONCATENATE(“A2″,”A3″,”A4″,”A5″,”A6″,”A7”, …).
  8. Click enter.
  9. Now you have a formula, but to take this and copy and paste over in Google Analytics, you need the values. Simply copy the formula, right-click in another cell, and paste with Values only (the clipboard with the 123 numbers).
  10. Yay, now you have your reg-ex and you’re ready to go copy and paste it back in the Filter Pattern Click the Save button and you’re done!

Filtering out Multiple IPv6 Addresses from Google Analytics

To filter our IPv6 addresses, you don’t need to add the \ after anything. You simply copy and paste the address and separate them with |. So, if I had a string of IPv6 and IPv4 addresses, my reg-ex would look something like this:

2601:252:c124:8a1::182e|51\.209\.145\.16|124\.11\.182\.129|85\.176\.123\.183|3501:212:c121:9a6::485e

  • No | at the end and no spaces.
  • If you need to filter out a lot of spaces, use Find and Replace in excel to replace the space with none.

Testing your Google Analytics Filters

To see your filter working, go back over to Reporting from the top navigation and click on Real-Time > Overview. Go and visit your website. If you see an active user pop-up when you arrive at the site, something is not working right with your filter. If you don’t see a number pop-up, success!

About Kasy Allen

Kasy brings years of experience in search engine optimization (SEO), content strategy, Internet marketing, and overall web-geekery to the table. She enjoys writing on the web and improving user experience across the Annapurna site, as well as with our clients. When Kasy is out of the office, she can often be found volunteering her time to help non-profit organizations build a better online presence and exploring the great outdoors with her family.

2 Comments

  • Mic Sumner says:

    Hi Kasy,

    Thank you for the nice post. I’ve saved this in my notes now. You are right that I would rather use an excel spreadsheet or an alternative solution through multiple cursors in a text editor like Atom or Sublime Text 3, as you outlined here in the article should I have to filter out many IP addresses to bring them into one line to place in the field.
    But I’ve built a quick web tool you might want to check out https://www.ipaddressregex.com/ that does the escaping for your own IP Address. IPv6 address supported! No need to type in the backslash carefully \.
    So that all you’ll have to do is use the pipe character | to append to the previous IP addresses. That way you can quickly get on the Analytics boat and collaborate with others. If there’s any comments about this please feel free to discuss since I am just newly qualified through the GA IQ!

    Kind regards,

    Mic Sumner

  • Kasy Allen says:

    Awesome, thanks for making life easier!

Leave a Reply

Ready to discuss your project? Request a Quote