It’s not unusual that you might want to block from your Google Analytics statistics visits from particular locations.
Let’s say you have multiple offices and multiple staff. If staff have their browsers set to always load your website upon startup, then your website traffic statistics may be skewed toward those visits. It’s often the case that website owners are more interested in traffic from external rather than internal sources. While there are certainly ways in Analytics to review different types of traffic, you may want to block all this internal traffic from your data.
The process can be more complicated if you have a range of IP addresses to block, which is not uncommon for a larger organization. If you are a single person, you can determine your IP address by going to a website such as whatismyip.com. If you run a larger outfit, IP addresses are likely to be managed by your IT department.
A range of IP addresses may be expressed in CIDR (Classless Inter-Domain Routing) format. A CIDR address may look something like this: 18.104.22.168/28 (number picked at random; this is likely somebody’s IP address – we’ve not attempted to determine whose it is). The smaller the number after the slash, the greater the number of individual IP addresses.
To determine the actual IP addresses expressed by a CIDR range, you can use an online tool, such as the one found here: http://www.ipaddressguide.com/cidr. Enter in the CIDR numbers and it will give you the range of IP addresses. Were you to type in the CIDR address above, the tool indicates that that the first IP address in the range is 22.214.171.124 and the last is 126.96.36.199.
Next, we would need to create for Analytics what is known as a regular expression or regex. God bless the Internet. Once you have an IP range, you can go to an online tool to create the appropriate regex for Analytics. Here’s a place to do that: http://www.analyticsmarket.com/freetools/ipregex. Using that tool with the above IP range, we get a regex that looks like this: ^65\.32\.250\.([0-9]|1[0-5])$. If the IP address were the singular 188.8.131.52, the regex would be ^65\.32\.250\.0$. Look closely and you’ll see an identifiable pattern. Meaning, you can create these regexes manually, but do you really want to?
Next, we need to use that regex in Analytics to filter traffic from that IP range.
Before you go changing your Analytics data, you should be aware that you can set up multiple views (25 as of this writing) of your data in Analytics. It’s advisable to maintain one view that captures all traffic, that is, that does not filter any traffic out. Just the raw data.
How do we create a new view with a new filter? It’s fairly straight forward, and here are the steps on:
How to Create a Google Analytics View with a Filter Blocking an IP Range
- Go the “Admin” tab in Analytics (as distinguished from Home, Reporting or Customization)
- Go the “View” tab (as disintinguished from Account or Property)
- Create a new view with a new name. (Image 1 below)
- Set the name and time zone (Image 2)
- Go to view Filters (Image 3)
- Create a new filter, give the filter a name, like “Block IPs” (Image 4)
- Select filter type “predefined”, exclude (Image 5)
- Under “select source or destination”, choose “traffic from the IP addresses” (Image 5)
- In the next box, choose “that contain” (Image 5)
- Enter the IP range in the box below (Image 5, using the sample data from above)
- Click on the “Save” button
And that’s it. Note that it can take a day or so for the filter to produce results.
Note, too, that if you link Analytics with your Adwords account, you will be choosing which Analytics view to link. If you set particular goals in Analytics (a post for another day) and use those goals in Adwords (another post for another day), you will want to think strategically about what traffic is appearing in which Analytics view.