Sub topic 4
Defining an Internal Traffic Rule
Prerequisites
Assume you have a GA4 property with a web data stream, Editor or Administrator access, and the public IP address used by your office or test network. You should also understand that an event is an interaction recorded by GA4, such as a page view or purchase.
An internal traffic rule does not delete visits immediately. It marks matching events with a special event parameter named traffic_type. A later property-level data filter can use that value to exclude the events.
Open the internal traffic settings
In Google Analytics 4:
- Open Admin.
- Under Data collection and modification, select Data streams.
- Select your web data stream.
- Open Configure tag settings.
- Select Show all.
- Choose Define internal traffic.
- Select Create.
Give the rule a name that identifies its purpose, such as Office network. Set the traffic_type value to internal. The value must match the value that your internal traffic data filter will use later.
Choose the IP condition
The rule needs a condition that matches your network's public IP address. Do not enter a private address such as 192.168.1.20. GA4 receives the public address assigned to your router or network provider.
| Network situation | Suitable match type | Example | Column | Column |
|---|---|---|---|---|
| One fixed public address | IP address equals | `203.0.113.42` | ||
| A consecutive address block | CIDR range | `203.0.113.0/24` | ||
| A pattern that cannot be expressed as a simple range | Regular expression | `^203\.0\.113\.([1-9] | [1-9][0-9] | 1[0-9]{2})$` |
For an office with one address, choose IP address equals. For several addresses, use IP address is in range (CIDR notation) when your network team gives you a CIDR block. CIDR notation describes a base address and the number of network bits. For example, 203.0.113.0/24 covers addresses from 203.0.113.0 through 203.0.113.255.
IP address is in range (CIDR notation): 203.0.113.0/24Use regular expressions only when the simpler match types do not fit. A regular expression is a pattern used to match text. Escape each dot so it means a literal dot rather than “any character.”
^203\.0\.113\.([1-9]|[1-9][0-9]|1[0-9]{2})$Understand the rule's output
When a request comes from a matching IP address, GA4 adds this value to the event:
gtag('config', 'G-XXXXXXXXXX', {
'traffic_type': 'internal'
});The configuration code above is an optional tagging method. It labels all events from that page load as internal, regardless of the visitor's IP address. Use it only when your implementation can reliably identify internal users. The IP-based rule is usually easier to manage for a known office network.
The data filter does not act on the IP address directly. It acts on the traffic_type value. This separation lets the collection rule identify traffic and the property filter decide what to do with it.
After saving the rule, record its name, IP condition, and traffic_type value. The next step is to create a property-level data filter that excludes events where traffic_type equals internal. The rule and filter are separate settings, so creating only the rule does not remove internal traffic from reports.
Exercise
An office uses the public address 203.0.113.42, and the data filter will exclude traffic_type=internal. Which rule settings should you choose?
Show answer
Name the rule clearly, set traffic_type to internal, choose IP address equals, and enter 203.0.113.42.