Sub topic 5
Debug mode: how events are flagged for DebugView
This chapter explains what debug mode is, how GA4 uses it to route events to DebugView, and which edge cases cause confusion. It assumes you know what events, event parameters and user properties are, and that you have a property with a web or app data stream. Later chapters cover the platform-specific steps in detail. Here you build the working model.
What debug mode actually is
Debug mode is a flag attached to events. It does not change what you measure. It tells GA4 to treat the events from a given device as debug traffic. Debug traffic is shown in DebugView, a report that lists the events from individual devices as they arrive.
Three facts shape everything else in this chapter:
- The flag is set by the sender, not by the GA4 interface. You cannot turn on debug mode for a device from Admin.
- The flag is attached per event. A device appears in DebugView because its events carry the flag.
- Flagged events are still collected as normal events. They are not held back or kept separate from your other data, unless you also apply a filter (see "Debug traffic and your reports" below).
The last point surprises many people. Debug mode makes your test events visible in DebugView, and it also leaves them in your standard reports unless you exclude them.
The debug_mode parameter
On the web, the flag is an event parameter named debug_mode. Its value is true (the boolean) or 1. Any event that carries it is treated as debug traffic.
You can set it in two places.
On the config command
Setting debug_mode on the config command flags every event sent from that page load:
gtag('config', 'G-XXXXXXXXXX', {
'debug_mode': true
});The browser then appears as a device in DebugView. Because config runs once per page load, the flag applies to the page view and to every later event on that page. After the next page load, the flag applies only if the config call still contains it.
On a single event
Setting debug_mode on one event sends only that event to DebugView:
gtag('event', 'sign_up', {
'method': 'email',
'debug_mode': true
});This is useful when you want to test one interaction without flagging the rest of the session. The trade-off is that DebugView then shows a partial picture. You see the sign_up event but not the page_view or session_start events that came before it, so you cannot judge session behavior from that stream.
Choosing between the two
| Approach | What is flagged | Best for | Risk |
|---|---|---|---|
| `debug_mode` on `config` | All events from the page load | Checking a full flow, including `page_view` and automatic events | Easy to leave in production code |
| `debug_mode` on one event | Only that event | Testing a single custom event | Partial view of the session |
How a debug device is identified
DebugView does not list users. It lists devices, because the debug flag travels with the events from a particular browser or app installation.
The device selector in DebugView offers the debug devices that sent flagged events in the last 30 minutes. If you flag events from two browsers, you see two devices. If you clear your cookies or open a private window, GA4 sees a new client, and a new entry can appear.
This has a practical consequence. If you share a test URL with a colleague and both of you trigger flagged events, you see separate devices. Select the right one before concluding that an event is missing.
What happens to a flagged event
The path of a flagged event is the same as for any other event, with one extra branch.
Three details follow from the diagram.
- DebugView shows events within a few seconds. It is the fastest way to see a single event.
- The Realtime report still counts the flagged events. Debug mode is not a reason an event is missing from Realtime.
- Whether flagged events reach standard reports depends on your filter configuration, not on debug mode alone.
Debug mode and the Developer traffic filter
GA4 properties include a data filter named Developer traffic. It matches events that carry the debug flag, and it can exclude them from reporting. A new property has this filter in the Testing state, which means it labels matching data without removing it. When you set it to Active, matching events are excluded permanently from the reports. A later chapter covers the filter in full, so only the key points are listed here:
- In the Testing state, flagged events still appear in reports. They can be isolated by using the Test data filter name dimension, so you can check what the filter would remove.
- In the Active state, exclusion is permanent. Events removed this way cannot be recovered by changing the filter back.
- The filter matches the debug flag. It does not detect a developer by IP address or by any other signal. (Internal traffic is a separate filter, based on IP address.)
Before you switch the filter to Active, confirm that no production code sends debug_mode. A stray debug_mode: true left in a live tag would then silently remove real visitors from your data.
Setting the flag from other tools
gtag.js is only one way to set the flag. The same flag can come from these sources, each covered in its own chapter:
- Google Tag Manager preview mode, which adds the flag to the GA4 tags it fires while you are previewing.
- The Tag Assistant tool, which can add the flag when it connects to your site.
- The Google Analytics Debugger browser extension, which sets the flag in your own browser without any code change.
- Android and iOS apps, which use launch settings or command-line flags rather than a parameter in code.
- Measurement Protocol requests, which can include the flag in the request itself.
For Android, the flag is controlled with adb commands against a connected device:
# Android: turn on debug mode for an app
adb shell setprop debug.firebase.analytics.app com.example.myapp
# Android: turn it off again
adb shell setprop debug.firebase.analytics.app .none.The setting persists until you turn it off, so remember to run the second command. A device left in debug mode keeps sending debug traffic.
Common errors
These problems account for most "my event is not in DebugView" questions that trace back to debug mode itself.
The flag is set on the wrong call
If you add debug_mode to a gtag('event', ...) call for a later event, the earlier events from the page do not carry it. The device may then show only some of the events you expect. When you want the whole flow, set the flag on config.
The flag is sent as a string
Use the boolean true or the number 1. A value such as "false" is a non-empty string, and you should not rely on it to turn the flag off. To stop flagging events, remove the parameter.
The page loads the configuration twice
If a page runs config once with the flag and once without, for example through a hard-coded tag and a Tag Manager tag, the events from the two sources differ. Some arrive flagged and some do not. Check that only one source configures the stream.
An ad blocker or consent setting stops the request
Debug mode cannot flag an event that never leaves the browser. If a blocker or a consent setting prevents the request, no event arrives in DebugView or in Realtime. Check the Network tab for requests to google-analytics.com before suspecting the flag.
Debug code ships to production
This is the costliest error. A flag left in a live page marks real traffic as debug traffic. With the Developer traffic filter in the Active state, that traffic is removed from reports. Remove the flag before release, or set it only when a condition such as a test hostname is true.
Confirming the flag is present
Before you open DebugView, check that the request actually contains the flag. In your browser's developer tools, open the Network tab and filter for collect. Select a request to google-analytics.com/g/collect and look in the request parameters for _dbg=1. That parameter is how the web flag appears on the wire. If _dbg is absent, DebugView has nothing to show, and the fault lies in how you set the flag, not in GA4.
Exercise
You add 'debug_mode': true to a single gtag('event', 'purchase', ...) call, then open DebugView. You see the purchase event but no page_view or session_start. Why, and what change shows the full flow?
Show answer
The flag is attached only to the purchase event, so only that event is sent to DebugView. The earlier automatic events were sent without the flag. Set debug_mode on the config command instead, then reload the page. All events from that page load are then flagged and shown.
Exercise
A colleague wants to set the Developer traffic filter to Active. List one check you should do first, and explain why.
Show answer
Confirm that no production page or tag sends debug_mode. For example, search the code and Tag Manager containers for it, and look at the Test data filter name dimension while the filter is in Testing. Active exclusion is permanent, so any real visitor flagged by mistake would be removed from reports and could not be recovered.