Sub topic 11
Excluding traffic without fixed IP addresses
IP-based rules only work when you know the addresses your team browses from. Remote staff, home broadband with changing addresses, mobile networks, and contractors all break that assumption. This chapter covers other ways to mark internal visits so the GA4 data filter can exclude them.
This chapter assumes you have:
- Editor access to a GA4 property with a web data stream.
- Created an internal traffic rule and data filter, as covered in earlier chapters.
- Basic familiarity with
gtag.jsor Google Tag Manager (GTM).
The principle: the filter reads a value, not an IP address
The internal traffic data filter does not check IP addresses itself. It checks the traffic_type event parameter. An IP-based rule is one way to set that parameter. Any other way of setting it works equally well, and the same filter then excludes those events.
So every method here answers one question: how does the browser or tag know this visit is internal, without relying on the network address?
- You can set
traffic_typeyourself from a signal you control, such as a cookie, a login role, or a URL parameter. - You can stop the tag from sending data at all, using a browser-side opt-out.
- You can move test activity to a separate property, so it never reaches the production reports.
Method 1: Set traffic_type from a cookie
A cookie marks one browser as internal, whatever network it uses. The usual workflow:
- Staff open a private marker URL once, for example
https://example.com/?internal=1. - A script stores a first-party cookie in that browser.
- On every later page load, the tag reads the cookie and sets
traffic_typetointernal.
This gtag.js example does all three steps. It must run before the config call.
// Step 1 and 2: remember this browser as internal when the marker URL is used.
const params = new URLSearchParams(window.location.search);
if (params.get('internal') === '1') {
document.cookie = 'ga_internal=1; max-age=31536000; path=/; SameSite=Lax; Secure';
}
// Step 3: read the cookie on every page load.
const isInternal = document.cookie.split('; ').includes('ga_internal=1');
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
// Only internal browsers send the parameter. Everyone else is untouched.
gtag('config', 'G-XXXXXXXXXX', isInternal ? { traffic_type: 'internal' } : {});This assumes the gtag.js library is loaded separately with a <script async src=...> element. The Secure attribute needs HTTPS, so remove it only on a local test server.
Use the same value in the data filter that you use here (internal in this example). If the cookie sets internal and the filter looks for staff, nothing is excluded, and no error tells you so.
Cookie limits
- Per browser, not per person. Each browser and device needs its own marker visit.
- Clearing cookies removes the marker. A staff member who clears site data appears as a customer again until they revisit the marker URL.
- Safari caps cookies set by JavaScript. Its tracking prevention limits them to about seven days, so Safari users must repeat the marker visit regularly. A cookie set by the server in an HTTP response is not capped this way.
- Private browsing windows start with no cookie, so those visits are counted.
- Anyone can read the marker URL. A customer who finds it can mark their own visits as internal. That only hides their data, but do not publish the URL.
Method 2: Set traffic_type in Google Tag Manager
If you use GTM, the same logic can be configured without editing site code. Create a first-party cookie variable that reads ga_internal. Then add a traffic_type parameter to your GA4 configuration tag, or to a settings variable it uses. Give the parameter a value only when the cookie matches.
A common pattern is a lookup table variable:
| Input variable | Value of input | Output |
|---|---|---|
| `Cookie - ga_internal` | `1` | `internal` |
Set the default output to undefined. If you set it to an empty string, GA4 may receive an empty traffic_type on every external event. An empty value is not useful, so keep it undefined.
Use GTM's Preview mode to confirm that the parameter appears on the tag only when the cookie is present.
Method 3: Use a login or role signal
When staff sign in to your site, the site knows who they are, and that is more dependable than a cookie. Your developers can expose a flag in the data layer, such as userRole: "employee". GTM then maps it to traffic_type.
This approach has trade-offs:
- It follows the person across devices, so it handles remote work well.
- It only covers sessions where the person is signed in. Pages visited before login, such as the login page itself, are still counted unless the cookie method is also in place.
- Do not send email addresses or names to GA4 to do this. Send only the role flag. Google's policies prohibit sending personally identifiable information.
For sites where employees are almost always signed in, combine this with the cookie. The cookie covers the pre-login pages.
Method 4: Stop sending data with an opt-out
The methods above send events and then let the filter remove them. You can also stop the tag from sending anything.
gtag.js honors a window property named after your measurement ID. Setting it to true disables measurement for that page:
// Place before the gtag config call.
window['ga-disable-G-XXXXXXXXXX'] = true;You can wrap this in the same cookie check, so internal browsers never send events. Google also publishes a browser add-on that does this without any site changes. Staff install it in each browser.
The trade-off against Method 1 is that these events are never collected, so you cannot review them later. With the filter in Testing state, you can still see which events would have been excluded, using the Test data filter name dimension. With an opt-out there is nothing to inspect, and a mistake in your condition silently drops real data. Use opt-out for developers who visit constantly. Use the filter approach when you want to verify the result first.
Method 5: Separate properties or streams for non-production traffic
Some internal traffic is not about people at all. Staging sites, QA environments, and local development servers can all send events to your production property.
- Use a separate GA4 property, or a separate data stream, with its own measurement ID for each non-production environment.
- Load the production measurement ID only when the hostname matches your production domain.
const isProduction = window.location.hostname === 'www.example.com';
const measurementId = isProduction ? 'G-PRODUCTION' : 'G-STAGING';This keeps test traffic out of production, and staging data never needs filtering. It also avoids the "too much filtering" problem: a filter is a patch, and a separate property removes the problem at its source.
Choosing a method
| Situation | Best fit | Main weakness |
|---|---|---|
| Office with a fixed public IP | IP-based rule | Misses remote work |
| Remote staff on home internet | Cookie plus GTM | Needs a marker visit per browser |
| Staff always signed in | Login role flag | Pages before login are counted |
| Developers testing constantly | `debug_mode` filter or opt-out | Opt-out data cannot be reviewed |
| Staging or QA environments | Separate property or stream | Needs a hostname check in the tag |
| Contractors you cannot configure | Opt-out add-on, or accept the noise | Depends on their cooperation |
You can use more than one method at once. The filter only cares that traffic_type equals the filter's value, so several sources can feed it.
Checking that it works
Treat each new method like an IP rule and verify it before the filter becomes Active.
- Keep the data filter in Testing state.
- Visit the site from a browser that should be marked internal, and from one that should not.
- In DebugView, confirm that
traffic_typeappears on events from the marked browser only. - After processing, add the Test data filter name dimension to a report, and confirm the marked events carry the filter's name.
- Only then set the filter to Active.
Remember that filters are not retroactive. Events collected before activation stay in the reports.
Common mistakes
- Mismatched values. The tag sends
Internaland the filter expectsinternal. Copy the exact string. - Setting the parameter too late. If
traffic_typeis added after the firstpage_viewis sent, that first event escapes the filter. Set it in the configuration call, not in a later event. - Assuming one visit fixes everything. Cookie and add-on methods need repeating for each browser and device.
- Forgetting unmanaged devices. Phones on mobile data and personal laptops are often missed. Decide deliberately whether to cover them.
Exercise
A company's staff all work from home on connections whose IP addresses change often. Staff sign in to the company site, but they often browse the public pages before signing in. Which combination of methods would you choose, and what value must match between the tag and the data filter?
Show answer
Use a cookie set from a marker URL, read by the tag or GTM to set traffictype, together with a login role flag. The cookie covers the public pages visited before signing in, and the role flag covers staff on browsers that have no cookie yet. Both must send the same traffictype string that the internal traffic data filter is configured to match (for example, internal), spelled and cased identically. Keep the filter in Testing state and verify in DebugView and with the Test data filter name dimension before making it Active.
Exercise
Why might a team prefer a data filter in Testing state over the ga-disable opt-out when first rolling out a cookie-based exclusion?
Show answer
With the filter, the internal events are still collected and flagged, so the team can check in reports which events would be excluded and fix a wrong condition before anything is removed. With the opt-out, events from matching browsers are never sent, so a mistake in the condition silently loses real data that cannot be recovered or inspected.