Drupal Tracking Issues
Platform-specific guides for diagnosing and fixing analytics and tracking issues on Drupal.
Common Issues
Events Not Firing
Debug why analytics events aren't being captured on Drupal.
Overview of Drupal Tracking Issues
Drupal's modular architecture and extensive caching mechanisms can create unique challenges for analytics implementation. Common tracking issues stem from module conflicts, aggressive caching strategies, theme template overrides, and complex content delivery workflows. Understanding Drupal's rendering pipeline and cache layers is essential for effective troubleshooting.
Drupal-Specific Tracking Challenges
Module Conflicts
Drupal's module ecosystem can create tracking conflicts:
- Google Analytics modules - Multiple GA modules (google_analytics, ga, simple_ga) can conflict
- Tag management modules - google_tag, tag_manager_advanced may inject duplicate code
- Cache-related modules - Internal Page Cache, Dynamic Page Cache, BigPipe affect code execution
- Performance modules - Advanced CSS/JS Aggregation, AdvAgg can break inline scripts
- Security modules - CSP modules may block tracking scripts
- Form modules - Webform, Entity Form alter AJAX submission tracking
Theme-Level Issues
Theme implementation affects tracking reliability:
- Template overrides - Custom html.html.twig or page.html.twig may exclude tracking region
- Render array modifications - Hook implementations can strip tracking attachments
- Library loading - Improper library dependencies cause timing issues
- Twig template caching - Cached templates may serve outdated tracking code
- Preprocessor functions - Theme preprocess hooks can interfere with script injection
- Base theme inheritance - Parent theme code may override tracking implementations
Caching and Performance Layers
Drupal's multi-tier caching creates tracking complexities:
- Internal Page Cache - Serves cached pages to anonymous users without running PHP
- Dynamic Page Cache - Caches personalized content, may cache tracking state
- BigPipe - Defers non-critical content, affecting script load order
- Render cache - Caches page fragments, can preserve stale tracking code
- Varnish/CDN caching - Edge caching prevents tracking code updates
- Browser cache - Aggressive cache headers prevent script updates
Content Type and Entity Specifics
Different entity types require different tracking approaches:
- Nodes vs Blocks - Tracking on nodes works but blocks fail
- Views pages - AJAX-enabled views don't trigger page views
- Panels/Layout Builder - Custom layouts may exclude tracking regions
- Webforms - Form submissions require special event tracking
- Commerce products - Product views and purchases need ecommerce tracking
Diagnostic Checklist for Tracking Issues
Work through these steps systematically:
1. Verify Code Installation
// Check if tracking script is in DOM
console.log('GTM Container:', document.querySelector('script[src*="googletagmanager.com/gtm.js"]'));
console.log('GA Script:', document.querySelector('script[src*="google-analytics.com/analytics.js"]') ||
document.querySelector('script[src*="googletagmanager.com/gtag/js"]'));
// Check for Drupal.behaviors
console.log('Drupal Behaviors:', Drupal.behaviors);
// Check Google Tag module settings
console.log('Google Tag container ID:', drupalSettings.google_tag?.container_id);
2. Check Module Status
Navigate to /admin/modules and verify:
- Only one analytics module is enabled
- No conflicting tag management modules
- Cache modules are properly configured
- JavaScript aggregation settings
3. Inspect Theme Implementation
Check theme files for tracking code placement:
# Find tracking code in theme templates
grep -r "googletagmanager\|analytics" themes/custom/YOUR_THEME/templates/
# Check for html.html.twig override
ls -la themes/custom/YOUR_THEME/templates/html.html.twig
# Verify page.html.twig doesn't exclude regions
cat themes/custom/YOUR_THEME/templates/page.html.twig | grep -A5 "page_top"
4. Clear All Caches
# Drush command to clear all caches
drush cr
# Or via UI: /admin/config/development/performance
5. Test in Different Scenarios
- Logged in vs anonymous user
- Different content types (node, page, article)
- AJAX-loaded content
- Form submissions
- With/without JavaScript aggregation
- Private browsing mode
Verifying Tracking Code Loads Correctly
Method 1: Browser Developer Tools
// Open Console (F12) and run:
// Check if GTM dataLayer exists
if (typeof dataLayer !== 'undefined') {
console.log('✓ dataLayer exists:', dataLayer);
} else {
console.error('✗ dataLayer not found');
}
// Check Google Analytics
if (typeof gtag !== 'undefined') {
console.log('✓ gtag found');
} else if (typeof ga !== 'undefined') {
console.log('✓ ga (Universal Analytics) found');
} else {
console.error('✗ No Google Analytics found');
}
// Check Drupal settings
console.log('Drupal Settings:', drupalSettings);
Method 2: Network Tab Verification
- Open DevTools Network tab (F12)
- Filter by "gtm" or "analytics"
- Reload page
- Look for:
gtm.js- Google Tag Manager containergtag/js- Google Analytics 4analytics.js- Universal Analyticscollect- Analytics hit requests
Method 3: Check HTML Source
View page source and search for:
<!-- GTM should appear in <head> -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];...})</script>
<!-- GTM noscript should appear after <body> -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXX"></iframe></noscript>
<!-- Check for duplicate installations -->
Method 4: Drupal-Specific Checks
// Check if Google Tag module attached the container
if (drupalSettings.google_tag) {
console.log('Google Tag module settings:', drupalSettings.google_tag);
console.log('Container ID:', drupalSettings.google_tag.container_id);
console.log('Include classes:', drupalSettings.google_tag.include_classes);
}
// Check if tracking is disabled for current role
if (drupalSettings.google_tag && drupalSettings.google_tag.disabled_by_role) {
console.warn('Tracking disabled for current user role');
}
Browser Developer Tools Debugging Guide
Console Debugging
// Enable Google Analytics debug mode
window.ga_debug = {trace: true};
// Listen for dataLayer pushes
(function() {
var originalPush = dataLayer.push;
dataLayer.push = function() {
console.log('dataLayer.push:', arguments);
return originalPush.apply(dataLayer, arguments);
};
})();
// Monitor GTM events
window.addEventListener('gtm.load', function(e) {
console.log('GTM Loaded:', e);
});
// Check Drupal AJAX events (important for Views, forms)
$(document).on('ajaxComplete', function(event, xhr, settings) {
console.log('AJAX Complete:', settings.url);
console.log('Check if tracking fired for this request');
});
// Monitor Drupal behaviors
var originalAttach = Drupal.behaviors.attach;
Drupal.behaviors.attach = function(context, settings) {
console.log('Drupal.behaviors.attach called', context, settings);
return originalAttach.apply(this, arguments);
};
Network Tab Debugging
Filter tracking requests:
gtm
analytics
collect
/g/collect
/r/collect
Inspect request payload for:
- Correct tracking ID/measurement ID
- Page path and title
- Custom dimensions and metrics
- User ID (if implemented)
- Event category, action, label
Application Tab (Cookies)
Check for tracking cookies:
_ga- Google Analytics ID_gid- Session ID_gat- Throttle requests_gcl_*- Google Ads click tracking
Verify cookie domain matches your site domain.
Common Symptoms and Their Causes
| Symptom | Likely Cause | Solution |
|---|---|---|
| No tracking on any page | Code not installed or blocked by cache | Clear all caches, verify module enabled |
| Tracking works logged out, not logged in | Role-based exclusion enabled | Check Google Tag module role settings |
| Duplicate page views | Multiple tracking codes or modules | Audit all modules, check theme for hardcoded tracking |
| Page views work, events don't fire | JavaScript errors or Drupal behaviors not attaching | Check console for errors, verify event code in Drupal.behaviors |
| Tracking delayed by 5+ seconds | BigPipe or JavaScript aggregation issues | Disable aggregation or adjust BigPipe placeholders |
| AJAX content not tracked | No listeners for Drupal AJAX events | Implement tracking in ajaxComplete handler |
| Form submissions not tracked | Forms submitted before tracking fires | Use Webform handlers or form API AJAX callbacks |
| Inconsistent tracking on views | Views caching or AJAX settings | Disable views caching for testing, add AJAX tracking |
| Tracking works locally, not on production | Varnish/CDN caching or environment-specific config | Check cache purging, verify production configuration |
| Ecommerce events missing data | Commerce order data not in dataLayer | Use Commerce GA module or custom order data layer |
| New tracking code doesn't appear | Render cache or Twig cache | Clear render cache: drush cr, disable Twig cache for development |
| Random tracking failures | Race condition with library loading | Ensure tracking library loaded before custom event code |
Tag Manager Troubleshooting for Drupal
GTM Preview Mode Issues
Common issues with GTM Preview on Drupal:
Problem: Preview pane shows "Tag Manager could not detect the container"
Causes:
- Content Security Policy blocking debug script
- Cache serving old container version
- Container code in wrong position
- JavaScript aggregation mangling GTM code
Solutions:
// 1. Add to settings.php to allow GTM debugging
$config['system.performance']['js']['preprocess'] = FALSE;
// 2. Check CSP headers allow GTM
// Add to .htaccess or settings.php:
// Content-Security-Policy: script-src 'self' 'unsafe-inline' *.googletagmanager.com;
// 3. Clear all caches
drush cr
// 4. Verify GTM container placement
// Should be immediately after opening <body> tag
DataLayer Not Populating
Debug dataLayer population:
// Check if dataLayer exists before GTM
console.log('dataLayer before GTM:', window.dataLayer);
// Monitor all dataLayer pushes
window.dataLayerMonitor = setInterval(function() {
if (window.dataLayer) {
console.log('Current dataLayer:', JSON.stringify(window.dataLayer, null, 2));
clearInterval(window.dataLayerMonitor);
}
}, 100);
// For Drupal Commerce ecommerce data
if (drupalSettings.commerce_ga) {
console.log('Commerce GA data:', drupalSettings.commerce_ga);
}
GTM Not Firing on AJAX Pages
Drupal AJAX requires special handling:
// Add to your theme's JavaScript file
(function ($, Drupal, drupalSettings) {
'use strict';
Drupal.behaviors.gtmAjaxTracking = {
attach: function (context, settings) {
// Only run once per context
$(context).once('gtm-ajax').each(function() {
// Track AJAX page loads (Views, etc.)
$(document).on('ajaxComplete', function(event, xhr, ajaxSettings) {
if (typeof dataLayer !== 'undefined') {
dataLayer.push({
'event': 'ajaxPageView',
'virtualUrl': ajaxSettings.url,
'pageTitle': document.title
});
}
});
// Track form AJAX submissions
$(document).on('submit', 'form', function(e) {
var $form = $(this);
if (typeof dataLayer !== 'undefined' && $form.hasClass('ajax-processed')) {
dataLayer.push({
'event': 'formAjaxSubmit',
'formId': $form.attr('id'),
'formAction': $form.attr('action')
});
}
});
});
}
};
})(jQuery, Drupal, drupalSettings);
Cookie and Consent-Related Tracking Problems
EU Cookie Compliance Module
The EU Cookie Compliance module can block tracking:
Check consent status:
// Check if EU Cookie Compliance is active
if (typeof Drupal.eu_cookie_compliance !== 'undefined') {
console.log('EU Cookie Compliance active');
console.log('Current status:', Drupal.eu_cookie_compliance.getCurrentStatus());
}
// Listen for consent events
$(document).on('eu_cookie_compliance.changeStatus', function(e, status) {
console.log('Cookie consent status changed:', status);
if (status === 'accepted') {
// Initialize tracking if not already done
console.log('User accepted cookies, initialize tracking');
}
});
Configuration checklist:
- Go to
/admin/config/system/eu-cookie-compliance - Ensure tracking scripts are in "JavaScript for accepted cookies" field
- Verify "Popup clicking confirmation" is working
- Test in incognito mode
Cookie Consent Manager
For custom cookie consent solutions:
// Example: Initialize tracking after consent
function initializeTrackingAfterConsent() {
if (typeof dataLayer !== 'undefined') {
dataLayer.push({
'event': 'consentGranted',
'analytics_consent': 'granted',
'ad_consent': 'granted'
});
}
// If using gtag consent mode
if (typeof gtag !== 'undefined') {
gtag('consent', 'update', {
'analytics_storage': 'granted',
'ad_storage': 'granted'
});
}
}
// Listen for your consent manager's event
document.addEventListener('cookieConsentAccepted', initializeTrackingAfterConsent);
First-Party Cookie Issues
Drupal-specific cookie domain configuration:
// In settings.php, ensure cookie domain is set correctly
$cookie_domain = '.yourdomain.com'; // Note the leading dot for subdomains
// Check session cookie configuration
$settings['session_write_interval'] = 180;
Drupal-Specific Plugin/Module Conflicts
Known Problematic Module Combinations
Google Analytics + Google Tag modules:
# Check if both are enabled (conflict)
drush pm:list --status=enabled | grep -E "google_analytics|google_tag"
# Disable one:
drush pm:uninstall google_analytics
# OR
drush pm:uninstall google_tag
Advanced CSS/JS Aggregation + Inline Tracking:
// In settings.php, disable JS aggregation for testing:
$config['system.performance']['js']['preprocess'] = FALSE;
// If you need aggregation, exclude tracking scripts:
// Add to your module's hook_js_alter():
function YOURMODULE_js_alter(&$javascript, \Drupal\Core\Asset\AttachedAssetsInterface $assets) {
foreach ($javascript as $key => $script) {
if (strpos($key, 'gtm') !== FALSE || strpos($key, 'analytics') !== FALSE) {
$javascript[$key]['preprocess'] = FALSE;
}
}
}
Lazy Loading Modules + Tracking Images:
Modules like Blazy or Lazy can prevent tracking pixels from loading:
// Exclude tracking pixels from lazy loading
// In your theme's JavaScript:
if (typeof blazy !== 'undefined') {
blazy.excludeClass = 'no-lazy tracking-pixel';
}
Content Security Policy (CSP) Module:
// Add to settings.php or CSP module configuration:
$csp_directives = [
'script-src' => ["'self'", "'unsafe-inline'", '*.google-analytics.com', '*.googletagmanager.com'],
'img-src' => ["'self'", 'data:', '*.google-analytics.com', '*.googletagmanager.com'],
'connect-src' => ["'self'", '*.google-analytics.com', '*.analytics.google.com'],
];
Event Tracking Validation Steps
1. Create Test Event Code
// Add to your theme's custom.js or via Drupal behaviors
(function ($, Drupal) {
'use strict';
Drupal.behaviors.customEventTracking = {
attach: function (context, settings) {
// Track button clicks
$('.track-button', context).once('track-button').on('click', function(e) {
var buttonText = $(this).text();
console.log('Button clicked:', buttonText);
if (typeof dataLayer !== 'undefined') {
dataLayer.push({
'event': 'button_click',
'button_text': buttonText,
'button_id': $(this).attr('id'),
'page_path': window.location.pathname
});
console.log('Event pushed to dataLayer');
} else {
console.error('dataLayer not available');
}
});
// Track outbound links
$('a[href^="http"]', context).once('outbound-tracking').on('click', function(e) {
var href = $(this).attr('href');
var currentDomain = window.location.hostname;
var linkDomain = $('<a>').attr('href', href)[0].hostname;
if (linkDomain !== currentDomain && typeof dataLayer !== 'undefined') {
dataLayer.push({
'event': 'outbound_click',
'outbound_url': href,
'outbound_domain': linkDomain
});
}
});
}
};
})(jQuery, Drupal);
2. Validate Events in Real-Time
// Monitor dataLayer for your events
setInterval(function() {
if (window.dataLayer && window.dataLayer.length > 0) {
var lastEvent = window.dataLayer[window.dataLayer.length - 1];
if (lastEvent.event) {
console.log('Latest event:', lastEvent);
}
}
}, 1000);
// Or use GA4 Debug mode
gtag('config', 'G-XXXXXXXXXX', {
'debug_mode': true
});
3. Check in GTM Preview
- Enable GTM Preview mode
- Perform action that should trigger event
- Check Preview pane for:
- Event appears in Summary
- Correct variables populated
- Tags fired successfully
4. Verify in GA4 DebugView
- Enable debug mode:
gtag('config', 'G-XXXXXXXXXX', {'debug_mode': true}); - Go to GA4 > Configure > DebugView
- Perform tracked action
- Verify event appears with correct parameters
Ecommerce Tracking Troubleshooting
Drupal Commerce Integration
Issue: Product impressions not tracking
// Create custom module to add product data to dataLayer
// In YOURMODULE.module:
use Drupal\commerce_product\Entity\ProductVariation;
/**
* Implements hook_preprocess_commerce_product().
*/
function YOURMODULE_preprocess_commerce_product(&$variables) {
$product = $variables['elements']['#commerce_product'];
// Get product variation data
$variation_id = $product->get('variations')->target_id;
$variation = ProductVariation::load($variation_id);
if ($variation) {
$price = $variation->getPrice();
// Attach product data for tracking
$variables['#attached']['drupalSettings']['ecommerce']['product'] = [
'id' => $product->id(),
'name' => $product->getTitle(),
'price' => $price->getNumber(),
'currency' => $price->getCurrencyCode(),
];
}
}
Then add JavaScript to push to dataLayer:
(function ($, Drupal, drupalSettings) {
'use strict';
Drupal.behaviors.commerceProductTracking = {
attach: function (context, settings) {
if (settings.ecommerce && settings.ecommerce.product) {
var product = settings.ecommerce.product;
if (typeof dataLayer !== 'undefined') {
dataLayer.push({
'event': 'view_item',
'ecommerce': {
'items': [{
'item_id': product.id,
'item_name': product.name,
'price': product.price,
'currency': product.currency
}]
}
});
}
}
}
};
})(jQuery, Drupal, drupalSettings);
Issue: Add to cart events not firing
// Track Drupal Commerce "Add to Cart" buttons
(function ($, Drupal) {
'use strict';
Drupal.behaviors.commerceAddToCartTracking = {
attach: function (context, settings) {
$('.commerce-order-item-add-to-cart-form', context).once('cart-tracking').on('submit', function(e) {
var $form = $(this);
var quantity = $form.find('input[name="quantity[0][value]"]').val() || 1;
// Extract product data from form or page
var productData = {
id: $form.find('input[name="purchased_entity[0][variation]"]').val(),
name: $('.product-title').text(),
quantity: parseInt(quantity)
};
if (typeof dataLayer !== 'undefined') {
dataLayer.push({
'event': 'add_to_cart',
'ecommerce': {
'items': [{
'item_id': productData.id,
'item_name': productData.name,
'quantity': productData.quantity
}]
}
});
console.log('Add to cart event pushed:', productData);
}
});
}
};
})(jQuery, Drupal);
Issue: Purchase/transaction tracking
// In order completion preprocess or hook
function YOURMODULE_preprocess_commerce_checkout_completion(&$variables) {
$order = $variables['order_entity'];
$items = [];
foreach ($order->getItems() as $order_item) {
$items[] = [
'item_id' => $order_item->getPurchasedEntity()->id(),
'item_name' => $order_item->getTitle(),
'price' => $order_item->getUnitPrice()->getNumber(),
'quantity' => (int) $order_item->getQuantity(),
];
}
$variables['#attached']['drupalSettings']['ecommerce']['purchase'] = [
'transaction_id' => $order->getOrderNumber(),
'value' => $order->getTotalPrice()->getNumber(),
'currency' => $order->getTotalPrice()->getCurrencyCode(),
'items' => $items,
];
}
Server-Side Caching Considerations
Varnish Configuration
If using Varnish, tracking code may be cached:
# In your Varnish VCL file
sub vcl_recv {
# Don't cache pages with tracking parameters
if (req.url ~ "(\?|&)(utm_|gclid=|fbclid=)") {
return (pass);
}
}
sub vcl_backend_response {
# Don't cache if Set-Cookie header present
if (beresp.http.Set-Cookie) {
set beresp.uncacheable = true;
return (deliver);
}
}
Drupal Internal Cache Configuration
// In settings.php
// Disable cache for testing
// $settings['cache']['bins']['render'] = 'cache.backend.null';
// $settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';
// $settings['cache']['bins']['page'] = 'cache.backend.null';
// For production, ensure cache contexts include tracking parameters
$config['system.performance']['cache']['page']['max_age'] = 3600;
// Add tracking URL parameters to cache contexts
$settings['cache_contexts'][] = 'url.query_args:utm_source';
$settings['cache_contexts'][] = 'url.query_args:utm_medium';
$settings['cache_contexts'][] = 'url.query_args:utm_campaign';
$settings['cache_contexts'][] = 'url.query_args:gclid';
BigPipe and Tracking
BigPipe can delay tracking script execution:
// Disable BigPipe for testing
// In settings.php:
$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml';
// In development.services.yml:
parameters:
renderer.config:
auto_placeholder_conditions:
max-age: -1
Or ensure tracking is in high-priority placeholder:
// In your module's .module file
function YOURMODULE_page_attachments(array &$attachments) {
$attachments['#attached']['html_head'][] = [
[
'#type' => 'html_tag',
'#tag' => 'script',
'#value' => 'YOUR_TRACKING_CODE_HERE',
'#attributes' => [
'data-big-pipe-placeholder-id' => 'tracking-code',
],
],
'tracking_code',
];
}
CDN and Proxy Troubleshooting
Cloudflare Issues
Problem: Tracking code cached by Cloudflare
Solution:
Create page rule to bypass cache for tracking parameters:
- URL:
*utm_*or*gclid=* - Cache Level: Bypass
- URL:
Purge Cloudflare cache after deploying tracking changes
Verify HTML caching settings:
- Go to Caching > Configuration
- Ensure "Respect Existing Headers" or set max-age appropriately
Problem: Rocket Loader breaking tracking scripts
<!-- Add data-cfasync="false" to exclude from Rocket Loader -->
<script data-cfasync="false">
// Your tracking code here
</script>
Reverse Proxy Headers
Ensure proper headers pass through proxy:
// In settings.php
// Configure reverse proxy
$settings['reverse_proxy'] = TRUE;
$settings['reverse_proxy_addresses'] = ['PROXY_IP_ADDRESS'];
$settings['reverse_proxy_header'] = 'HTTP_X_FORWARDED_FOR';
Debugging Code Examples
Complete Diagnostic Script
Add this to your theme or run in console:
(function() {
console.log('=== Drupal Analytics Diagnostic ===');
// Check Drupal version and settings
console.log('Drupal version:', Drupal.VERSION || 'Unknown');
console.log('Drupal settings:', drupalSettings);
// Check tracking codes
var checks = {
'dataLayer exists': typeof dataLayer !== 'undefined',
'GTM script loaded': !!document.querySelector('script[src*="googletagmanager.com/gtm.js"]'),
'GA4 script loaded': !!document.querySelector('script[src*="googletagmanager.com/gtag/js"]'),
'UA script loaded': !!document.querySelector('script[src*="google-analytics.com/analytics.js"]'),
'Google Tag module': !!drupalSettings.google_tag,
'jQuery available': typeof jQuery !== 'undefined',
'Drupal behaviors': typeof Drupal.behaviors === 'object'
};
console.table(checks);
// Check for errors
var scriptErrors = [];
var scripts = document.querySelectorAll('script[src]');
scripts.forEach(function(script) {
if (script.src.includes('analytics') || script.src.includes('gtm')) {
script.addEventListener('error', function() {
scriptErrors.push(script.src);
});
}
});
if (scriptErrors.length > 0) {
console.error('Failed to load scripts:', scriptErrors);
}
// Check cache status
console.log('Page Cache:', document.querySelector('meta[name="Cache-Control"]')?.content || 'Not set');
// Check for common conflicts
var conflicts = [];
if (drupalSettings.google_tag && drupalSettings.google_analytics) {
conflicts.push('Both google_tag and google_analytics modules detected');
}
if (document.querySelectorAll('script[src*="gtm.js"]').length > 1) {
conflicts.push('Multiple GTM scripts detected');
}
if (conflicts.length > 0) {
console.warn('Potential conflicts:', conflicts);
}
// Monitor next 10 seconds of dataLayer activity
if (typeof dataLayer !== 'undefined') {
var originalPush = dataLayer.push;
var pushCount = 0;
dataLayer.push = function() {
pushCount++;
console.log('dataLayer.push #' + pushCount + ':', arguments[0]);
return originalPush.apply(dataLayer, arguments);
};
setTimeout(function() {
dataLayer.push = originalPush;
console.log('dataLayer monitoring complete. Total pushes:', pushCount);
}, 10000);
}
console.log('=== Diagnostic Complete ===');
})();
Test Event Firing
// Test function to manually trigger events
function testTrackingEvent(eventName, eventData) {
console.log('Testing event:', eventName, eventData);
if (typeof dataLayer === 'undefined') {
console.error('dataLayer not available');
return false;
}
var eventObj = {
'event': eventName,
'timestamp': new Date().toISOString(),
'test': true
};
// Merge in custom data
for (var key in eventData) {
eventObj[key] = eventData[key];
}
dataLayer.push(eventObj);
console.log('Event pushed successfully');
// Wait and check if it appears in dataLayer
setTimeout(function() {
var found = dataLayer.some(function(item) {
return item.event === eventName && item.test === true;
});
console.log('Event in dataLayer:', found);
}, 100);
return true;
}
// Usage:
testTrackingEvent('test_event', {
'category': 'Test',
'action': 'Manual Test',
'label': 'Debugging'
});
When to Contact Support
Contact your analytics vendor or Drupal support when:
Tracking completely fails after following all steps
- Provide: Site URL, Drupal version, enabled modules list, browser console errors
Module conflicts cannot be resolved
- Provide: List of all enabled modules (
drush pm:list --status=enabled) - Provide: Theme name and any custom code
- Provide: List of all enabled modules (
Cache issues persist despite clearing
- Provide: Cache configuration from settings.php
- Provide: Information about CDN/proxy setup
- Run:
drush cr -vand provide output
Platform-specific ecommerce tracking fails
- Provide: Commerce version, order workflow details
- Provide: Sample order for testing
- Include: Checkout completion page HTML source
Custom implementation not working
- Provide: Complete code snippet
- Provide: Browser console output
- Provide: GTM Preview mode screenshots
Information to Gather Before Contacting Support
# Drupal environment info
drush status
# Enabled modules
drush pm:list --status=enabled
# Theme info
drush theme:list
# Configuration export
drush config:get google_tag.settings
# Recent log entries
drush watchdog:show --count=50
# Check for JavaScript errors
# (in browser console, no command)
# System requirements
php -v
composer show
General Fixes
For universal tracking concepts, see the Global Tracking Issues Hub.