Sub topic 2
How GA4 marks traffic with traffic_type
This chapter covers the traffic_type event parameter. GA4 uses it to label events that should be treated as internal, and a data filter later reads that label. It assumes you have a GA4 property with a web data stream, Editor or Administrator access, and a working idea of events, parameters, and sessions. You will not create the filter here. That comes in a later chapter. This chapter explains the label the filter depends on.
Why a label is needed
GA4 does not exclude your own visits by looking at the visitor. It works in two separate steps:
- Something marks each event, or leaves it unmarked.
- A data filter at property level looks at that mark and decides whether to keep the event.
The mark is an event parameter called traffic_type. An event parameter is a named value that travels with an event, like page_location or engagement_time_msec. A data filter that excludes internal traffic does not know about IP addresses. It only checks whether traffic_type equals a value you chose, such as internal.
This split gives you flexibility. Any method that can put the right traffic_type value on an event can feed the same filter. The methods are IP rules in the tag settings, a manual parameter in your code, or a value set through Google Tag Manager.
The two ways `traffic_type` gets set
Automatically, from an internal traffic rule
In the web data stream's tag settings, you can define internal traffic rules. Each rule has three parts:
| Field | Meaning |
|---|---|
| Rule name | A label for you, such as "Head office". It is not sent with events. |
| `traffic_type` value | The text added to matching events. The default is `internal`. |
| IP address condition | A match type and an address, such as an address range in CIDR notation. |
GA4 compares the IP address of each incoming hit with your rules. When a hit matches, GA4 adds traffic_type with the rule's value to the events from that hit. You do not change any code on your site.
Manually, from your own code
You can also set the parameter yourself. This is useful when the IP address is not a good signal, for example for a staff member on a home connection who uses a special build of the site.
gtag('config', 'G-XXXXXXXXXX', {
'traffic_type': 'internal'
});Every event sent after this call carries traffic_type set to internal. An internal traffic data filter with the same value then excludes those events, in the same way as events marked by an IP rule.
A complete page snippet looks like this:
<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());
// Decide whether this visitor is internal before configuring the tag.
var isStaff = document.cookie.indexOf('staff=1') !== -1;
gtag('config', 'G-XXXXXXXXXX', isStaff ? { 'traffic_type': 'internal' } : {});
</script>The staff cookie in this example is a placeholder. Use whatever signal your site can read reliably. The point is that the decision is made before the config call, because events sent earlier are not tagged afterwards.
What the data flow looks like
The diagram shows that the data filter is a separate step from tagging. Tagging alone excludes nothing. If you define a rule but never create a filter, the events carry a traffic_type value and still appear in your reports.
Matching rules between the label and the filter
The filter and the label must agree on the value. A few points are worth knowing:
- The match is on the text of the value. A rule that sets
internaland a filter that looks forInternalorinternal(with a trailing space) are different values as far as you should assume. Copy the value rather than retyping it, and keep it lowercase and without spaces. - You can use more than one value. For example, a rule for the head office could set
officeand a rule for a contractor network could setcontractor. Each would then need its own filter, because an internal traffic filter checks for one value. - If you only need one filter, use the same
traffic_typevalue in every rule. All rules can shareinternal, and one filter then covers all of them. - The value is a free-text label. It does not have to say
internal. A name likeqa_teamworks, as long as the filter uses the same one.
Where you can see the parameter
An event parameter is only visible in standard reports if you register it as a custom dimension. A custom dimension is a name you give GA4 so it can show an event parameter as a field in reports and Explorations. You do not need to register traffic_type for filtering to work. The data filter reads the parameter directly.
Registering it is still useful for auditing. With traffic_type available as an event-scoped custom dimension, you can build an Exploration that splits traffic by that value and see how much of it your rules are catching. It can also help you spot events that should have been tagged but were not.
If you export data to BigQuery, traffic_type appears as a key in the event_params array on the events that carry it.
Timing and retroactivity
Two timing facts affect everything else in this tutorial:
- A rule tags events only from the moment it is saved. It does not go back and relabel events that GA4 already collected.
- A manual
traffic_typevalue is only on events sent after your code sets it.
Because of this, the first minutes after a change can look inconsistent. Some of your own events may be tagged and some may not. Judge a change by events collected after it was in place, not by the whole day's report.
Common mistakes
The code sets the value after the first events have gone out. If gtag('config', ...) runs once without the parameter and your staff check runs later, the first page view is untagged. Make the decision before the config call. Alternatively, send the parameter with gtag('set', ...) before config.
A rule is defined, but there is no filter. The label is present on events and reports still include them. Check the Data filters list in the property settings.
The rule value and the filter value differ. A rule sets internal while the filter looks for internal_traffic. Nothing is excluded, and nothing warns you. A filter in the Testing state helps here, because you can check whether any events carry its name.
The IP address you entered is your private address. Addresses such as 192.168.x.x or 10.x.x.x are only valid inside your network. GA4 sees the public address that your network presents to the internet, so the rule must use that one. Search for "what is my IP" from inside the office, or ask your network administrator.
Several tags on one page. If a page loads two GA4 tags that point at different properties, each property has its own rules and filters. Setting traffic_type in one config call does not affect the other.
A short worked example
A company has an office with the public address range 203.0.113.0/24. Staff browse the company's site all day, so the analytics team wants them excluded.
- They create one internal traffic rule named "Head office" with the
traffic_typevalueinternaland the CIDR range203.0.113.0/24. - A developer working from home needs to be excluded too. The company's staging build calls
gtag('config', 'G-XXXXXXXXXX', {'traffic_type': 'internal'}), so those events carry the same value without an IP rule. - In the property's data filter settings, they create an internal traffic filter that looks for
internal.
Now both groups reach the same filter through different routes. If the developer's build had used Internal with a capital I, the filter would have missed those events. Matching values is the thing to check first when something does not get excluded.
Summary of how it fits together
| Question | Answer |
|---|---|
| What is `traffic_type`? | An event parameter whose value labels the origin of the traffic. |
| Who sets it? | An internal traffic rule (by IP) or your own code. |
| What reads it? | An internal traffic data filter. |
| Does setting it exclude anything by itself? | No. A data filter must exist and be Active. |
| Does it change past data? | No. It applies to events collected after the change. |
Exercise
A team defined an internal traffic rule with the traffic_type value internal for their office range, and they created a data filter for the value office. Staff visits still show up in reports. Name the cause and give two ways to fix it.
Show answer
The rule and the filter use different values, so the filter never matches the label on the events. Fix it either by changing the filter to look for internal, or by changing the rule's traffic_type value to office. Either way, the two values must be identical. Only events collected after the change are affected, because changes are not retroactive.
Exercise
Your page code runs gtag('config', 'G-XXXXXXXXXX'); immediately and then, a second later, runs a check that sets traffic_type to internal for staff. Why might the first page view of each staff visit still appear in reports, and what is the fix?
Show answer
The first config call sends the page view before the value is set, so that event has no traffic_type. The fix is to make the staff check run first and pass { 'traffic_type': 'internal' } in the config call, or to set the value with gtag('set', ...) before config.