Enabling Debug Mode for GA4:
Setting with console
- Set the Debug Mode Cookie:
document.cookie = "debug_mode=true;path=/;max-age=31536000;SameSite=Lax;";
This sets a cookie that will last for one year and ensures that the debug mode will persist across multiple pages. - Enable Debug Mode for GA4:
window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-CVZ4RHQ130', { 'debug_mode': true });
Using Query Parameters in the URL:
- Append
?_dbg=1
to the URL in the browser to enable the debug mode for your session. This method works for web applications.
- Append
Using a Browser Extension:
- Install and activate the Google Analytics Debugger Chrome extension. This extension will enable debug mode for all sites you visit with the extension turned on. It works by automatically setting the
_dbg
parameter.
- Install and activate the Google Analytics Debugger Chrome extension. This extension will enable debug mode for all sites you visit with the extension turned on. It works by automatically setting the
Programmatically with gtag.js:
If you have direct access to the
gtag.js
configuration in your code, you can enable debug mode programmatically:
javascriptCopy code gtag('set', 'debug_mode', true);
This method is beneficial if you want to toggle debugging dynamically based on certain conditions, such as only for logged-in users or when a special query parameter is set.
Steps to Track Down Data Missing in GA4 Analytics:
If you have data that appears to be sent from GTM but is missing in GA4, follow these steps to diagnose the issue:
Use GTM Preview Mode:
- Enter GTM Preview mode and perform the action that should trigger the event.
- Check if the appropriate tags are firing and if they are sending the expected data to GA4.
Check GA4 DebugView:
- Open GA4's DebugView to check for real-time data. This view will show you the events as they come in, along with all the parameters.
- DebugView is especially helpful because it can show you if the event hits GA4 even if it's not yet showing up in standard reports.
Review GTM Configuration:
- Ensure that the tags, triggers, and variables in GTM are correctly configured.
- Check that triggers are firing under the correct conditions and that tags are using the correct configuration, especially the GA4 Measurement ID.
Inspect Network Requests:
- Use the Network tab in your browser's developer tools to inspect outgoing network requests.
- Look for requests to
https://www.google-analytics.com/g/collect
and review the query parameters to confirm they contain the correct data.
Audit GA4 Configuration:
- Verify your GA4 configuration to ensure that events are not being filtered or blocked.
- Check that you have set up any required custom definitions or parameters in GA4.
Verify Data Layer Values:
- Ensure that the values pushed to the
dataLayer
are correct and occur before the GTM tags attempt to use them. - The timing of
dataLayer
pushes is crucial; they must happen before the GTM tags that depend on them fire.
- Ensure that the values pushed to the
Review Data Processing Latency:
- Remember that while DebugView is real-time, standard reports in GA4 can have processing latency.
- It may take up to 24-48 hours for events to appear in regular reports.
Check for Filters or Restrictions:
- Ensure that there are no filters applied in GA4 that might exclude the data.
- Also, make sure that any ad blockers or browser extensions are not interfering with GA4 tracking.
Look for GA4 Notifications:
- Check your GA4 property for any notifications that may indicate configuration issues or data collection problems.
Ensure Compliance with GA4 Limits:
- GA4 has limits on the number of events and parameters. Make sure you're not exceeding these limits.
By going through these steps, you can systematically identify where the breakdown might be occurring between GTM and GA4 and resolve issues with missing data.