Sub topic 13
Excluding internal traffic
Your own team's visits can distort GA4 reports. Developers reload pages, editors preview drafts, and QA staff run test purchases. On a site with modest traffic, these visits can noticeably inflate sessions and conversion counts. This chapter covers how to tag that traffic, how to filter it out safely, and where the approach falls short.
This chapter assumes you have a working web data stream with the tag installed and you can open Admin for the property. You need the Editor role on the property to create the rule and filter.
How exclusion works in GA4
Excluding internal traffic takes two separate steps. Neither works alone.
- Define internal traffic. A rule on the data stream compares each hit's IP address against the addresses you list. When an address matches, GA4 adds a parameter named
traffic_typeto the event, with the value you chose (by defaultinternal). - Create a data filter. A property-level filter looks for events whose
traffic_typeequals that value. It then either marks them for testing or drops them.
A rule without a filter only labels the traffic. A filter without a rule matches nothing, because no event carries the parameter.
Step 1: Define the internal traffic rule
- Go to Admin, then Data collection and modification, then Data streams.
- Select your web stream.
- Under Google tag, choose Configure tag settings.
- Click Show all, then Define internal traffic.
- Click Create.
The rule form has three fields:
| Field | What to enter |
|---|---|
| Rule name | A label for people, such as `Office network` |
| traffic_type value | The value written to the parameter. The default is `internal`. |
| IP address | A match type and one or more addresses |
The match types include IP address equals, begins with, ends with, contains, IP address range (CIDR notation), and regular-expression options. Use these as a rule of thumb:
- Use equals for a single static address, such as your office's public IP.
- Use CIDR range for a block of addresses, such as
203.0.113.0/28. - Use regular expressions only when you can't express the set any other way. A mistake in a pattern can match far more addresses than you intended.
Use the public IP address your visits come from. The private address of your laptop (such as 192.168.1.20) is not what GA4 sees. Searching "what is my IP" from the office network shows the public address.
You can add several rules. If you need different labels, give each rule its own traffic_type value, for example office and vpn. A filter matches one value, so with different labels you need a filter for each.
Step 2: Create and activate the data filter
- Go to Admin, then Data collection and modification, then Data filters.
- GA4 normally lists an Internal Traffic filter already, in the Testing state. If it's missing, click Create filter, then choose Internal Traffic.
- Check that the Parameter value matches the
traffic_typevalue from your rule (internalby default). - Set the filter operation to Exclude and save.
A filter has three states:
| State | Effect on data | Reversible? |
|---|---|---|
| Testing | Matching events stay in reports and carry the filter's name in a dimension called **Test data filter name** | Yes |
| Active | Matching events are dropped before they're stored | No, for data already dropped |
| Inactive | The filter does nothing | Yes |
Test before you activate
Leave the filter in Testing first. In an Exploration, add the Test data filter name dimension and compare events with that value against the rest. If you see your own visits there and no real customers, the rule is correct. Then change the filter state to Active.
Filter changes also take time to apply. Allow up to about a day before judging whether the filter works, and don't assume that a Realtime report will show the effect immediately.
Tagging traffic from the page instead of by IP
IP rules work poorly in some situations:
- Staff work from home on changing residential addresses.
- Visitors use a VPN that shares an address with real customers.
- The team's network uses IPv6 addresses that are hard to list.
In those cases you can set traffic_type yourself in the tag. The filter doesn't care how the parameter got onto the event. It only checks the value.
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
// A staff member sets this cookie once, for example from a bookmarklet
// or an internal login page: document.cookie = 'internal_user=1; max-age=31536000; path=/';
var isInternal = document.cookie.split('; ').indexOf('internal_user=1') !== -1;
if (isInternal) {
gtag('config', 'G-XXXXXXXXXX', { 'traffic_type': 'internal' });
} else {
gtag('config', 'G-XXXXXXXXXX');
}
</script>The cookie follows the browser, not the network. It still works from home, on a VPN, or on a phone, but it has to be set again after cookies are cleared or on a new device. The same idea works in Google Tag Manager: add traffic_type as a field to set in the Google tag, and use a variable (such as a cookie variable) to supply the value.
You can combine both methods. The IP rule covers the office without any effort from staff, and the cookie covers everyone else.
Related options and what they do not cover
- Developer traffic filter. GA4 also provides a separate filter for events sent with
debug_modeenabled. It's useful when you test with DebugView, as covered earlier. It is independent of the internal traffic rule. - Opt-out browser add-on. Google's Analytics opt-out add-on stops a person's browser from sending data to Google Analytics. It's suitable for individuals but impractical to manage across a team.
- Server-sent events. Hits sent from your own server, for example through the Measurement Protocol, carry the server's IP address, not the user's. An office-IP rule won't catch them. Set
traffic_typeexplicitly if you need to separate them. - Separate test properties. For staging sites, use a different data stream or property instead of filters. This keeps test events out of production data from the start (see the later chapter on structuring multiple sites).
Common errors
- The filter never matches anything. The
traffic_typevalue in the rule and the Parameter value in the filter differ, for exampleinternalandInternal. Compare them character for character. - Wrong IP. You entered a private address, or your office has several public addresses and you listed one. Check your public address from each network.
- The filter is still in Testing. In this state nothing is excluded. This is the most common reason internal visits stay in reports weeks after setup.
- Past data still contains internal visits. Filters are not retroactive. To remove them from analysis of old data, use a segment or comparison that excludes the matching traffic.
- Testing through the rule in Realtime. Realtime may still show your visit while the filter is in Testing. Use the Exploration dimension to confirm instead.
Checklist
- Create an internal traffic rule with your office's public IP or CIDR range.
- Confirm the
traffic_typevalue matches the filter's parameter value. - Leave the filter in Testing and check the Test data filter name dimension in an Exploration.
- Add a cookie or tag-level
traffic_typefor remote staff. - Switch the filter to Active only after the test results look right.
Exercise
Your filter is Active and the rule uses the IP range 198.51.100.0/24, but a colleague working from home still appears in your reports. Name two likely reasons and one fix.
Show answer
The colleague's home IP address is outside the listed range, so the rule never added traffictype. Alternatively, the rule's traffictype value doesn't exactly match the filter's parameter value. A fix is to set traffic_type to internal from the page, for example with a cookie checked in the tag's config call. Use the same value the filter expects, and the filter then excludes that colleague's events whatever their IP address.
Exercise
Why should a new internal traffic filter stay in the Testing state first, and how do you check its results?
Show answer
An Active filter permanently drops matching events and can't restore them, so a rule that is too broad destroys real data. In Testing, matching events stay in the reports and carry the filter name in the Test data filter name dimension. You add that dimension in an Exploration and check that only internal visits appear under it.