Segments in Piwik PRO are a great way to temporarily exclude internal traffic from reports and dashboards, based on IP address. Here's how to do it.
One of the most common analytics questions I hear is: how do I stop internal traffic from showing up in my reports? The solution often involves filtering out or excluding traffic based on IP address, and Piwik PRO offers a couple of ways to do this.
The first is to use the 'Filter' function, which stops data from specified IP addresses being collected at all. But this has two main limitations: first, it's a permanent change (any data not collected is lost forever), and second, it doesn't apply to historic data. In other words, you need to set the filter up before you collect your data - which requires a bit of forward planning!
If you only want to exclude internal traffic temporarily, or if you're working with historic data, another option - and the one I go through in this post - is to use a segment. Segments in Piwik PRO work very much like segments in the old version of Google Analytics, Universal Analytics, if you're familiar with those. However there's one caveat that makes setting a segment to exclude internal traffic trickier than it should be.
But before we get into the process of setting up your Segment, make sure you have the list of IP addresses you want to exclude from your reports. You can get your IP address by going to a site such as https://whatismyipaddress.com/ - if you send this link to your colleagues, they should then be able to provide you with their IP address. The site will list an IPv4 address or an IPv6 address: Piwik PRO can work with either of these.
I don't actually live in Sheffield - it's an example
I'm not going to get into the pros and cons of excluding internal traffic based on IP address rather than other approaches, but just bear in mind that it isn't foolproof. You may find you have a dynamic IP address that changes whenever you reset your router. This means that you could spend more time managing and updating your segment than doing anything else! Also, an IP address filter or segment won't help with excluding traffic from mobile devices.
By default, reports, custom reports and dashboards in Piwik PRO have the 'All visitors' segment selected - you'll see this listed at the top.
To create our new segment:
Segments consist of different conditions - any user that meets those conditions will be part of the segment. And the conditions are built up using dimensions - these are the green things listed on the right of the 'Manage segments' page:
If you type 'IP' into the search box above this list of dimensions, the list will be filtered to only these two:
These are the dimensions we'll be using for our segment.
Let's go ahead and add our first condition. Drag the relevant dimension (in my case 'IPv4 address') into the box that says 'Drop a dimension from the list on the right to create a new condition'.
Once you've done that, the condition will say something like:
IPv4 address equals e.g., 192.168.0.1
Paste your IP address into the value field (the bit that says 'e.g'). Piwik PRO will then calculate the number of visitors included in this segment (based on traffic in the last 30 days). In my case, the segment includes one visitor, or 0.2% of my total:
It would be great if Piwik PRO let you exclude segments from reports. If that was the case, we could just add a condition for each internal IP address and be done with it. But segments define the visitors we want to report on, not the ones we don't want to report on. So in our condition, we need to click on 'equals' and change it to 'not equals':
Here's where something strange happens. As my 'equals' condition accounted for 0.2% of visitors, I would expect my 'not equals' condition to account for 99.8% of visitors. Instead it gives me a figure of around 64%:
The reason for this is that some visitors don't have an identified IP address at all, and these are included in neither the 'IP address equals' or the 'IP address not equals' condition! Instead we have to add a second condition to account for these visitors.
Drag another IP address dimension into the 'OR' box and set it to 'is empty'. Now your segment will include all visitors except for those matching the IP address you specified. In my case, the segment includes 99.8% of recent site visitors:
Now you can continue adding internal IP addresses to your segment. IMPORTANT: Each new IP address will need both an 'IP address now equals' condition and an 'IP address is empty' condition, following this pattern:
IP address not equals VALUE 1
OR
IP address is emptyAND
IP address not equals VALUE 2
OR
IP address is emptyAND
Keep an eye on the visitors calculation as you go to make sure you haven't gone wrong.
Here's (part of) my working example:
Once you've finished adding all your IP addresses, click on the blue 'Create a segment' button at the bottom (you won't be able to do this unless you've first given your segment a name).
Now, in any report or dashboard, click the '+' button at the top (alongside 'All visitors') to access your list of segments. Select your new segment to apply it to that report or dashboard.
Each widget will now show two values, one for 'All visitors' and one for your segment that excludes internal IPs. You can now (temporarily) remove the 'All visitors' segment if you like, by clicking the 'x' button alongside it. This will leave you only looking at traffic with internal IPs excluded: