WordPress Tracking Issues | Blue Frog Docs

WordPress Tracking Issues

Troubleshoot and resolve analytics tracking issues on WordPress websites.

WordPress Tracking Issues

Platform-specific guides for diagnosing and fixing analytics and tracking issues on WordPress.

Common Issues Overview

WordPress tracking issues typically stem from plugin conflicts, theme incompatibilities, caching layers, consent management tools, or JavaScript errors. This comprehensive guide addresses the most common scenarios encountered on WordPress sites.

Events Not Firing

Debug why analytics events aren't being captured on WordPress.

Installation Problems

Plugin-Based Installations

Google Analytics Plugins Not Working

Symptoms:

  • Plugin installed but no data in GA4
  • Measurement ID saved but tracking not active
  • Plugin settings page shows errors

Common Causes:

  1. Duplicate tracking codes - Multiple plugins or manual code conflicting
  2. Caching issues - Page cache serving old version without tracking code
  3. Plugin conflicts - Security or performance plugins blocking script execution
  4. Incorrect Measurement ID format - Using GA3 tracking ID in GA4 field

Solutions:

Check for duplicate installations:

// Add to functions.php temporarily to debug
add_action('wp_footer', function() {
    echo '<!-- Tracking Debug -->';
    echo '<script>console.log("GA loaded:", typeof gtag);</script>';
    echo '<script>console.log("GA4:", typeof window.gtag === "function");</script>';
});

Verify plugin output in page source:

# Check if plugin is outputting code
curl https://yoursite.com | grep -i "gtag\|analytics"

Clear all caches:

  1. WordPress object cache
  2. Page cache (WP Rocket, W3 Total Cache, etc.)
  3. CDN cache (Cloudflare, etc.)
  4. Browser cache

Tag Manager Plugins Issues

MonsterInsights / ExactMetrics:

  • Verify authentication is still active
  • Check if site is authorized in GA property
  • Review excluded user roles (admins often excluded by default)
  • Confirm enhanced ecommerce is enabled for WooCommerce tracking

Site Kit by Google:

  • Re-authenticate Google account connection
  • Verify Site Kit has proper permissions
  • Check if modules are properly activated
  • Review Analytics module settings

Google Tag Manager for WordPress (DuracellTomi):

  • Confirm GTM container ID is correct (GTM-XXXXXX format)
  • Verify container is published
  • Check dataLayer output with browser console
  • Test with GTM preview mode

Manual Code Installation Problems

Code Not Appearing in Source

Check these common issues:

  1. Wrong hook priority:
// May not execute if priority too low
add_action('wp_head', 'my_tracking_code', 999); // Try higher priority
  1. Theme not calling wp_head():
// In header.php, verify this exists before </head>
<?php wp_head(); ?>
  1. Code in wrong location:
// Tracking code should be in wp_head, not wp_footer for most platforms
function add_analytics_code() {
    ?>
    <!-- Google tag (gtag.js) -->
    <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>
    <?php
}
add_action('wp_head', 'add_analytics_code', 1);
  1. Functions.php in wrong theme:
  • Check child theme vs parent theme
  • Verify active theme's functions.php is being used

Code Appearing But Not Executing

JavaScript errors preventing execution:

Check browser console for:

  • Syntax errors in tracking code
  • Conflicts with jQuery or other libraries
  • Security policies blocking script execution
  • Content Security Policy (CSP) violations

Debug with:

// Add to tracking code temporarily
console.log('Analytics script loaded');
if (typeof gtag === 'function') {
    console.log('gtag function available');
} else {
    console.error('gtag function NOT available');
}

WooCommerce Tracking Installation

Enhanced Ecommerce Not Working

Common setup errors:

  1. Missing WooCommerce integration:

    • Most GA plugins require separate enhanced ecommerce activation
    • Verify plugin supports GA4 ecommerce (not just Universal Analytics)
  2. dataLayer not populated:

// Check dataLayer in console on product pages
console.log(window.dataLayer);
// Should show ecommerce objects
  1. Events not matching GA4 requirements:
    • GA4 requires specific event names (view_item, add_to_cart, purchase)
    • Parameters must follow GA4 schema

Verification steps:

  1. Visit product page → Check for view_item event
  2. Add to cart → Check for add_to_cart event
  3. Complete purchase → Check for purchase event with transaction data
// Monitor all dataLayer pushes
const originalPush = dataLayer.push;
dataLayer.push = function() {
    console.log('dataLayer push:', arguments);
    return originalPush.apply(dataLayer, arguments);
};

Configuration Issues

Issue Symptoms Common Causes Solutions
Admin Tracking Own visits inflating data User role exclusion not configured Configure plugin to exclude logged-in admins; use analytics exclusion plugin
Duplicate Events 2x event volume Multiple tracking implementations Audit all plugins and manual code; remove duplicates
Missing Pageviews Low pageview count SPA-like theme without virtual pageviews Implement history change tracking; use GTM with history trigger
Cookie Consent Blocking No tracking until consent Scripts blocked before consent Implement consent mode; use proper GTM consent template
Cross-Domain Tracking Sessions breaking across domains Linker parameters not configured Set up GA4 cross-domain tracking; add domains to referral exclusion
Enhanced Ecommerce No product data dataLayer not implemented Install WooCommerce-specific plugin; verify dataLayer structure
User ID Tracking No user identification User ID not passed to analytics Implement User ID tracking with logged-in user data
Cached Pages Stale data/no updates Aggressive caching Exclude tracking scripts from cache; use AJAX for dynamic data
Localhost Tracking Development data in production No environment filtering Filter localhost; use separate GA4 properties for dev/prod
Bot Traffic Inflated metrics Bot filtering not enabled Enable bot filtering in GA4; use Cloudflare bot protection

Debugging with Developer Tools

Chrome DevTools Workflow

1. Network Tab Inspection

Check tracking requests:

  1. Open DevTools (F12) → Network tab
  2. Filter: collect (for GA4) or analytics or gtag
  3. Reload page
  4. Look for requests to:
    • www.google-analytics.com/g/collect (GA4)
    • www.google-analytics.com/j/collect (GA4)
    • connect.facebook.net (Meta Pixel)
    • bat.bing.com (Microsoft Ads)

What to verify:

Request URL: https://www.google-analytics.com/g/collect?v=2&tid=G-XXXXXXXXXX
Status: 200 OK
Query parameters:
  - v=2 (protocol version)
  - tid=G-XXXXXXXXXX (measurement ID)
  - en=page_view (event name)
  - dl=https://yoursite.com/page (document location)

Common issues:

  • Status 0 → Request blocked by ad blocker or CSP
  • 404 Not Found → Incorrect URL or syntax error
  • No requests → Script not loading or JavaScript error

2. Console Debugging

Check for JavaScript errors:

// Look for errors related to:
// - Uncaught ReferenceError: gtag is not defined
// - Uncaught TypeError: Cannot read property 'push' of undefined

Test tracking manually:

// Test if gtag is available
typeof gtag
// Should return: "function"

// Test if dataLayer exists
window.dataLayer
// Should return: array

// Fire test event
gtag('event', 'test_event', {
    'event_category': 'debugging',
    'event_label': 'manual_test'
});

// Check if event was pushed
dataLayer[dataLayer.length - 1]

3. Application Tab Analysis

Check cookies:

  1. DevTools → Application → Cookies
  2. Look for:

Missing cookies indicate:

  • Consent not granted
  • Cookies blocked by browser
  • Tracking script not executing

Check Local Storage:

  • Some consent tools store preferences here
  • GTM may use for data persistence

Browser Extensions for Debugging

Google Tag Assistant Legacy

How to use:

  1. Install Chrome extension
  2. Navigate to your WordPress site
  3. Click extension icon → Enable
  4. Refresh page
  5. Review tags found

What it shows:

  • Tags present on page
  • Tag implementation errors
  • HTTP vs HTTPS issues
  • Duplicate tags

Google Analytics Debugger

Enables debug mode:

// Shows detailed logging in console
// Install extension and reload page
// Check console for:
// - "Running command: ga("create"...)"
// - Event tracking details
// - Error messages

Meta Pixel Helper

For Facebook tracking:

  1. Install extension
  2. Visit your site
  3. Click extension icon
  4. Review pixel events

Check for:

  • PageView events
  • Custom conversions
  • Pixel ID matches your account
  • No errors or warnings

dataLayer Inspector+

Deep dataLayer inspection:

  • Real-time dataLayer monitoring
  • Event history
  • Variable values
  • GTM debugging

WordPress-Specific Debugging Plugins

Query Monitor

Track PHP errors affecting tracking:

// Install Query Monitor plugin
// Activate and check for:
// - PHP errors in tracking code
// - Slow database queries affecting page load
// - Hook execution order issues

WP Debugging Plugin

Enable WordPress debug mode:

// Adds to wp-config.php automatically:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
define('SCRIPT_DEBUG', true);

Check debug.log for:

  • PHP warnings in tracking plugins
  • Failed API calls to analytics services
  • Database errors

WordPress-Specific Tracking Challenges

Plugin Conflicts

Identifying Conflicting Plugins

Common conflict categories:

  1. Security Plugins:

    • Wordfence
    • Sucuri Security
    • iThemes Security

    Issues caused:

    • Blocking external script loading
    • Stripping JavaScript from headers
    • Firewall blocking analytics requests

    Solutions:

    • Whitelist analytics domains
    • Disable JavaScript filtering
    • Add tracking domains to allowed list
  2. Performance/Caching Plugins:

    • WP Rocket
    • W3 Total Cache
    • Autoptimize
    • LiteSpeed Cache

    Issues caused:

    • Minifying/combining breaks tracking code
    • Caching pages with old tracking code
    • Delaying JavaScript execution

    Solutions:

    WP Rocket:
    - File Optimization → Exclude gtag/analytics from minification
    - Add: gtag/js, analytics.js, gtm.js to exclusions
    
    W3 Total Cache:
    - Minify → Never minify following files: gtag, analytics, fbevents
    
    Autoptimize:
    - Exclude scripts from Autoptimize: gtag, analytics, fbevents.js
    
  3. Cookie Consent Plugins:

    • CookieYes
    • Complianz
    • GDPR Cookie Consent

    Issues caused:

    • Blocking scripts before consent
    • Not unblocking after consent granted
    • Breaking script execution order

    Solutions:

    • Enable analytics in consent categories
    • Use consent mode (GA4)
    • Test consent flow thoroughly

Systematic Conflict Testing

Step-by-step isolation:

  1. Backup your site

  2. Create testing checklist:

☐ Deactivate all plugins except analytics plugin
☐ Test tracking (should work)
☐ Reactivate plugins one by one
☐ Test after each activation
☐ Note which plugin breaks tracking
  1. Test with default theme:
☐ Switch to Twenty Twenty-Four theme
☐ Test tracking
☐ If works, issue is theme-related
☐ If doesn't work, issue is plugin-related
  1. Use Health Check plugin:
    • Enables troubleshooting mode
    • Only affects your admin session
    • Visitors see normal site

Theme Compatibility Issues

Page Builders

Elementor:

  • Custom widgets may not trigger events
  • Preview mode may block tracking
  • Ajax page loads need virtual pageview tracking

Solution:

// Add to tracking code for Elementor
jQuery(document).on('elementor/frontend/init', function() {
    elementorFrontend.hooks.addAction('frontend/element_ready/widget', function($scope) {
        // Track widget interactions
        $scope.find('a').on('click', function() {
            gtag('event', 'click', {
                'event_category': 'elementor_widget',
                'event_label': $(this).text()
            });
        });
    });
});

Divi Builder:

  • Split testing features may cause duplicate tracking
  • Visual Builder mode blocks some scripts

Gutenberg Blocks:

  • Custom blocks need event handlers
  • Dynamic blocks may load after tracking init

Solution for custom blocks:

// In custom block JavaScript
wp.domReady(() => {
    const blocks = document.querySelectorAll('.wp-block-custom');
    blocks.forEach(block => {
        block.addEventListener('click', () => {
            if (typeof gtag === 'function') {
                gtag('event', 'block_interaction', {
                    'block_type': block.dataset.blockType
                });
            }
        });
    });
});

AJAX-Heavy Themes

Single Page Application (SPA) themes:

Problem: Only first pageview tracked, navigation doesn't trigger new pageviews

Solution - History Change Tracking:

// Add to theme or tracking code
(function() {
    let lastPath = location.pathname;

    // Monitor history changes
    setInterval(function() {
        if (location.pathname !== lastPath) {
            lastPath = location.pathname;

            // Send virtual pageview
            if (typeof gtag === 'function') {
                gtag('config', 'G-XXXXXXXXXX', {
                    'page_path': location.pathname + location.search
                });
            }
        }
    }, 500);
})();

Better solution with GTM:

  1. Create History Change trigger
  2. Add GA4 Configuration tag
  3. Set to fire on history change

Multisite Network Issues

WordPress Multisite challenges:

  1. Different tracking codes per site:
// functions.php in network-activated plugin
function multisite_analytics() {
    $blog_id = get_current_blog_id();

    $tracking_ids = array(
        1 => 'G-AAAAAAAAAA', // Main site
        2 => 'G-BBBBBBBBBB', // Site 2
        3 => 'G-CCCCCCCCCC', // Site 3
    );

    $tracking_id = isset($tracking_ids[$blog_id]) ? $tracking_ids[$blog_id] : '';

    if ($tracking_id) {
        ?>
        <script async src="https://www.googletagmanager.com/gtag/js?id=<?php echo $tracking_id; ?>"></script>
        <script>
          window.dataLayer = window.dataLayer || [];
          function gtag(){dataLayer.push(arguments);}
          gtag('js', new Date());
          gtag('config', '<?php echo $tracking_id; ?>');
        </script>
        <?php
    }
}
add_action('wp_head', 'multisite_analytics', 1);
  1. Cross-domain tracking between subsites:

    • Configure cross-domain tracking
    • Add all subdomains to GA4 settings
    • Use same tracking ID or roll-up property
  2. User role exclusions across network:

// Exclude super admins from all sites
function should_track_user() {
    if (is_user_logged_in() && current_user_can('manage_network')) {
        return false;
    }
    return true;
}

function conditional_analytics() {
    if (should_track_user()) {
        // Add tracking code
    }
}
add_action('wp_head', 'conditional_analytics');

Membership and Restricted Content

MemberPress, Restrict Content Pro, etc.:

Challenge: Track member behavior without exposing user data

Solution - User ID Tracking:

function member_tracking() {
    if (is_user_logged_in()) {
        $user_id = get_current_user_id();
        $user = wp_get_current_user();
        ?>
        <script>
          gtag('config', 'G-XXXXXXXXXX', {
              'user_id': '<?php echo $user_id; ?>',
              'dimension1': '<?php echo esc_js($user->roles[0]); ?>', // User role
              'dimension2': '<?php echo esc_js(get_user_meta($user_id, 'membership_level', true)); ?>' // Membership level
          });
        </script>
        <?php
    }
}
add_action('wp_head', 'member_tracking', 20);

Error Messages and Solutions

Common Error Messages

"gtag is not defined"

Error in console:

Uncaught ReferenceError: gtag is not defined

Causes:

  1. Analytics script blocked by ad blocker
  2. Script loading after gtag() calls
  3. CSP blocking external scripts
  4. Network error loading script

Solutions:

Check script loading order:

<!-- This must come BEFORE any gtag() calls -->
<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>

Add fallback:

// Wait for gtag to be available
function safeGtag() {
    if (typeof gtag === 'function') {
        gtag.apply(this, arguments);
    } else {
        console.warn('gtag not available');
    }
}

// Use safeGtag instead of gtag
safeGtag('event', 'click', {...});

"dataLayer is not defined"

Error:

Uncaught ReferenceError: dataLayer is not defined

Cause: GTM container not loaded before dataLayer.push()

Solution:

<!-- Initialize dataLayer BEFORE GTM -->
<script>
  window.dataLayer = window.dataLayer || [];
</script>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){...GTM code...})(window,document,'script','dataLayer','GTM-XXXXXX');</script>

"Failed to load resource: net::ERR_BLOCKED_BY_CLIENT"

Error in Network tab:

www.google-analytics.com/g/collect - Failed to load resource: net::ERR_BLOCKED_BY_CLIENT

Cause: Ad blocker or browser extension blocking request

Solutions:

  1. Test in incognito mode without extensions
  2. Cannot fix for users with ad blockers
  3. Consider server-side tracking for critical metrics
  4. Use Google Tag Manager server-side container

"Refused to load script...Content Security Policy"

Error:

Refused to load the script 'https://www.googletagmanager.com/gtag/js' because it violates the following Content Security Policy directive: "script-src 'self'"

Solution: Update CSP headers:

// Add to functions.php or security plugin settings
add_filter('wp_headers', 'add_analytics_csp');
function add_analytics_csp($headers) {
    $headers['Content-Security-Policy'] = "script-src 'self' 'unsafe-inline' https://www.googletagmanager.com https://www.google-analytics.com; connect-src 'self' https://www.google-analytics.com;";
    return $headers;
}

WooCommerce-Specific Errors

Purchase events not firing

Debug checkout page:

// Add to thank you page temporarily
jQuery(document).ready(function($) {
    console.log('Order data:', <?php echo json_encode($order->get_data()); ?>);
    console.log('dataLayer:', window.dataLayer);

    // Check if purchase event exists
    const purchaseEvent = window.dataLayer.find(item => item.event === 'purchase');
    if (purchaseEvent) {
        console.log('Purchase event found:', purchaseEvent);
    } else {
        console.error('Purchase event NOT found in dataLayer');
    }
});

Common causes:

  1. Cache serving old thank you page
  2. Payment gateway redirecting before event fires
  3. Order status not "completed"
  4. dataLayer not properly initialized

Performance Problems Affecting Tracking

Slow Page Load Breaking Tracking

Issue: Tracking scripts timeout or don't load

Solutions:

  1. Async loading:
<!-- Always use async for gtag -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
  1. Defer non-critical scripts:
// Defer analytics scripts
function defer_analytics_scripts($tag, $handle, $src) {
    $defer_scripts = array('google-analytics', 'gtag', 'facebook-pixel');

    foreach ($defer_scripts as $script) {
        if (strpos($handle, $script) !== false) {
            return str_replace(' src', ' defer src', $tag);
        }
    }
    return $tag;
}
add_filter('script_loader_tag', 'defer_analytics_scripts', 10, 3);
  1. Load GTM in head, not footer:
    • GTM should be as high as possible in <head>
    • Ensures tracking even if page load interrupted

Mobile Performance Issues

Mobile-specific problems:

  1. Slow 3G/4G connections
  2. Limited processing power
  3. Aggressive browser power saving

Solutions:

Test mobile performance:

# Use Lighthouse mobile test
npx lighthouse https://yoursite.com --preset=perf --view --chrome-flags="--emulated-form-factor=mobile"

Optimize for mobile:

// Reduce tracking on slow connections
if ('connection' in navigator) {
    const connection = navigator.connection;

    if (connection.effectiveType === 'slow-2g' || connection.effectiveType === '2g') {
        // Minimal tracking on slow connections
        gtag('config', 'G-XXXXXXXXXX', {
            'send_page_view': true,
            'custom_map': {}  // Disable custom dimensions
        });
    }
}

When to Contact Support

Analytics Platform Support

Contact GA4 Support when:

  • Data appears in DebugView but not in reports (24+ hours)
  • Events showing in real-time but not in standard reports
  • Configuration issues in GA4 interface
  • Data retention or privacy questions

What to provide:

  1. Measurement ID (G-XXXXXXXXXX)
  2. Specific page URLs
  3. Screenshots of DebugView
  4. Expected vs actual behavior

Plugin Support

Contact plugin developer when:

  • Plugin settings save but don't apply
  • Plugin conflicts with WordPress core functionality
  • Error messages specifically mentioning the plugin
  • Features documented but not working

What to provide:

  1. WordPress version
  2. Plugin version
  3. Other active plugins
  4. Theme name and version
  5. Error messages from debug log
  6. Steps to reproduce

Theme Support

Contact theme developer when:

  • Tracking works with default theme but not with their theme
  • Theme documentation mentions analytics integration that doesn't work
  • Theme updates break previously working tracking

When to Hire a Developer

Complex scenarios requiring expert help:

  1. Custom ecommerce implementations beyond WooCommerce
  2. Advanced event tracking requiring JavaScript development
  3. Server-side tracking setup (GTM server-side)
  4. Data layer architecture for complex sites
  5. Custom WordPress plugin development for tracking
  6. GDPR-compliant tracking with complex requirements
  7. Multi-site network tracking with custom requirements
  8. Headless WordPress with separate frontend

Advanced Troubleshooting Techniques

Server-Side Debugging

Check server logs for tracking requests:

# Apache access log
tail -f /var/log/apache2/access.log | grep "gtag\|analytics"

# Nginx access log
tail -f /var/log/nginx/access.log | grep "gtag\|analytics"

Test with curl:

# Check if analytics script loads from server
curl -I https://www.google-analytics.com/analytics.js

# Should return 200 OK

Database-Level Debugging

Check plugin settings in database:

-- View all options related to analytics plugins
SELECT * FROM wp_options WHERE option_name LIKE '%analytics%';
SELECT * FROM wp_options WHERE option_name LIKE '%gtm%';
SELECT * FROM wp_options WHERE option_name LIKE '%google%';

Reset plugin settings if corrupted:

-- Backup first!
-- Delete specific plugin options
DELETE FROM wp_options WHERE option_name = 'monster_insights_settings';

Tracking Testing Workflow

Complete testing procedure:

  1. Pre-deployment testing:

    • Test on staging site
    • Verify events in GA4 DebugView
    • Check dataLayer in console
    • Test consent flow
    • Test on mobile devices
  2. Deployment verification:

    • Clear all caches
    • Test in incognito window
    • Verify events in real-time reporting
    • Check for JavaScript errors
    • Test from different locations
  3. Post-deployment monitoring:

    • Monitor real-time reports (24 hours)
    • Compare to previous data
    • Check conversion events
    • Review bounce rate and engagement
  4. Ongoing maintenance:

    • Monthly tracking audit
    • Review after plugin updates
    • Test after theme changes
    • Verify after WordPress core updates

General Fixes

For universal tracking concepts, see the Global Tracking Issues Hub.

// SYS.FOOTER