Troubleshooting Website Traffic Tracking

This comprehensive troubleshooting guide helps you diagnose and fix common issues with Alpha Insights website traffic tracking. Follow the diagnostic steps for your specific problem to quickly identify and resolve issues.

General troubleshooting: For general Alpha Insights troubleshooting, see Troubleshooting Performance. This guide focuses specifically on website traffic tracking issues.

Quick Diagnostic Checklist

Before diving into specific issues, run through this quick checklist:

Issue 1: No Traffic Data Showing

Symptom

Reports show zero sessions, zero page views, or "No data available"

Quick reference: For understanding how tracking works, see the Technical Architecture guide.

Possible Causes & Solutions

1. Analytics is disabled

Check:

Settings → General Settings → Alpha Analytics & Event Tracking
Verify "Enable Woocommerce Event Tracking" = True

Solution: Enable tracking and wait a few minutes for data to appear

2. You're excluded from tracking

Check:

Settings → General Settings → "Exclude These Roles From Tracking"
Verify your user role is NOT in the exclusion list

Solution:

3. Date range is incorrect

Check: Report date range in date picker

Solution:

4. No actual traffic yet

Check: Realtime Dashboard for live activity

Solution:

5. JavaScript not loading

Check: Browser developer tools (F12) → Network tab → look for wpd-alpha-insights-event-tracking.js

Solution:

6. Database tables missing

Check: Via phpMyAdmin or WP-CLI

// Check if tables exist
SHOW TABLES LIKE 'wp_wpd_ai_%';

// Should show:
// wp_wpd_ai_session_data
// wp_wpd_ai_events

Solution:

Issue 2: Sessions Not Being Created

Symptom

Events might be tracked, but no sessions appear in reports

Diagnostic Steps

1. Check database directly

SELECT * FROM wp_wpd_ai_session_data 
WHERE date_created_gmt > DATE_SUB(NOW(), INTERVAL 1 HOUR)
ORDER BY date_created_gmt DESC
LIMIT 10;

If no results: Sessions not being created at all

2. Check if cookies are set

If cookies missing:

3. Check for bot detection false positive

// Test if you're being flagged as a bot
// Add this temporarily to your theme's functions.php
add_action('template_redirect', function() {
  $user_agent = new WPDAI_User_Agent_Classification();
  if ($user_agent->isBot()) {
    error_log('Bot detected: ' . $_SERVER['HTTP_USER_AGENT']);
  }
});

If you're flagged as bot:

4. Check PHP errors

// Enable WordPress debug logging
// In wp-config.php (temporarily):
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

// Then check: wp-content/debug.log for errors

Issue 3: Events Not Being Tracked

Symptom

Sessions exist but specific events (page views, add to cart, etc.) are missing

Diagnostic Steps

1. Check REST API endpoint

// Test API endpoint manually
// Open browser console and run:
fetch('/wp-json/alpha-insights/v1/woocommerce-events', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Referer': window.location.href
  },
  body: JSON.stringify({
    event_type: 'test_event',
    page_href: window.location.href
  })
})
.then(r => r.json())
.then(data => console.log('API Response:', data))
.catch(err => console.error('API Error:', err));

Expected response: {"message": "1 rows were inserted into the db."}

If error 403: Referer validation failing (check if domain matches)

If error 404: REST API not working (check permalink settings)

If error 429: Rate limit exceeded (wait 60 seconds)

2. Check JavaScript console for errors

Common JavaScript errors:

3. Check Network tab for API calls

If no API calls: JavaScript not firing events

If API calls failing: Check response status and error message

4. Check for rate limiting

// Check if your IP is rate limited
// Run in WordPress admin or via WP-CLI:
$ip = '192.168.1.100'; // Your IP
$transient_key = 'wpd_ai_rate_limit_' . md5($ip);
$count = get_transient($transient_key);
echo "Request count: " . $count . " / 60";

// Check if banned
$ban_key = 'wpd_ai_ip_banned_' . md5($ip);
$banned = get_transient($ban_key);
echo "Banned: " . ($banned ? 'Yes' : 'No');

If rate limited: Wait 60 seconds

If banned: Wait 24 hours or delete transient manually

Issue 4: Orders Not Attributed to Traffic Sources

Symptom

Orders show in WooCommerce but landing page/referrer not saved to order meta

Diagnostic Steps

1. Check if landing page cookie exists at time of order

If cookie missing or expires:

2. Check order meta after purchase

// Query order meta in database
SELECT meta_key, meta_value 
FROM wp_postmeta 
WHERE post_id = [ORDER_ID]
AND meta_key LIKE '_wpd_ai%';

// Should show:
// _wpd_ai_landing_page
// _wpd_ai_referral_source
// _wpd_ai_meta_campaign_id (if present)
// _wpd_ai_google_campaign_id (if present)

If meta fields missing:

3. Check if hook is firing

// Add debugging temporarily
add_action('woocommerce_checkout_order_processed', function($order_id) {
  error_log('Order processed: ' . $order_id);
  error_log('Landing page cookie: ' . $_COOKIE['wpd_ai_landing_page'] ?? 'NOT SET');
}, 5); // Priority 5 (before Alpha Insights)

4. Test with fresh browser session

Issue 5: UTM Parameters Not Showing in Reports

Symptom

UTM-tagged URLs used, but campaigns don't appear in Traffic Channels report

Quick reference: For UTM best practices, see the UTM Campaign Tracking guide.

Diagnostic Steps

1. Verify UTM parameters in URL

If parameters missing:

2. Check landing page cookie value

If UTMs not in cookie:

3. Check database for UTM data

// Check session landing pages
SELECT landing_page 
FROM wp_wpd_ai_session_data 
WHERE landing_page LIKE '%utm_campaign%'
ORDER BY date_created_gmt DESC 
LIMIT 10;

If UTMs not in database:

4. Check report date range

5. Check for typos in UTM parameters

Issue 6: Traffic Source Showing as "Unknown" or Incorrect

Symptom

Traffic categorized incorrectly (e.g., Facebook showing as "Unknown" instead of "Social")

Quick reference: For complete traffic source detection logic, see the Traffic Source Analysis guide.

Diagnostic Steps

1. Check referrer URL

// Query database to see actual referrer
SELECT referral_url, landing_page
FROM wp_wpd_ai_session_data
WHERE date_created_gmt > DATE_SUB(NOW(), INTERVAL 1 HOUR)
ORDER BY date_created_gmt DESC
LIMIT 20;

Common issues:

2. Social platforms strip referrers

Problem: Facebook, Instagram, TikTok often don't send referrer for privacy

Solution: Always use UTM parameters for social posts

// Instead of: https://yourstore.com/products
// Use: https://yourstore.com/products?utm_source=facebook&utm_medium=social

3. Check traffic source classification logic

// Test traffic source detection
$traffic_type = new WPDAI_Traffic_Type_Detection($referral_url, $query_params);
$source = $traffic_type->determine_traffic_source();
echo "Traffic source: " . $source;

4. Add custom source detection

// If platform not recognized, add via filter
add_filter('wpd_traffic_source', function($source, $referral_url, $query_params) {
  if (strpos($referral_url, 'custom-platform.com') !== false) {
    return 'Custom Platform';
  }
  return $source;
}, 10, 3);

Issue 7: Data Appears Delayed or Missing

Symptom

Traffic happened hours ago but not yet in reports

Explanation

Expected behavior:

Solutions

1. Check Realtime Dashboard first

2. Clear transient cache

// Delete all report caches
DELETE FROM wp_options 
WHERE option_name LIKE '_transient_wpd_%'
OR option_name LIKE '_transient_timeout_wpd_%';

3. Check if data actually exists

// Count today's sessions
SELECT COUNT(*) as sessions_today
FROM wp_wpd_ai_session_data
WHERE DATE(date_created_gmt) = CURDATE();

// Count today's events
SELECT COUNT(*) as events_today
FROM wp_wpd_ai_events
WHERE DATE(date_created_gmt) = CURDATE();

Issue 8: Page Views Not Tracking

Symptom

Sessions are created but page_view events missing or low count

Diagnostic Steps

1. Check if page view event is firing

2. Check jQuery dependency

If jQuery missing:

3. Check if document.ready is firing

// Add to browser console
jQuery(document).ready(function() {
  console.log('Document ready fired');
  console.log('WpdAiEventTracking:', typeof WpdAiEventTracking);
  console.log('Localized data:', wpdAlphaInsightsEventTracking);
});

4. Check for JavaScript conflicts

Issue 9: Add to Cart Events Missing

Symptom

Products being added to cart but add_to_cart events not recorded

Explanation

Add to cart is tracked server-side via woocommerce_add_to_cart hook for maximum reliability.

Diagnostic Steps

1. Verify add to cart actually works

2. Check if hook is firing

// Add debugging temporarily
add_action('woocommerce_add_to_cart', function($cart_item_key, $product_id, $quantity) {
  error_log('Add to cart fired - Product: ' . $product_id . ', Qty: ' . $quantity);
}, 5, 3); // Priority 5 (before Alpha Insights at 10)

3. Check event in database

SELECT * FROM wp_wpd_ai_events
WHERE event_type = 'add_to_cart'
AND date_created_gmt > DATE_SUB(NOW(), INTERVAL 1 HOUR)
ORDER BY date_created_gmt DESC;

4. Check if session exists

Add to cart requires active session (with cookie)

Issue 10: High "Direct" Traffic (Seems Wrong)

Symptom

Most traffic showing as "Direct" even though you know it comes from other sources

Explanation

"Direct" traffic includes:

Solutions

1. Use UTM parameters everywhere

2. Enable auto-tagging for ads

3. Check for HTTPS issues

4. Accept some "Direct" is legitimate

Advanced Debugging Tools

Enable Debug Logging

// In wp-config.php
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

// Logs will be written to: wp-content/debug.log

Test REST API Directly

// Via command line (curl)
curl -X POST https://yoursite.com/wp-json/alpha-insights/v1/woocommerce-events \
  -H "Content-Type: application/json" \
  -H "Referer: https://yoursite.com" \
  -d '{
    "event_type": "test_event",
    "page_href": "https://yoursite.com/test",
    "event_quantity": 1,
    "event_value": 0
  }'

Check Database Directly

// Recent sessions
SELECT * FROM wp_wpd_ai_session_data 
ORDER BY date_created_gmt DESC LIMIT 10;

// Recent events
SELECT * FROM wp_wpd_ai_events 
ORDER BY date_created_gmt DESC LIMIT 10;

// Event counts by type
SELECT event_type, COUNT(*) as count
FROM wp_wpd_ai_events
WHERE date_created_gmt > DATE_SUB(NOW(), INTERVAL 24 HOUR)
GROUP BY event_type;

Check PHP Error Logs

Location varies by server:

Performance Issues

Issue: Tracking Slowing Down Site

For general performance optimization, see Optimizing Report Performance and Troubleshooting Performance.

Symptoms:

Diagnostic:

// Check database table sizes
SELECT 
  table_name,
  ROUND((data_length + index_length) / 1024 / 1024, 2) as size_mb,
  table_rows
FROM information_schema.tables
WHERE table_schema = DATABASE()
AND table_name LIKE 'wp_wpd_ai_%';

Solutions:

  1. Archive old data:
    // Delete sessions older than 1 year
    DELETE FROM wp_wpd_ai_session_data
    WHERE date_created_gmt < DATE_SUB(NOW(), INTERVAL 365 DAY);
  2. Optimize tables:
    OPTIMIZE TABLE wp_wpd_ai_session_data;
    OPTIMIZE TABLE wp_wpd_ai_events;
  3. Add indexes (if missing):
    ALTER TABLE wp_wpd_ai_events ADD INDEX idx_event_type (event_type);
    ALTER TABLE wp_wpd_ai_events ADD INDEX idx_session_id (session_id);
    ALTER TABLE wp_wpd_ai_events ADD INDEX idx_date (date_created_gmt);
  4. Reduce tracking frequency:

Getting Help

Before contacting support, gather:

Support checklist:

Common Misunderstandings

1. "Why doesn't my old data appear?"

2. "Why do I have multiple sessions for same visitor?"

3. "Why is my traffic not showing even though Google Analytics shows visitors?"

4. "Why does order show different source than I expected?"

Related Documentation