Overview
This guide helps you diagnose and resolve common Google Analytics tracking issues for both GA4 (Google Analytics 4) and Universal Analytics. Use the debugging tools and techniques below to ensure accurate data collection.
Debug Mode
GA4 Debug Mode
Enable debug mode in GA4 to see real-time event tracking:
// Enable debug mode for GA4
gtag('config', 'G-XXXXXXXXXX', {
'debug_mode': true
});
View debug events in DebugView:
- Go to Admin → DebugView
- Generate events on your site
- See events appear in real-time
GA4 Chrome Extension
Install Google Analytics Debugger Chrome extension:
- Install from Chrome Web Store
- Click extension icon to enable
- Open browser console
- See detailed GA event logs
Universal Analytics Debug
// Check if UA is loaded
if (typeof ga !== 'undefined') {
console.log('Google Analytics loaded');
ga(function(tracker) {
console.log('Tracker name:', tracker.get('name'));
console.log('Tracking ID:', tracker.get('trackingId'));
});
} else {
console.error('Google Analytics not loaded');
}
Common Issues
No Data in Reports (GA4)
Symptoms: Tracking code installed but no data appears in GA4 reports.
Solutions:
- Verify Measurement ID:
// Check your GA4 config
gtag('config', 'G-XXXXXXXXXX');
// Verify Measurement ID in Admin → Data Streams
Check data stream settings:
Use DebugView:
// Enable debug mode
gtag('config', 'G-XXXXXXXXXX', {
'debug_mode': true
});
// Check DebugView for incoming events
// Admin → DebugView
- Verify gtag.js is loaded:
// Check if gtag exists
if (typeof gtag !== 'undefined') {
console.log('gtag.js loaded successfully');
} else {
console.error('gtag.js not loaded');
}
// Check script tag exists
const gtagScript = document.querySelector('script[src*="googletagmanager.com/gtag"]');
if (gtagScript) {
console.log('gtag.js script tag found');
} else {
console.error('gtag.js script tag missing');
}
- Check network requests:
- Open DevTools → Network tab
- Filter by "google-analytics" or "collect"
- Look for requests to
google-analytics.com/g/collect - Status should be 200 or 204
Events Not Tracking (GA4)
Symptoms: Custom events aren't appearing in GA4.
Solutions:
- Verify event syntax:
// Correct GA4 event tracking
gtag('event', 'button_click', {
'event_category': 'engagement',
'event_label': 'signup_button',
'value': 1
});
// Check in DebugView within seconds
- Check event name restrictions:
- Must start with a letter
- Only letters, numbers, underscores
- Max 40 characters
- Can't use reserved names (e.g., "page_view", "session_start")
// Good event names
gtag('event', 'signup_completed');
gtag('event', 'video_played');
// Bad event names (will fail)
gtag('event', '1st_event'); // Can't start with number
gtag('event', 'sign-up'); // No hyphens allowed
gtag('event', 'very_long_event_name_that_exceeds_40_chars'); // Too long
- Verify event parameters:
// Parameters must follow naming rules
gtag('event', 'purchase', {
'currency': 'USD', // Valid
'value': 99.99, // Valid
'transaction_id': 'T123', // Valid
'items': [ // Valid
{
'item_id': 'SKU123',
'item_name': 'Product Name',
'price': 99.99,
'quantity': 1
}
]
});
- Check timing:
- Events appear in DebugView immediately
- Standard reports: 24-48 hours
- Realtime reports: Within minutes
Universal Analytics Not Working
Symptoms: UA tracking code not collecting data.
Solutions:
- Verify tracking code:
// Check if ga object exists
if (typeof ga !== 'undefined') {
console.log('✓ UA loaded');
// Get tracker info
ga(function(tracker) {
console.log('Tracking ID:', tracker.get('trackingId'));
console.log('Client ID:', tracker.get('clientId'));
});
} else {
console.error('✗ UA not loaded');
}
- Check analytics.js is loaded:
<!-- Verify script tag exists -->
<script async src="https://www.google-analytics.com/analytics.js"></script>
- Test page view tracking:
// Manual page view
ga('send', 'pageview', {
'page': '/test-page',
'title': 'Test Page'
});
- Check network requests:
- Filter Network tab by "collect"
- Look for requests to
google-analytics.com/collect - Verify
tidparameter matches your UA-XXXXXXXX-X
Google Tag Manager Issues
Symptoms: GTM container loaded but tags not firing.
Solutions:
Enable Preview Mode:
- In GTM, click "Preview"
- Navigate to your site
- GTM debug panel appears
- See which tags fire on each event
Check container loading:
// Verify GTM is loaded
if (typeof google_tag_manager !== 'undefined') {
console.log('GTM loaded');
console.log('Container IDs:', Object.keys(google_tag_manager));
} else {
console.error('GTM not loaded');
}
- Verify dataLayer:
// Check dataLayer exists
if (typeof dataLayer !== 'undefined') {
console.log('dataLayer exists');
console.log('dataLayer contents:', dataLayer);
} else {
console.error('dataLayer not defined');
}
// Push test event
dataLayer.push({
'event': 'test_event',
'eventCategory': 'test',
'eventAction': 'debug'
});
- Common GTM mistakes:
- dataLayer defined after GTM container
- Tag triggers not configured correctly
- Variables returning undefined
- Tags paused or blocked
Cross-Domain Tracking Issues
Symptoms: Sessions breaking across domains.
Solutions:
- GA4 cross-domain setup:
// Configure cross-domain tracking
gtag('config', 'G-XXXXXXXXXX', {
'linker': {
'domains': ['domain1.com', 'domain2.com']
}
});
- Universal Analytics cross-domain:
// Configure UA cross-domain
ga('create', 'UA-XXXXXXXX-X', 'auto', {
'allowLinker': true
});
ga('require', 'linker');
ga('linker:autoLink', ['domain1.com', 'domain2.com']);
Verify linker parameters:
- Check URLs for
_glparameter (GA4) - Check URLs for
_gaparameter (UA) - Links should include cross-domain parameters
- Check URLs for
Test cross-domain tracking:
// Check if linker is working
// Click link to other domain
// URL should contain: ?_gl=1*abc123*_ga*...
// In GA, filter by hostname to see both domains in same session
Ecommerce Tracking Not Working
Symptoms: Purchase or transaction data missing.
Solutions:
- GA4 ecommerce setup:
// Send purchase event
gtag('event', 'purchase', {
'transaction_id': 'T12345',
'value': 99.99,
'currency': 'USD',
'tax': 8.00,
'shipping': 5.00,
'items': [
{
'item_id': 'SKU123',
'item_name': 'Product Name',
'price': 86.99,
'quantity': 1
}
]
});
// Check in DebugView immediately
// Check Monetization reports after 24-48 hours
Verify required parameters:
transaction_id(must be unique)value(total purchase amount)currency(3-letter ISO code)itemsarray with at least one item
Check for duplicate transactions:
// Prevent duplicate purchases
let purchaseTracked = false;
function trackPurchase(data) {
if (!purchaseTracked) {
gtag('event', 'purchase', data);
purchaseTracked = true;
}
}
User-ID Not Working
Symptoms: User-ID not being set or reported.
Solutions:
- GA4 User-ID setup:
// Set User-ID
gtag('config', 'G-XXXXXXXXXX', {
'user_id': 'user_12345'
});
// Or set with event
gtag('set', 'user_properties', {
'user_id': 'user_12345'
});
- Verify User-ID is sent:
// Check in DebugView
// Look for user_id parameter in events
// Or check network requests
// Look for &uid= parameter
- Enable User-ID reporting:
- Go to Admin → Data Settings → Data Collection
- Enable "User-ID"
- Create User-ID reporting view
Debugging Tools
GA4 DebugView
// Enable for specific users
gtag('config', 'G-XXXXXXXXXX', {
'debug_mode': true
});
// Or enable based on URL parameter
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.get('debug') === 'true') {
gtag('config', 'G-XXXXXXXXXX', {
'debug_mode': true
});
}
Google Analytics Debugger Extension
Install and use:
- Install from Chrome Web Store
- Enable extension
- Open DevTools console
- See detailed GA logs
Tag Assistant Legacy
For Universal Analytics:
- Install Tag Assistant extension
- Click extension icon
- Click "Enable"
- Refresh page
- See GA tag status
Network Inspector
// Log all GA requests
function logGARequests() {
const observer = new PerformanceObserver((list) => {
list.getEntries().forEach((entry) => {
if (entry.name.includes('google-analytics.com') ||
entry.name.includes('googletagmanager.com')) {
console.log('GA Request:', entry.name);
}
});
});
observer.observe({ entryTypes: ['resource'] });
}
logGARequests();
Browser-Specific Issues
Safari ITP (Intelligent Tracking Prevention)
// GA4 uses first-party cookies, less affected
// But cookie lifetime reduced to 7 days for client-side tracking
// Consider server-side GTM for longer persistence
Ad Blockers
// Detect if GA is blocked
setTimeout(function() {
if (typeof gtag === 'undefined' || typeof ga === 'undefined') {
console.warn('Google Analytics blocked by ad blocker');
// Send to alternative analytics
if (typeof alternativeAnalytics !== 'undefined') {
alternativeAnalytics.track('ga_blocked');
}
}
}, 2000);
Content Security Policy (CSP)
<!-- Add GA domains to CSP -->
<meta http-equiv="Content-Security-Policy"
content="script-src 'self' https://www.googletagmanager.com https://www.google-analytics.com;
img-src 'self' https://www.google-analytics.com;
connect-src 'self' https://www.google-analytics.com;">
Data Quality Issues
Bot Filtering
// GA4 automatically filters known bots
// Verify bot filtering in Admin → Data Settings → Data Filters
// For additional bot detection
if (navigator.webdriver ||
/bot|crawler|spider/i.test(navigator.userAgent)) {
console.log('Bot detected - tracking may be skipped');
}
Referrer Spam
// GA4 has built-in spam filtering
// For UA, create filter in Admin → View → Filters
// Filter Type: Custom → Exclude
// Filter Field: Campaign Source
// Filter Pattern: spam-domain\.com
Data Import Issues
// Verify data import schema matches
// Check Admin → Data Import
// Review import status for errors
// Ensure primary key matches
Getting Help
Check GA Status
Visit Google Analytics Status Dashboard to check for service interruptions.
Diagnostic Report
// Create comprehensive diagnostic report
function gaHealthCheck() {
console.group('GA Health Check');
// Check GA4
if (typeof gtag !== 'undefined') {
console.log('✓ GA4 gtag.js loaded');
} else {
console.error('✗ GA4 gtag.js not loaded');
}
// Check UA
if (typeof ga !== 'undefined') {
console.log('✓ UA analytics.js loaded');
ga(function(tracker) {
console.log('Tracking ID:', tracker.get('trackingId'));
console.log('Client ID:', tracker.get('clientId'));
});
} else {
console.warn('○ UA not detected (may be GA4 only)');
}
// Check GTM
if (typeof dataLayer !== 'undefined') {
console.log('✓ GTM dataLayer exists');
console.log('dataLayer events:', dataLayer.length);
} else {
console.warn('○ GTM not detected');
}
console.groupEnd();
}
gaHealthCheck();
Google Analytics Help
Google Analytics Help Center:
- support.google.com/analytics
- Comprehensive documentation
- Video tutorials
Google Analytics Community:
- Ask questions
- Search existing solutions
- Connect with experts
Google Support:
- For Analytics 360 customers
- Direct support available
- Priority assistance
Best Practices
Regular Monitoring
// Create monitoring function
function monitorGA() {
setInterval(function() {
if (typeof gtag === 'undefined' && typeof ga === 'undefined') {
console.error('Google Analytics not detected');
// Alert your monitoring service
}
}, 30000); // Check every 30 seconds
}
monitorGA();
Error Tracking
// Log GA errors
window.addEventListener('error', function(e) {
if (e.message.includes('gtag') ||
e.message.includes('analytics') ||
(e.filename && (e.filename.includes('gtag') || e.filename.includes('analytics')))) {
console.error('GA Error:', e);
// Send to error tracking service
}
});
Testing Checklist
- Page views tracking correctly
- Custom events firing
- Ecommerce events sending
- User-ID being set (if applicable)
- Cross-domain tracking working (if applicable)
- All required parameters included
- Data appearing in reports within expected timeframe
- No console errors related to GA
- Network requests successful (200/204 status)