This guide covers the implementation and detection of popular analytics tools on WordPress sites, including Google Analytics and Matomo.
Analytics tools help track website performance, user behavior, and conversion metrics. The most common solutions for WordPress are:
- Google Analytics (via Google Site Kit plugin or manual implementation)
- Matomo (via official Matomo plugin or manual implementation)
The recommended approach for Google Analytics on WordPress is using the official Google Site Kit plugin.
Installation:
- Install the "Site Kit by Google" plugin from WordPress repository
- Activate and connect to your Google account
- Configure Google Analytics through the Site Kit dashboard
Features:
- Automatic tracking code implementation
- Dashboard integration within WordPress admin
- Multiple Google services integration (Analytics, Search Console, AdSense, etc.)
- Automatic updates and maintenance
For advanced users who need custom tracking configurations:
- Create a Google Analytics account and property
- Get your Measurement ID (GA4) or Tracking ID (Universal Analytics)
- Add tracking code to your theme's header or use a plugin like "Insert Headers and Footers"
The official Matomo plugin provides easy integration:
Installation:
- Install "Matomo Analytics - Ethical Stats" plugin
- Choose between Matomo Cloud or self-hosted installation
- Configure tracking settings in the plugin dashboard
Features:
- Privacy-focused analytics (GDPR compliant by default)
- Self-hosted option for complete data ownership
- Real-time analytics
- No data sampling
- Integrated heatmaps and session recordings
For self-hosted Matomo installations:
- Set up Matomo on your server
- Get your site ID and tracking code
- Add the JavaScript tracking code to your theme
You can check if analytics tools are properly implemented on any WordPress site using curl commands.
Check for Site Kit meta tags and configuration:
# Check for Site Kit meta tags and setup
curl -sL https://example.com | grep -E 'googlesitekit|gtagconfig'
# Expected output example:
# <meta name="googlesitekit-setup" content="abc123-def4-567g-8hij-klmnopqrstuv" />
# <meta name="generator" content="Site Kit by Google 1.150.0" />Check for Google Analytics tracking code implementation:
# Check for Google Analytics tracking code
curl -sL https://example.com | grep -E 'gtag\(|googletagmanager|analytics\.js|GA_MEASUREMENT_ID'
# Check for DNS prefetch (performance optimization)
curl -sL https://example.com | grep -E 'dns-prefetch.*googletagmanager'
# Expected output example:
# <link rel='dns-prefetch' href='//www.googletagmanager.com' />Check specifically for Google Tag Manager implementation:
# Check for GTM container
curl -sL https://example.com | grep -E 'googletagmanager\.com/gtm\.js\?id=GTM-'
# Expected output example:
# <script src="https://www.googletagmanager.com/gtm.js?id=GTM-XXXXXXX"></script>Check for Matomo tracking implementation:
# Check for Matomo tracking code (self-hosted)
curl -sL https://example.com | grep -E 'matomo\.js|piwik\.js|_paq\.push'
# Check for Matomo Cloud
curl -sL https://example.com | grep -E 'cdn\.matomo\.cloud'
# Check for Matomo tracking pixel
curl -sL https://example.com | grep -E 'matomo\.php\?|piwik\.php\?'
# Expected output examples:
# <script src="https://analytics.example.com/matomo.js"></script>
# var _paq = window._paq = window._paq || [];
# <script src="https://cdn.matomo.cloud/example.matomo.cloud/matomo.js"></script>Here's a comprehensive bash script to check for all analytics implementations:
#!/bin/bash
DOMAIN="example.com"
echo "=== Analytics Detection for $DOMAIN ==="
echo
echo "1. Checking for Google Site Kit..."
curl -sL https://$DOMAIN | grep -E 'googlesitekit|Site Kit by Google' | head -3
echo
echo "2. Checking for Google Analytics..."
curl -sL https://$DOMAIN | grep -E 'gtag\(|googletagmanager|GA_MEASUREMENT_ID' | head -3
echo
echo "3. Checking for Google Tag Manager..."
curl -sL https://$DOMAIN | grep -E 'googletagmanager\.com/gtm\.js\?id=GTM-' | head -3
echo
echo "4. Checking for Matomo..."
curl -sL https://$DOMAIN | grep -E 'matomo\.js|piwik\.js|_paq\.push|cdn\.matomo\.cloud' | head -3
echo
echo "5. Checking for other analytics..."
curl -sL https://$DOMAIN | grep -E 'facebook\.net/.*fbevents|hotjar\.com|segment\.com' | head -3- Always implement cookie consent mechanisms
- Consider privacy-focused alternatives like Matomo
- Anonymize IP addresses where required
- Provide clear privacy policies
- Use DNS prefetching for external analytics scripts
- Implement analytics tracking asynchronously
- Consider server-side tracking for critical metrics
- Use plugins for easier management and updates
- Test analytics implementation in staging environments
- Monitor for plugin conflicts
- Regular audits of tracking accuracy
- Tracking code not firing: Check for JavaScript errors and plugin conflicts
- Duplicate tracking: Ensure only one implementation method is active
- Missing data: Verify tracking ID/Measurement ID configuration
- Plugin conflicts: Disable other analytics plugins when testing
- Google Analytics Debugger (Chrome extension)
- Google Tag Assistant
- Browser developer tools (Network tab)
- WordPress debug logs
- Site Kit by Google (Official Google plugin)
- MonsterInsights (Popular third-party option)
- GA Google Analytics (Lightweight option)
- Matomo Analytics (Official Matomo plugin)
- WP-Matomo (Alternative implementation)
- Keep analytics plugins updated
- Use HTTPS for all tracking requests
- Implement Content Security Policy headers
- Regular security audits of third-party scripts
- Consider self-hosted solutions for sensitive data
Last updated: [Current Date] For more WordPress tools and utilities, check the other directories in this repository.