How to create segments to include or exclude staff traffic based on complex IP address ranges?
A simple and scalable approach to segmenting internal and external traffic in Matomo is to detect staff users server-side and tag them with a custom dimension. While it is possible to exclude internal traffic using global IP filters, this is less practical to maintain and does not give you the ability to report on staff traffic.
This guide explains how to create segments to include or exclude staff from your reports using a Custom Dimension.
Before you start
In your CMS or web application, add server-side logic to detect when a visitor is a staff member. This could be based on IP address, authentication status, user role, or specific request headers. The detection must happen before the page is sent to the browser and before the Matomo tracking code loads.
Create a Custom Visit Dimension
- Navigate to Matomo settings (Administration)
> Measurables > Custom Dimensions.
- In Visit Dimensions, click Configure A New Dimension.
- Provide an identifiable Name (e.g., Staff user) and select the Active checkbox to enable the new dimension.
- Click Create to save.
Add the Custom Dimension to Matomo tracking
In this step, add the Custom Dimension to either the JavaScript tracking code or Matomo Tag Manager to record whether the visitor is a staff user at the time the page loads.
Matomo JavaScript tracking code
- If you are using the JavaScript tracking code, add the following line before
trackPageView
, so when a staff member is detected, it will be recorded in the custom dimension:_paq.push(['setCustomDimension', ID_DIMENSION_HERE, 'Staff user']);
- Note: Replace ID_DIMENSION_HERE with the numeric ID of your custom dimension.
<!-- Matomo -->
<script>
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['setCustomDimension', ID_DIMENSION_HERE, 'Staff user']);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
You do not need to explicitly configure anything for non-staff visitors. No value is recorded for regular visitors as they are automatically excluded from this dimension.
Matomo Tag Manager
If you are using Tag Manager, you can modify the Matomo Configuration Variable to include the custom dimension.
- Go to Tag Manager > Variables and open the Matomo Configuration Variable linked to your Matomo tracking tag.
- Scroll down to the Custom Dimensions section and enter the Index (Custom Dimension Id) and Value (name of the dimension e.g.,
Staff user
).
- Click Update to save and then publish the change to your live environment.
Create a Segment for Staff traffic
- From your Matomo dashboard, open the segment selector and click Add New Segment.
- Provide an identifiable name for the segment such as Staff member with the following condition using the new custom dimension:
Staff user
Isstaff
. - Click Save & Apply.
When this segment is selected, it will filter your reports to show only your staff members.
Create a Segment for non-Staff traffic
- From your Matomo dashboard, open the segment selector and click Add New Segment.
- Provide an identifiable name for the segment such as Visitors (not staff) with the following condition using the new custom dimension:
Staff user
Is notstaff
. - Click Save & Apply.
When this segment is selected, it will exclude staff members and only report on public visitors.
This setup is especially useful if you want to analyse staff interaction with your site separately, or if you need to exclude internal users from conversion metrics, Heatmaps, or other visitor-based reports.