Sub topic 5
Creating the internal traffic data filter
This chapter assumes you already have a GA4 property with a web data stream, Editor or Administrator access, and an internal traffic rule that sets traffic_type to a value such as internal. You should also know what an event parameter is and how sessions relate to events. The rule only labels traffic. The data filter is the property setting that acts on that label.
What the data filter does
An internal traffic rule lives in the data stream's tag settings. When a hit arrives from a matching IP address, Google's collection servers add traffic_type=internal to the event. At that point the event is only labeled, and it still counts in your reports.
A data filter lives at the property level, under Admin > Data collection and modification > Data filters. It reads that label and decides what to do with the event. Without a filter, the label has no effect on your reports.
The division of work looks like this:
| Layer | Where you configure it | What it does |
|---|---|---|
| Internal traffic rule | Data stream > Configure tag settings > Define internal traffic | Matches IP addresses and sets `traffic_type` |
| Data filter | Admin > Data filters | Includes or excludes events by the `traffic_type` value |
| Report | Reports, Explorations, BigQuery export | Shows only what the filter let through |
Check what already exists
GA4 creates a filter named Internal Traffic automatically for every property. Its default state is Testing, and it looks for the traffic_type value internal. Before you create anything, open the Data filters page and look at the list. Many properties already have this filter, and a second one with the same condition does nothing useful.
The same page also shows a Developer traffic filter, which excludes events sent with debug_mode. It is covered in a later chapter. Leave it alone for now.
If the existing Internal Traffic filter uses a value other than the one in your rule, you have two options:
- Change the rule's value to
internal. - Create a new filter that uses your custom value.
The first option is simpler. Use the second when several rules emit different values, for example office and agency, and you want to handle them separately.
Create the filter
You can only create filters at the property level, and you need the Editor role or higher.
- Open Admin and choose the property.
- Under Data collection and modification, choose Data filters.
- Choose Create filter, then Internal traffic.
- Enter a Data filter name, such as
Office network. - Enter the traffic_type value that your internal traffic rule sets. For the rule used in this tutorial, that is
internal. - Choose a Filter operation: Exclude or Include.
- Choose a Filter state: Testing, Active, or Inactive.
- Choose Create.
The traffic_type value must match the rule exactly. Matching is case-sensitive, so Internal and internal are different values. A mismatch is the most common reason a filter seems to do nothing.
Exclude or include
Exclude drops every event whose traffic_type equals the filter's value. Use this for the usual case of removing office traffic.
Include keeps only events whose traffic_type equals the filter's value and drops everything else. This is a specialized tool. If you set it to internal by mistake, you keep only your own visits and discard all of your customers' data, and GA4 cannot recover it. Do not choose Include unless you want a property that contains only labeled traffic, such as a separate test property.
Make sure the rule and filter agree
The rule and filter are two settings that must use the same value. This table shows how each combination behaves.
| Rule sets `traffic_type` | Filter value | Result |
|---|---|---|
| `internal` | `internal` | Matching events are filtered. |
| `office` | `internal` | The filter never matches. Internal traffic stays in reports. |
| `Internal` | `internal` | The filter never matches because of case. |
| Not set (rule missing) | `internal` | The filter never matches. |
You can also set the value in the page's tag code. This approach works without an IP rule, and it is the method to use when you cannot identify fixed addresses.
gtag('config', 'G-XXXXXXXXXX', {
'traffic_type': 'internal'
});Every event from a page load with this configuration carries the label, and a filter with the value internal can then exclude it. Your code should set this only for the visits you want to exclude, for example behind a login check or a cookie that your team sets. Setting it for every visitor would exclude all of your traffic once the filter is active.
What a filter changes and what it does not
Keep these points in mind when you decide to activate a filter.
- It is not retroactive. A filter only affects events that GA4 collects after it becomes active. Events already stored stay in your reports.
- It is permanent for new data. When a filter is Active, GA4 drops matching events at processing time. You cannot restore them later by switching the filter off. Switching it off only lets later events through.
- It applies to the whole property. Every report and every export sees the same filtered data. A filter cannot be applied to one report only.
- It works on events, not users. If a person visits from home and from the office, only the office events are removed.
- It needs the label to be present. Events that never reach the rule, such as Measurement Protocol hits sent without the parameter, are not filtered.
Because of the permanent effect, GA4 gives you the Testing state. The next chapter covers states in detail. For this chapter, the workflow is short.
A safe creation workflow
Follow this sequence for every new filter.
- Check that the internal traffic rule exists and that its value matches the filter's value.
- Create the filter in Testing state.
- Generate traffic from a matching address. Open the site from the office network and click through a few pages.
- Open Admin > DebugView, or Explore with the Test data filter name dimension, and confirm that your events show the filter name.
- Open a normal browser session from a non-matching connection, such as a mobile network, and confirm those events do not show the filter name.
- Wait for the data to appear in reports. This can take up to 24 hours for standard reports.
- Change the state to Active only when both checks pass.
The Test data filter name dimension is available in Explorations and in the BigQuery export. It holds the name of the filter that would have excluded an event. A blank value means that no testing filter matched.
Match ranges before you create the filter
The rule decides what the filter ever sees, so you should confirm its IP match first. For an office with a block of addresses, a CIDR range is the simplest choice.
IP address is in range (CIDR notation): 203.0.113.0/24This matches every address from 203.0.113.0 to 203.0.113.255. If you need a more flexible pattern, a regular expression can express ranges that no other match type handles.
^203\.0\.113\.([1-9]|[1-9][0-9]|1[0-9]{2})$The dots are escaped so they match only literal dots. Regular expressions are anchored with ^ and $ here to stop partial matches. This one matches 203.0.113.1 through 203.0.113.199, which leaves out .0 and .200 to .255. If you meant to cover the full block, use the CIDR form instead.
Common problems
The filter is Active, but internal visits still appear. Check these in order:
- The rule's value and the filter's value differ, including by case.
- The rule's IP match is wrong. Your public address may not be the one you assumed. Search for "what is my IP" from the office network and compare the result.
- You are using a VPN or mobile hotspot, so your traffic comes from a different address.
- The data is from before activation. Filters are not retroactive.
- Several data streams exist. The rule is defined per web data stream, so a second stream needs its own rule.
The filter excluded too much. Look for an Include operation, a rule that matches a shared address such as a coworking space or a large ISP range, or tag code that sets traffic_type for all visitors.
Test data filter name is blank for every event. Your events are not receiving the label. Open DebugView and check the event's traffic_type parameter. If it is missing, return to the rule and confirm that it is saved on the correct data stream.
Maintain the filter
A filter needs occasional review, because the addresses behind it change.
- Review the IP list whenever your office changes provider or moves.
- Give filters descriptive names. The name appears in the Test data filter name dimension, so
Office networkis easier to read thanFilter 1. - Record the creation date and who approved the Active change. A dropped event cannot be audited afterwards.
- Keep a second property with no filters if you need a complete record. Teams often do this with a raw "unfiltered" property that receives the same stream data.
Exercise
Your internal traffic rule sets traffic_type to office. The property still has the default Internal Traffic filter in Testing state with the value internal. You switch it to Active and check reports a day later. Office visits still appear. Why, and what are two ways to fix it?
Show answer
The filter never matches because its value (internal) differs from the value the rule sets (office), so no event is dropped. Fix it either by changing the rule's traffic_type value to internal, or by editing or creating a filter whose value is office. After fixing, remember that the already collected events stay in reports, and only new events are filtered.
Exercise
A colleague creates an Internal traffic filter with the value internal, sets the operation to Include, and sets the state to Active. What happens to the property's data, and can it be undone?
Show answer
Only events labeled internal are kept. All other events, including all customer traffic, are discarded as they arrive. Switching the filter back to Exclude or Inactive stops further loss, but the events already dropped cannot be recovered.
Exercise
You want to confirm a filter before activation. Which state do you use, and which dimension shows whether it matched an event?
Show answer
Use the Testing state. The Test data filter name dimension, available in Explorations, shows the name of the filter that matched an event. In Testing state the event is still kept in reports.