Comprehensive troubleshooting guide for when analytics and marketing pixel events fail to fire on your PrestaShop store.
Quick Diagnostic Checklist
Before diving deep, run through this checklist:
Basic Checks
- Clear PrestaShop cache:
rm -rf var/cache/* - Disable ad blockers: Test with all browser extensions disabled
- Check browser console: Look for JavaScript errors (F12 > Console)
- Verify tracking code exists: View page source, search for tracking ID
- Test in incognito mode: Rules out cookie/cache issues
- Module is enabled: Check module status in Back Office
- Correct tracking ID: Verify GA4 Measurement ID / Meta Pixel ID format
Platform-Specific Checks
- PrestaShop version: Check compatibility with tracking module
- PHP version: Ensure meeting requirements
- Theme compatibility: Test with default theme
- Module conflicts: Disable recently installed modules
- Hook registration: Verify module hooks are registered
Common Scenarios and Solutions
Scenario 1: No Tracking Code on Page
Symptoms:
- No tracking script in page source
- Tracking pixel not detected by browser extensions
- No network requests to analytics servers
Diagnostic Steps:
1. View Page Source:
Right-click page > View Page Source
Ctrl+F to search for:
- GA4: "googletagmanager.com/gtag/js" or "G-"
- Meta Pixel: "facebook.net/fbevents.js" or "fbq"
- GTM: "googletagmanager.com/gtm.js" or "GTM-"
2. Check Module Installation:
Back Office > Modules > Module Manager > Search for tracking module
Verify:
- Module is installed
- Module is enabled
- Configuration is saved
3. Check Module Configuration:
Module > Configure
Verify:
- Tracking ID is entered correctly
- Module is enabled/activated
- No validation errors shown
Solutions:
A. Module Not Loading in Hook:
// Check if module hooks are registered
// Create file: debug-hooks.php in PrestaShop root
<?php
require_once('config/config.inc.php');
$module_name = 'your_tracking_module'; // Replace with your module name
$module = Module::getInstanceByName($module_name);
if ($module) {
echo "Module found: " . $module->displayName . "\n\n";
// Check registered hooks
$hooks = $module->getHooks();
echo "Registered Hooks:\n";
foreach ($hooks as $hook) {
echo "- " . $hook . "\n";
}
} else {
echo "Module not found!\n";
}
B. Clear All Caches:
# Via command line
cd /path/to/prestashop
rm -rf var/cache/dev/*
rm -rf var/cache/prod/*
rm -rf var/cache/smarty/*
# Regenerate class index
php bin/console prestashop:update:class-index
# Clear XML cache
rm -rf config/xml/*.xml
# Via Back Office
Advanced Parameters > Performance > Clear cache
C. Reinstall Module:
Back Office > Modules > Module Manager
1. Uninstall module
2. Delete module files (if necessary)
3. Re-upload/install module
4. Configure with tracking ID
5. Clear cache
6. Test again
Scenario 2: Tracking Code Loads But Events Don't Fire
Symptoms:
- Tracking script visible in page source
- Base code loads (GTM, fbq, gtag functions exist)
- Specific events (AddToCart, Purchase, etc.) don't fire
Diagnostic Steps:
1. Check Browser Console:
F12 > Console tab
Look for:
- JavaScript errors (red text)
- "gtag is not defined"
- "fbq is not defined"
- "Uncaught TypeError"
2. Check Network Tab:
F12 > Network tab > Filter by "analytics" or "facebook"
Reload page and perform action (add to cart, etc.)
Check:
- Are requests being sent?
- What's the status code? (200 = success)
- Are parameters included?
3. Use Tracking Debuggers:
For GA4:
- Install "Google Analytics Debugger" extension
- Or add
debug_mode: trueto gtag config - Check GA4 DebugView in Analytics
For Meta Pixel:
- Install "Meta Pixel Helper" extension
- Check for green checkmark (working) or red X (error)
- Review warnings/errors in extension popup
For GTM:
- Use GTM Preview mode
- Click Preview in GTM workspace
- Enter your store URL
- Browse site while watching debugger
Solutions:
A. JavaScript Errors Blocking Execution:
// Common error: gtag/fbq called before script loads
// Check script loading order in page source
// WRONG ORDER:
<script>gtag('event', 'page_view');</script> // Called first
<script src="gtag/js"></script> // Loaded second
// CORRECT ORDER:
<script src="gtag/js"></script> // Loaded first
<script>gtag('event', 'page_view');</script> // Called second
Fix in PrestaShop module:
// Ensure base code loads before events
public function hookDisplayHeader($params)
{
// Load base tracking code
return $this->display(__FILE__, 'views/templates/hook/base-code.tpl');
}
// Events fire in separate hook that executes after header
public function hookDisplayFooterProduct($params)
{
// This fires after displayHeader, so gtag/fbq will be available
return $this->display(__FILE__, 'views/templates/hook/product-event.tpl');
}
B. Events Fire But Parameters Missing:
// Debug: Log event data before sending
console.log('Firing event with data:', eventData);
gtag('event', 'add_to_cart', eventData);
// Check console output - are all parameters present?
// Missing parameters often due to:
// 1. PrestaShop context data not available
// 2. Smarty variables not assigned
// 3. JavaScript unable to find DOM elements
Fix missing parameters:
// In module hook - ensure all data is assigned
public function hookDisplayFooterProduct($params)
{
$product = $params['product'];
// Get all needed data
$product_data = array(
'item_id' => (string)$product->id,
'item_name' => $product->name,
'price' => $product->getPrice(true)
);
// Verify data before assigning
if (empty($product_data['item_id'])) {
PrestaShopLogger::addLog('Product ID missing in tracking event', 3);
return '';
}
$this->context->smarty->assign('product_data', $product_data);
return $this->display(__FILE__, 'views/templates/hook/event.tpl');
}
C. Cookie Consent Blocking Events:
// Check if consent is preventing tracking
console.log('Cookie consent status:', prestashop.gdprConsent);
// Events should only fire if consent given
if (typeof prestashop !== 'undefined' && prestashop.gdprConsent) {
if (prestashop.gdprConsent.analytics) {
// Fire analytics events
gtag('event', 'page_view');
}
} else {
console.log('No consent - events blocked');
}
Scenario 3: Purchase Event Not Firing
Symptoms:
- Other events work fine
- Purchase/conversion event doesn't fire on order confirmation
- Revenue not tracked
Diagnostic Steps:
1. Test Order Completion:
- Place real test order (or use test payment method)
- Reach order confirmation page
- Check browser console for errors
- Check Network tab for analytics requests
- Look for purchase event in GA4 DebugView / Meta Test Events
2. Check Page Source on Order Confirmation:
View Source on order confirmation page
Search for:
- "purchase" event
- Order reference/transaction ID
- Order total value
Solutions:
A. Module Not Hooked to Order Confirmation:
// Verify hook registration
public function install()
{
return parent::install()
&& $this->registerHook('displayOrderConfirmation'); // Must be registered
}
// Implement hook
public function hookDisplayOrderConfirmation($params)
{
$order = $params['order'];
// Fire purchase event
$this->context->smarty->assign(array(
'transaction_id' => $order->reference,
'value' => $order->total_paid_tax_incl,
'currency' => $this->context->currency->iso_code
));
return $this->display(__FILE__, 'views/templates/hook/purchase-event.tpl');
}
B. Duplicate Purchase on Refresh:
// Prevent duplicate purchase tracking on page refresh
var transactionId = 'ORDER_REFERENCE_HERE';
var cookieName = 'purchase_tracked_' + transactionId;
function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
}
// Only fire if not already tracked
if (!getCookie(cookieName)) {
gtag('event', 'purchase', purchaseData);
// Set cookie to prevent duplicate (expires in 24 hours)
document.cookie = cookieName + '=1; path=/; max-age=86400';
}
C. Order Data Not Available:
// Debug order data availability
public function hookDisplayOrderConfirmation($params)
{
// Check if order exists
if (!isset($params['order'])) {
PrestaShopLogger::addLog('Order not available in displayOrderConfirmation hook', 3);
return '';
}
$order = $params['order'];
// Log order data for debugging
PrestaShopLogger::addLog(
'Order Confirmation: ID=' . $order->id . ', Reference=' . $order->reference . ', Total=' . $order->total_paid_tax_incl,
1
);
// Continue with event firing...
}
Scenario 4: Events Fire Multiple Times (Duplicates)
Symptoms:
- Same event fires 2-3 times
- Inflated analytics numbers
- Duplicate events in GA4 DebugView
Diagnostic Steps:
// Monitor how many times event fires
var eventCounter = {};
var originalGtag = window.gtag;
window.gtag = function() {
var eventName = arguments[1];
eventCounter[eventName] = (eventCounter[eventName] || 0) + 1;
console.log('Event fired:', eventName, 'Count:', eventCounter[eventName]);
return originalGtag.apply(this, arguments);
};
Common Causes:
- Multiple tracking modules active
- Manual code + module both implementing tracking
- Theme + module both firing events
- Event fires on page load AND user interaction
Solutions:
A. Check for Multiple Implementations:
# Search all theme/module files for tracking code
cd /path/to/prestashop
grep -r "gtag('event'" themes/
grep -r "fbq('track'" themes/
grep -r "gtag('event'" modules/
grep -r "fbq('track'" modules/
B. Disable Duplicate Modules:
Back Office > Modules > Module Manager
Search for: "analytics", "google", "facebook", "pixel"
Disable all but one implementation
C. Add Deduplication Logic:
// Prevent same event from firing multiple times
var firedEvents = {};
function fireEventOnce(eventName, eventData) {
var eventKey = eventName + JSON.stringify(eventData);
if (!firedEvents[eventKey]) {
gtag('event', eventName, eventData);
firedEvents[eventKey] = true;
} else {
console.log('Duplicate event prevented:', eventName);
}
}
// Use instead of direct gtag call
fireEventOnce('add_to_cart', {
item_id: '123',
value: 29.99
});
Scenario 5: Events Work in Desktop Browser But Not Mobile
Symptoms:
- Events fire correctly on desktop
- Mobile devices don't send events
- Mobile has different behavior
Diagnostic Steps:
1. Test on Actual Mobile Device:
- Use real phone/tablet, not just responsive mode
- Connect device to same WiFi as computer
- Use remote debugging:
- Chrome: chrome://inspect
- Safari: Develop menu > Device name
2. Check Mobile-Specific Issues:
- Touch events vs click events
- Mobile theme vs desktop theme
- Network connection quality
- Browser differences (Safari vs Chrome)
Solutions:
A. Use Touch Events:
// Listen for both click and touch events
function addEventListeners(element, callback) {
element.addEventListener('click', callback);
element.addEventListener('touchend', callback);
}
// Use on buttons
var addToCartButtons = document.querySelectorAll('[data-button-action="add-to-cart"]');
addToCartButtons.forEach(function(button) {
addEventListeners(button, function(e) {
// Fire tracking event
gtag('event', 'add_to_cart', eventData);
});
});
B. Check for iOS Safari Specific Issues:
// iOS Safari may block tracking due to ITP (Intelligent Tracking Prevention)
// Use first-party cookies and avoid third-party domains
// Check if Safari
var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
if (isSafari) {
console.log('Safari detected - using alternative tracking method');
// Implement alternative or use Conversions API
}
Scenario 6: GTM Preview Mode Shows Events But Production Doesn't
Symptoms:
- GTM Preview mode shows events firing correctly
- Events don't fire after publishing container
- Tags work in debug but not live
Solutions:
A. Publish GTM Container:
Google Tag Manager > Submit > Publish
- Ensure you clicked Publish, not just Submit
- Check version number increased
- Clear browser cache after publishing
B. Check GTM Triggers:
Tags may fire in Preview but not production due to:
- Trigger conditions not met in production
- Variables returning different values
- Consent state different in production
Verify triggers in GTM:
- Check trigger conditions
- Test variables return expected values
- Review trigger history in debugger
C. GTM Container Not Loading:
// Check if GTM container loaded
if (typeof google_tag_manager !== 'undefined') {
console.log('GTM loaded successfully');
console.log('Container:', google_tag_manager);
} else {
console.log('GTM not loaded - check container ID');
}
PrestaShop-Specific Debugging
Check Module Hooks
-- Verify module hooks in database
SELECT h.name, hm.position
FROM ps_hook_module hm
JOIN ps_hook h ON hm.id_hook = h.id_hook
JOIN ps_module m ON hm.id_module = m.id_module
WHERE m.name = 'your_tracking_module'
ORDER BY h.name, hm.position;
-- Should show:
-- displayHeader
-- displayFooterProduct
-- displayOrderConfirmation
-- etc.
Enable Debug Mode
// config/defines.inc.php
// Enable debug mode to see errors
if (!defined('_PS_MODE_DEV_')) {
define('_PS_MODE_DEV_', true);
}
Check Error Logs
# PrestaShop error logs
tail -f var/logs/$(date +%Y%m%d)_exception.log
# PHP error logs
tail -f /var/log/php8.1-fpm.log
# Look for:
# - Module exceptions
# - Smarty compilation errors
# - Hook execution errors
Test with Default Theme
Back Office > Design > Theme & Logo > Select Classic Theme
If events work with default theme:
- Issue is with custom theme
- Check theme template files
- Verify theme doesn't override tracking code
Systematic Debugging Process
Step 1: Isolate the Problem
Questions to Answer:
- Which events don't fire? (All / Specific events)
- Which pages affected? (All pages / Specific pages)
- Which browsers affected? (All / Specific browsers)
- Which devices affected? (Desktop / Mobile / Both)
- When did it stop working? (Never worked / Worked before)
Step 2: Verify Prerequisites
Checklist:
- Tracking ID correct format
- Module/code installed and enabled
- Cache cleared
- No JavaScript errors in console
- Base tracking code loads before events
- Required data available (product ID, price, etc.)
Step 3: Test Incrementally
Start Simple:
- Test PageView (simplest event)
- Test ViewContent (single product page)
- Test AddToCart (requires interaction)
- Test Purchase (requires full checkout)
Identify where it breaks:
- If PageView works but ViewContent doesn't → Product data issue
- If desktop works but mobile doesn't → Device-specific issue
- If Preview works but production doesn't → Configuration issue
Step 4: Check Data Flow
User Action
↓
PrestaShop Hook Fires
↓
Module Hook Function Executes
↓
Data Assigned to Smarty
↓
Template Rendered
↓
JavaScript Executes
↓
Event Sent to Analytics
↓
Event Received and Processed
Verify each step:
- Hook fires: Add logging to hook function
- Data assigned: Check Smarty variables
- Template rendered: View page source
- JavaScript executes: Check console
- Event sent: Check Network tab
- Event received: Check GA4/Meta debugger
Testing Tools and Techniques
Browser Console Debugging
// Check if tracking functions available
typeof gtag !== 'undefined' // Should return true
typeof fbq !== 'undefined' // Should return true
typeof dataLayer !== 'undefined' // Should return true (for GTM)
// Manually fire test event
gtag('event', 'test_event', {
test_parameter: 'test_value'
});
// Check dataLayer
console.log(window.dataLayer);
// Monitor all network requests to analytics
var originalFetch = window.fetch;
window.fetch = function() {
if (arguments[0].includes('google-analytics.com') || arguments[0].includes('facebook.com')) {
console.log('Analytics request:', arguments[0]);
}
return originalFetch.apply(this, arguments);
};
Network Tab Analysis
F12 > Network tab
Filter by:
- "collect" (for GA4)
- "facebook" (for Meta Pixel)
- "gtm" (for GTM)
Click on request and check:
- Headers: Status code (should be 200)
- Payload: Event parameters
- Response: Server response
If no requests:
- Event not firing at all
- Requests blocked by browser/extension
Create Debug Module
<?php
// modules/trackingdebug/trackingdebug.php
class TrackingDebug extends Module
{
public function __construct()
{
$this->name = 'trackingdebug';
$this->version = '1.0.0';
parent::__construct();
}
public function install()
{
return parent::install()
&& $this->registerHook('displayHeader');
}
public function hookDisplayHeader($params)
{
// Log all context data
PrestaShopLogger::addLog(
'Page: ' . $this->context->controller->php_self .
', Customer: ' . ($this->context->customer->isLogged() ? $this->context->customer->id : 'Guest') .
', Cart: ' . $this->context->cart->id,
1
);
// Output debug info to page
echo "<!-- Debug: Controller=" . get_class($this->context->controller) . " -->";
}
}
Prevention Best Practices
Use Version Control
# Track all custom tracking code
git init
git add modules/custom_tracking/
git commit -m "Initial tracking implementation"
# Before making changes
git checkout -b tracking-updates
# Make changes
git commit -m "Updated purchase event tracking"
Document Implementations
# Tracking Implementation Documentation
## GA4 Setup
- Module: Custom GA4 Module v1.0
- Measurement ID: G-XXXXXXXXXX
- Events Implemented:
- PageView: displayHeader
- ViewContent: displayFooterProduct
- AddToCart: JavaScript (cart-tracking.js)
- Purchase: displayOrderConfirmation
## Known Issues
- Purchase event must use deduplication cookie
- Mobile Safari requires touchend event listener
## Testing Checklist
- [ ] Test on desktop Chrome
- [ ] Test on mobile Safari
- [ ] Test purchase event doesn't duplicate on refresh
- [ ] Verify in GA4 DebugView
Regular Testing
# Create automated test script
#!/bin/bash
echo "Testing tracking on PrestaShop..."
# Test homepage
echo "Testing homepage..."
curl -s https://yourstore.com | grep -q "gtag" && echo "✓ GA4 on homepage" || echo "✗ GA4 missing"
# Test product page
echo "Testing product page..."
curl -s https://yourstore.com/product-url | grep -q "view_item" && echo "✓ ViewContent event" || echo "✗ ViewContent missing"
# Test order confirmation
echo "Manual test required: Complete test order and verify purchase event"
When to Seek Help
Contact PrestaShop developer or tracking specialist if:
- Events don't fire after trying all solutions
- Complex multi-store setup with different tracking needs
- Custom checkout process or modules
- Server-side tracking (Conversions API) required
- Need to track custom user flows
- Compliance requirements (GDPR, CCPA)
Prepare This Information:
- PrestaShop version
- PHP version
- Tracking module name and version
- Specific events not working
- Steps already attempted
- Error logs
- Screenshots of browser console/network tab
Next Steps
- GA4 Setup - Proper GA4 implementation
- Meta Pixel Setup - Meta Pixel implementation
- GTM Data Layer - GTM and data layer setup
- Troubleshooting Overview - Other PrestaShop issues