7.6 KiB
GTM Preview Mode and Debugging Guide
Enabling Preview Mode
Steps:
- Open GTM workspace
- Click Preview button (top-right)
- Enter website URL in popup
- Click Connect
- New browser tab opens with Tag Assistant
Result: Tag Assistant panel shows real-time tag activity
Tag Assistant Interface
Summary Tab
Shows:
- Tags Fired count
- Tags Not Fired count
- Data Layer Messages
- Event timeline
Tags Tab
Categories:
- Tags Fired: Successfully triggered tags
- Tags Not Fired: Tags that didn't trigger
- Tag Firing Failed: Tags with errors
For Each Tag:
- Tag name
- Trigger that fired it
- Variables used
- Parameters sent
Variables Tab
Shows All Variables:
- Name
- Current value
- Type
- Last updated
Data Layer Tab
Shows:
- All dataLayer pushes
- Event details
- Parameters
- Timestamp
Errors Tab
Shows:
- JavaScript errors
- Tag firing errors
- Configuration issues
Debugging Workflow
Step 1: Verify GA4 Configuration Tag
In Tag Assistant:
- Look for "GA4 - Configuration" in Tags Fired
- Check it fired on Initialization - All Pages trigger
- Verify Tag ID is correct (G-XXXXXXXXXX)
Expected: Fires on every page load
Step 2: Test Event Tags
Workflow:
- Trigger expected action (click button, submit form)
- Check Tags Fired for corresponding GA4 event tag
- Expand tag to see:
- Event Name: Correct event name
- Event Parameters: Populated with expected values
- Trigger: Correct trigger fired
Example: Button Click
- Click "Subscribe" button
- Verify "GA4 - Button Click - Subscribe" in Tags Fired
- Check Event Parameters:
button_name: "Subscribe Now"button_location: "header"
Step 3: Verify Variables
In Variables Tab:
- Locate variable (e.g., "DL - Product ID")
- Check Value column
- Verify value matches expected data
Common Variables to Check:
- Data Layer Variables
- Click Variables (after clicking element)
- Form Variables (after form interaction)
- Page Variables (on page load)
Step 4: Check Data Layer
In Data Layer Tab:
- See all
dataLayer.push()calls - Expand each message
- Verify structure and values
Example:
Message: {event: "add_to_cart", product_id: "SKU_123", ...}
Event: add_to_cart
Variables:
- product_id: "SKU_123"
- product_name: "Blue T-Shirt"
- price: 29.99
Step 5: Verify in GA4 DebugView
After Tags Fire in GTM:
- Open GA4 property
- Go to Admin → DebugView
- Events appear in real-time
- Click event to see parameters
Verify:
- Event name matches GTM event name
- Parameters match GTM event parameters
- Values are correct types (strings, numbers)
Common Debugging Scenarios
Scenario 1: Tag Not Firing
Symptoms:
- Tag appears in Tags Not Fired
- Expected action performed but tag doesn't fire
Troubleshooting:
-
Check Trigger Conditions:
- Expand tag in Tags Not Fired
- See "Why didn't this tag fire?"
- Review trigger conditions
-
Verify Trigger Variables:
- Check variables used in trigger
- Ensure they have expected values
-
Check Trigger Type:
- Click trigger: Did you click the right element?
- Form trigger: Did form actually submit?
- Custom Event: Was event pushed to dataLayer?
-
Check Exceptions:
- Tag may have exception preventing firing
Example Fix:
- Problem: Click trigger for button ID "subscribe-btn" not firing
- Check: Click ID variable value
- Find: Actual button ID is "subscribe-button"
- Fix: Update trigger condition
Scenario 2: Wrong Variable Value
Symptoms:
- Tag fires but parameter value is wrong/empty
- Variable shows
undefinedor wrong data
Troubleshooting:
-
Check Variable Configuration:
- Data Layer Variable: Verify key name (case-sensitive)
- JavaScript Variable: Check global variable exists
- Click Variable: Ensure element has attribute
-
Check Data Layer:
- Go to Data Layer tab
- Find relevant dataLayer push
- Verify key exists and has value
-
Check Timing:
- Variable may not be set when tag fires
- Ensure data layer push happens BEFORE tag fires
Example Fix:
- Problem:
product_idvariable empty - Check: Data Layer tab
- Find: Key is
productId(camelCase), notproduct_id - Fix: Update variable name to
productId
Scenario 3: Duplicate Events
Symptoms:
- Same event fires multiple times
- Duplicate events in GA4
Troubleshooting:
-
Check for Multiple Triggers:
- Same event tag may have multiple triggers
- Review tag's triggering section
-
Check for Multiple Tags:
- Multiple tags for same event
- Search for duplicate tag names
-
Check for gtag.js + GTM:
- Website may have both gtag.js snippet AND GTM
- Remove gtag.js if using GTM
Example Fix:
- Problem:
page_viewfiring twice - Find: Both gtag.js snippet in <head> and GTM GA4 Configuration tag
- Fix: Remove gtag.js snippet
Scenario 4: Missing Event Parameters
Symptoms:
- Event fires but some parameters missing
- GA4 DebugView shows event without expected parameters
Troubleshooting:
-
Check Tag Configuration:
- Expand tag in Preview
- Verify all parameters added to tag
-
Check Variable Values:
- Variables Tab: Check parameter variables have values
- Empty variables won't send parameters
-
Check Data Layer:
- Ensure data layer includes all expected keys
- Verify spelling and case
Example Fix:
- Problem:
item_categoryparameter missing fromadd_to_cart - Check: Variables Tab
- Find:
DL - Item Categoryhas valueundefined - Root Cause: dataLayer push missing
item_categorykey - Fix: Update dataLayer push to include
item_category
Advanced Debugging
Debugging Data Layer
View in Console:
// View entire data layer
window.dataLayer
// View last message
window.dataLayer[window.dataLayer.length - 1]
// Monitor pushes
var _push = window.dataLayer.push;
window.dataLayer.push = function() {
console.log('dataLayer push:', arguments);
return _push.apply(this, arguments);
};
Debugging Triggers
Test Trigger Manually:
- Preview mode active
- Open Console
- Manually push event:
dataLayer.push({'event': 'test_event'});
- Check if trigger fires
Debugging Variables
Check Variable in Console:
// For built-in variables
google_tag_manager['GTM-XXXXXXX'].dataLayer.get('variableName')
// For data layer
window.dataLayer.find(item => item.product_id)
Testing Checklist
Before Publishing:
- GA4 Configuration tag fires on all pages
- All event tags fire when expected
- No tags in "Tags Not Fired" section
- Variables populate with correct values
- Event parameters sent to GA4
- No duplicate events firing
- Data Layer pushes correctly formatted
- Events appear in GA4 DebugView
- Parameters match expected values in DebugView
- No JavaScript errors in Errors tab
Best Practices
During Development:
- Test each tag immediately after creating
- Use Preview mode for every change
- Verify in both GTM and GA4 DebugView
- Document expected behavior
- Test on multiple pages/scenarios
Before Publishing:
- Complete testing checklist
- Test with team members
- Document all tags/triggers/variables
- Create version description
- Schedule publication during low-traffic period
After Publishing:
- Verify tags still working in production
- Monitor GA4 DebugView for 30 minutes
- Check standard GA4 reports next day
- Monitor for anomalies