Sub topic 6
Turning on debug mode for a website
This chapter shows three ways to flag website traffic as debug traffic so that it appears in DebugView: the debug_mode parameter in gtag.js, Google Tag Manager (GTM) preview mode, and Tag Assistant. It assumes you have a GA4 web data stream, can edit the site's code or its GTM container, and know what an event and an event parameter are.
What debug mode does
Debug mode is a flag on events. When an event arrives with debug_mode set to true (or 1), GA4 treats the sending browser as a debug device and lists it in DebugView. The flag does not change what the browser collects. It changes how GA4 labels the hits.
Three points to keep in mind:
- The flag is per event. A page that sends it on
configflags every event from that page load. A single event can also carry it. - Debug events still go through normal processing. They can show up in standard reports unless you filter them out. A later chapter covers the Developer traffic data filter.
- The flag is read from each hit. If the parameter is missing from a hit, that hit is ordinary traffic, even if earlier hits from the same browser were flagged.
Method 1: the debug_mode parameter in gtag.js
If the site loads the Google tag directly, add debug_mode to the config command. Every event sent after that call carries the flag.
<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());
gtag('config', 'G-XXXXXXXXXX', {
'debug_mode': true
});
</script>Replace G-XXXXXXXXXX with your Measurement ID. Reload the page, then open DebugView (covered in the next chapters). The browser should appear in the device selector within a few seconds.
You can also flag one event only. This helps when you are testing one interaction and do not want every page view flagged.
gtag('event', 'sign_up', {
'method': 'email',
'debug_mode': true
});Only that sign_up event goes to DebugView. Other events from the same browser stay ordinary traffic.
Turning it off
Remove the parameter from the code and redeploy. Do not rely on setting it to false. Several configuration layers can pass the value along as a string, and a missing parameter is the unambiguous way to say "not debug."
Hard-coding is a deployment risk
A debug_mode: true line that reaches production flags every visitor as a debug device. DebugView then becomes unusable, because the device list fills with real users. Gate the flag on something you control, such as a query string:
const params = new URLSearchParams(window.location.search);
const debugOn = params.get('ga_debug') === '1';
gtag('config', 'G-XXXXXXXXXX', debugOn ? { 'debug_mode': true } : {});With this code, only a visit to https://example.com/?ga_debug=1 is flagged. Keep in mind that anyone who knows the parameter can use it. That is acceptable for testing, but their events then go to DebugView and may reach reports.
Method 2: Google Tag Manager preview mode
If the site uses GTM, you usually do not edit code at all.
- Open your container in GTM and click Preview.
- Enter the site URL and click Connect. Tag Assistant opens a new tab with your site.
- Interact with the site. GA4 tags fire in the debug session, and GTM sends the events with
debug_modeset, so the browser appears in DebugView.
Preview mode only flags traffic from the browser that started the session. Other visitors are unaffected, and ending the session stops the flagging. This makes it the safest option for production sites.
If you want the flag on without a preview session, add a field to the Google tag:
- Open the Google tag (or GA4 configuration tag) and go to Configuration settings.
- Add a parameter named
debug_modewith the valuetrue. - Save, then publish only to a test workspace or environment.
Treat this like the hard-coded gtag line. Publishing it to the live container flags all traffic.
Method 3: Tag Assistant
Tag Assistant (tagassistant.google.com) is the tool that runs GTM preview sessions, and it can also connect to sites that use the Google tag without GTM.
- Open Tag Assistant and click Add domain.
- Enter your site URL and click Connect.
- Use the site in the tab it opens. Tag Assistant lists the tags that fire and shows the hits they send.
For a gtag.js site, Tag Assistant's connected session enables debug mode for your browser, so the events reach DebugView without a code change. The connected session works for as long as the Tag Assistant tab is attached.
You may still see references to the Google Analytics Debugger Chrome extension. It also flags traffic as debug, but Tag Assistant and the parameter are the maintained routes, so prefer them.
Choosing a method
| Method | Needs code change | Scope | Best for |
|---|---|---|---|
| `debug_mode` on `config` | Yes | Every event from the page load | Local and staging sites |
| `debug_mode` on one event | Yes | One event | Testing a single interaction |
| GTM preview mode | No | Your browser, one session | Production sites with GTM |
| Tag Assistant connection | No | Your browser, one session | Quick checks, gtag.js sites |
Checking that it worked
Work through this checklist in order:
- Open DebugView in Admin > Data display > DebugView (or Admin > DebugView, depending on your interface version) for the right property.
- Confirm that the device selector at the top left lists your browser. If you have several debug devices, pick yours by its model or browser name.
- Reload the page and check that
page_viewandsession_startappear in the stream. - Trigger the event you are testing and see it appear within seconds.
You can also check the request itself. In your browser's developer tools, open the Network tab, filter by collect, and select a request to google-analytics.com. A flagged hit carries _dbg=1 in its query string. If _dbg=1 is missing, the page is not sending the flag, and DebugView will stay empty.
Common mistakes
- The flag is set on the wrong Measurement ID. The
configcall must name the same stream whose property you are viewing in DebugView. - Cached scripts. A CDN or browser cache can serve the old page without your change. Hard-reload, or test with a cache-busting query string.
- Consent blocking. If consent mode denies analytics storage, hits may be limited or cookieless, and the device may not appear as expected. Test with consent granted first.
- Cross-domain or iframe pages. The flag must be present on the page that sends the hit. A flag set on the parent page does not apply to a separate tag inside an iframe.
- Forgetting to remove it. Flagged events are still real events, so test data can end up in your reports.
Exercise
Your site uses GTM and you must test a new sign_up event on the live site without affecting other visitors or changing code. Which method do you use, and how can you confirm in the browser that the hit is flagged?
Show answer
Use GTM preview mode (connected through Tag Assistant). It flags only your browser's session, so other visitors are unaffected. To confirm, open developer tools, go to the Network tab, filter by collect, and check that the request to google-analytics.com includes _dbg=1 in its query string. Then check that your browser appears in the DebugView device selector.
Exercise
You added gtag('config', 'G-XXXXXXXXXX', { 'debug_mode': true }); to a production page template. What problem will this cause, and what is a safer pattern?
Show answer
It flags every visitor as a debug device, so DebugView fills with real users and your own test device becomes hard to find. The flagged events also still count in reports unless filtered. A safer pattern is to set the flag only when a query-string parameter such as ga_debug=1 is present, or to use GTM preview mode or Tag Assistant, which flag only your own browser.