Common causes and solutions for tracking events that don't fire correctly on MODX sites.
For general tracking troubleshooting, see the global tracking troubleshooting guide.
Quick Diagnosis Checklist
Before diving deep, check these common issues:
- Ad blocker disabled (for testing)
- Incognito/private mode (clear cache)
- Browser console has no errors (F12)
- MODX cache cleared (Manage → Clear Cache)
- Template saved (if recently edited)
- Plugin enabled (if using plugin method)
- GTM container published (if using GTM)
- MODX placeholders parsing (not showing as literal text)
- No plugin conflicts (disable plugins one by one)
MODX-Specific Tracking Issues
Cache Interfering with Tracking
Problem: Tracking events showing cached data instead of current resource.
Diagnosis:
// Check if tracking shows wrong resource ID
// View page source, search for resourceId or similar
Common scenarios:
- Resource ID always shows "1" (homepage)
- Page title always the same across pages
- TVs showing values from different resources
Fix:
Option 1: Use Uncached Tags
<!-- Before: Cached (shows cached data) -->
<script>
dataLayer.push({
'resourceId': '[[*id]]',
'pageTitle': '[[*pagetitle]]'
});
</script>
<!-- After: Uncached (shows current data) -->
<script>
dataLayer.push({
'resourceId': '[[!*id]]',
'pageTitle': '[[!*pagetitle]]'
});
</script>
Option 2: Use Plugin (Always Dynamic)
<?php
// Plugin automatically uses current resource
$resource = $modx->resource;
$dataLayer = [
'resourceId' => $resource->get('id'),
'pageTitle' => $resource->get('pagetitle')
];
Option 3: Clear Cache After Changes
- Manage → Clear Cache
- Test in incognito mode
- Verify correct data appears
MODX Placeholders Not Parsing
Problem: MODX tags appear as literal text in tracking code or browser.
Example in page source:
<script>
gtag('event', 'page_view', {
'page_title': '[[*pagetitle]]', // Should be actual title
'resource_id': '[[*id]]' // Should be number
});
</script>
Causes:
1. Incorrect Tag Syntax
// Wrong syntax
{*pagetitle} // Wrong delimiters
[*pagetitle] // Missing brackets
[[pagetitle]] // Missing asterisk
[[*pagetitle] // Missing closing bracket
// Correct syntax
[[*pagetitle]] // Resource field
[[+placeholder]] // Placeholder
[[++setting]] // System setting
[[!*uncached]] // Uncached resource field
2. Tags in Cached Chunk
If tracking code is in a cached chunk:
// In chunk that's cached elsewhere
<script>
gtag('event', 'page_view', {
'page_title': '[[!*pagetitle]]' // Use uncached !
});
</script>
Or move tracking to template instead of chunk.
3. Parser Not Processing
Check template:
- Template is saved
- Resource is published
- Cache is cleared
Verify in browser:
// Console check
console.log('Resource ID:', '[[*id]]');
// If shows [[*id]], parser didn't run
Template Variable (TV) Values Not Available
Problem: TV placeholders show empty or undefined in tracking.
Diagnosis:
// Check TV value in template
[[*tv_name]] - Empty or placeholder shows?
Causes & Fixes:
1. TV Not Assigned to Template
Fix:
- Elements → Templates → Your template
- Template Variables tab
- Ensure TV is in "Assigned" list
- Save template
2. TV Not Set on Resource
Fix:
- Edit resource
- Template Variables tab
- Set TV value
- Save resource
3. TV Name Misspelled
// Wrong
[[*product_pric]] // Typo
// Correct
[[*product_price]]
4. TV Output Filter Needed
// May return empty if TV not set
[[*product_price]]
// Better: Provide default
[[*product_price:default=`0`]]
// Or check if exists
[[*product_price:notempty=`[[*product_price]]`:default=`0`]]
Plugin Execution Issues
Problem: Plugin-based tracking not appearing on pages.
Diagnosis:
Check plugin is enabled:
- Elements → Plugins
- Find your tracking plugin
- Ensure checkbox is checked
Check system events:
- Open plugin
- System Events tab
- Ensure correct event checked (e.g.,
OnWebPagePrerender)
Check for errors:
- Reports → Error Log
- Look for plugin-related errors
Common issues:
1. Wrong System Event
// Plugin should be on OnWebPagePrerender for output injection
// Not OnLoadWebDocument (too early) or OnWebPageComplete (too late)
Fix: Check System Events tab, select OnWebPagePrerender.
2. Plugin Disabled
Fix: Enable plugin checkbox and save.
3. Plugin Code Error
// Check error log for PHP errors
// Common issues:
- Undefined variables
- Syntax errors
- Missing semicolons
Debug:
<?php
// Add to plugin to verify it's running
$modx->log(modX::LOG_LEVEL_ERROR, 'Tracking plugin executed');
Check error log to confirm message appears.
4. Plugin Execution Order
Problem: Another plugin interfering.
Fix:
- Elements → Plugins
- Adjust plugin Priority (lower number = higher priority)
- Or disable other plugins temporarily to test
Google Analytics 4 (GA4) Issues
GA4 Events Not Appearing
1. Check GA4 DebugView
Enable debug mode:
gtag('config', 'G-XXXXXXXXXX', {
'debug_mode': true
});
Check DebugView:
- GA4 → Admin → DebugView
- Should see events in real-time
- If events appear here but not in Reports, wait 24-48 hours for processing
2. Verify Measurement ID
<!-- Wrong: Universal Analytics (old) -->
gtag('config', 'UA-XXXXXXXXX');
<!-- Correct: GA4 -->
gtag('config', 'G-XXXXXXXXXX');
Check MODX implementation:
// In template or plugin
G-XXXXXXXXXX // Should start with G-
3. gtag Not Loaded
Console check:
console.log(typeof gtag);
// Should be "function"
// If "undefined", gtag.js didn't load
Causes:
- Script blocked by ad blocker
- Incorrect src URL
- JavaScript error before gtag loads
Fix:
<!-- Ensure gtag.js loads -->
<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');
</script>
4. MODX Data Not Populating
Issue: Events fire but MODX data shows as placeholders.
Diagnosis:
// In GA4 DebugView, check event parameters
// If see [[*id]] instead of number, placeholders not parsed
Fix:
// Ensure MODX tags parse before GA4 code
<script>
gtag('event', 'page_view', {
'page_title': '[[!*pagetitle]]', // Use uncached
'resource_id': '[[!*id]]',
'template': '[[!*template]]'
});
</script>
Or use plugin to avoid parsing issues:
<?php
$resource = $modx->resource;
$gaCode = <<<HTML
<script>
gtag('event', 'page_view', {
'page_title': '{$resource->get('pagetitle')}',
'resource_id': '{$resource->get('id')}',
'template': '{$resource->get('template')}'
});
</script>
HTML;
GA4 via GTM Not Working
Check GTM is loading:
console.log(window.google_tag_manager);
// Should show object with your container
If undefined:
- GTM code not in template
- GTM container ID wrong
- JavaScript error blocking GTM
See GTM Issues below.
Meta Pixel Issues
Meta Pixel Not Loading
1. Verify Pixel Helper
Install Meta Pixel Helper:
- Green icon = Working
- Yellow = Warnings
- Red = Error
- No icon = Not loaded
2. Check Pixel ID
// Correct format: 16-digit number
fbq('init', '1234567890123456');
// Wrong: Letters or wrong format
fbq('init', 'YOUR_PIXEL_ID'); // Placeholder not replaced
3. fbq Not Defined
Console check:
console.log(typeof fbq);
// Should be "function"
If undefined:
<!-- Ensure base pixel code loads -->
<script>
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)}(window, document,'script',
'https://connect.facebook.net/en_US/fbevents.js');
fbq('init', 'YOUR_PIXEL_ID');
fbq('track', 'PageView');
</script>
Meta Pixel Events Not Firing
1. Check Events Manager
Real-time testing:
- Meta Events Manager → Test Events
- Enter MODX site URL
- Perform actions
- Verify events appear within seconds
2. Event Parameters Missing MODX Data
Issue: Events fire but missing resource data.
Fix:
<!-- Ensure MODX placeholders parse -->
<script>
fbq('track', 'ViewContent', {
'content_name': '[[!*pagetitle]]',
'content_ids': ['[[!*id]]'],
'content_category': '[[!*parent:select=`pagetitle`]]'
});
</script>
Or use plugin for reliability:
<?php
$resource = $modx->resource;
$pixelCode = <<<HTML
<script>
fbq('track', 'ViewContent', {
'content_name': '{$resource->get('pagetitle')}',
'content_ids': ['{$resource->get('id')}'],
'value': 0
});
</script>
HTML;
3. FormIt Form Events
Issue: Lead event not firing on form submission.
Diagnosis:
// Check if success message shows
[[!+fi.successMessage:notempty=`Form submitted!`]]
If form submits but event doesn't fire:
<!-- Ensure event code is in success condition -->
[[!+fi.successMessage:notempty=`
<script>
fbq('track', 'Lead', {
'content_name': 'Contact Form',
'content_category': '[[*pagetitle]]'
});
</script>
<p>Thank you! Form submitted.</p>
`]]
Google Tag Manager (GTM) Issues
GTM Container Not Loading
1. Verify Installation
Check template:
// Should be in <head>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});...})(window,document,'script','dataLayer','GTM-XXXXXXX');</script>
// Should be in <body>
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXXX"...></iframe></noscript>
Console check:
console.log(window.google_tag_manager);
// Should show GTM object with container ID
2. Container Not Published
Most common GTM issue: Changes made but not published.
Fix:
- Go to GTM
- Look for "Workspace Changes" banner
- Click Submit
- Click Publish
Verify: Container version should show as "Published"
3. Container ID Wrong
// Check template/plugin for correct ID
GTM-XXXXXXX // Should match your actual container
Data Layer Issues
1. Data Layer Empty or Missing
Console check:
console.log(window.dataLayer);
// Should show array with MODX data
If undefined or empty:
Cause: Data layer not initialized before GTM.
Fix - Template:
<!-- Data layer MUST come BEFORE GTM code -->
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({
'resourceId': '[[!*id]]',
'pageTitle': '[[!*pagetitle]]'
});
</script>
<!-- THEN GTM code -->
<script>(function(w,d,s,l,i){...GTM code...})</script>
Fix - Plugin:
<?php
// Ensure data layer injects before GTM
$dataLayerCode = '...';
$gtmCode = '...';
$output = $modx->resource->_output;
$output = str_replace('</head>', $dataLayerCode . $gtmCode . '</head>', $output);
2. MODX Data Not in Data Layer
Issue: Data layer exists but MODX values missing.
Check:
window.dataLayer.filter(obj => obj.resourceId);
// Should show objects with resourceId
If empty or shows placeholders:
// Use uncached tags
dataLayer.push({
'resourceId': '[[!*id]]', // Uncached
'pageTitle': '[[!*pagetitle]]'
});
// Or use plugin
<?php
$dataLayer = [
'resourceId' => $modx->resource->get('id'),
'pageTitle' => $modx->resource->get('pagetitle')
];
$json = json_encode($dataLayer);
// Push $json to page
GTM Variables Not Populating
Issue: GTM variable shows undefined in Preview mode.
Diagnosis:
- GTM Preview mode
- Variables tab
- Check variable value
Causes:
1. Wrong Data Layer Path
// Wrong
ecommerce.products.0.id
// Correct (check your actual data layer structure)
resourceId
Fix: Match exact data layer structure in GTM variable.
2. Data Doesn't Exist on Page
Example: Trying to get product price on non-product page.
Fix: Use GTM triggers to ensure variable only accessed when data exists.
GTM Tags Not Firing
Check in Preview mode:
- Enable GTM Preview
- Navigate to MODX page
- Check Tags tab
- Look for "Tags Not Fired"
Common causes:
1. Trigger Not Met
Fix: Review trigger conditions, ensure MODX data populates variables correctly.
2. Tag Paused
Fix: In GTM, ensure tag is not paused (unpause in tag settings).
3. Blocking Trigger
Fix: Check for trigger exceptions blocking the tag.
Form Tracking Issues
FormIt Events Not Tracking
Problem: Form submits but tracking event doesn't fire.
Diagnosis:
Confirm form submits:
- Success message shows
- Email received
- Form data saved
Check success condition:
// Does this show after submission?
[[!+fi.successMessage:notempty=`Success!`]]
If form submits but no event:
Fix 1: Ensure Event in Success Block
[[!+fi.successMessage:notempty=`
<!-- Event code here -->
<script>
gtag('event', 'form_submit', {...});
fbq('track', 'Lead', {...});
</script>
<p>Thank you for your submission!</p>
`]]
Fix 2: Use Custom FormIt Hook
Create plugin:
<?php
/**
* Custom FormIt Hook for Tracking
*/
$formName = $hook->getValue('form_name') ?: 'contact';
// Store in session to fire on next page load
$_SESSION['form_submitted'] = [
'formName' => $formName,
'resourceId' => $modx->resource->get('id')
];
return true;
In FormIt:
[[!FormIt?
&hooks=`email,FormItSaveForm,trackFormHook`
]]
Debugging Workflow
Step-by-Step Process
Clear All Caches
- MODX cache: Manage → Clear Cache
- Browser cache: Ctrl+Shift+Delete
- Test in incognito mode
Verify Basic Setup
- Tracking code in template/plugin
- IDs/Container IDs correct
- No JavaScript errors (console)
- Template saved
- Plugin enabled (if using)
Test MODX Placeholders
<!-- Add to template temporarily --> Resource ID: [[*id]]<br/> Page Title: [[*pagetitle]]<br/> <!-- Should show actual values, not placeholders -->Test Tracking Code
// Console checks console.log(typeof gtag); // GA4 console.log(typeof fbq); // Meta Pixel console.log(window.google_tag_manager); // GTM console.log(window.dataLayer); // Data layerUse Platform Tools
- GA4 DebugView
- Meta Events Manager Test Events
- GTM Preview Mode
Check MODX Error Log
- Reports → Error Log
- Look for JavaScript or plugin errors
Test Across Resources
- Test on multiple pages
- Different templates
- Different resource types
Common Error Messages
"gtag is not defined"
Cause: GA4 script not loaded.
Fix:
- Check script src is correct
- Disable ad blocker
- Check for JavaScript errors before gtag
"fbq is not defined"
Cause: Meta Pixel script not loaded.
Fix:
- Verify Pixel base code in template
- Check Pixel ID is correct
- Disable ad blocker
"dataLayer is not defined"
Cause: Data layer not initialized.
Fix:
window.dataLayer = window.dataLayer || [];
// Initialize BEFORE pushing data
MODX placeholder shows as literal text
Cause: Parser not running or wrong syntax.
Fix:
- Use correct syntax:
[[*id]] - Clear MODX cache
- Use uncached:
[[!*id]] - Move to plugin instead of template
When to Get Help
Hire a MODX Developer
- Events still not firing after troubleshooting
- Complex custom tracking requirements
- Plugin development needed
- Template architecture issues
- Multiple integrations conflicting
Find developers: MODX Professional Directory
Platform Support
GA4: Google Analytics Help Meta: Meta Business Help GTM: Tag Manager Help
MODX Community
Forums: forums.modx.com Slack: MODX Slack community Documentation: docs.modx.com
Next Steps
For general troubleshooting strategies, see Tracking Troubleshooting Guide.