Add Google Analytics (or Tracking Codes) via SEOvault AI
SEOVault AI includes built-in Google Analytics integration, allowing you to add tracking codes to your site without additional plugins. This guide covers GA4 setup and custom tracking code options.
Tracking methods
Section titled “Tracking methods”SEOVault AI supports two tracking methods:
gtag.js (Google Analytics 4)
Section titled “gtag.js (Google Analytics 4)”The recommended method for Google Analytics 4. Uses the official gtag.js library from Google Tag Manager.
Features:
- Official Google Analytics 4 implementation
- Automatic pageview tracking
- Event tracking support
- IP anonymization option
- Measurement ID configuration
Custom tracking code
Section titled “Custom tracking code”For custom tracking implementations or other analytics services.
Features:
- Full control over tracking code
- Support for any analytics service
- Raw JavaScript output
- No library restrictions
Enable tracking
Section titled “Enable tracking”Tracking is disabled by default. Enable it to start collecting analytics data.
To enable:
- Go to SEOvault AI > Analytics
- Check Enable Analytics Tracking
- Click Save Changes
Configure gtag.js tracking
Section titled “Configure gtag.js tracking”Measurement ID
Section titled “Measurement ID”Your GA4 Measurement ID (e.g., G-XXXXXXXXXX).
To find your Measurement ID:
- Go to Google Analytics
- Select your property
- Go to Admin > Data Streams
- Select your data stream
- Copy the Measurement ID
To configure:
- Go to SEOvault AI > Analytics
- Select gtag as the tracking method
- Enter your Measurement ID
- Click Save Changes
IP anonymization
Section titled “IP anonymization”Anonymize IP addresses sent to Google Analytics for privacy compliance.
To enable:
- Go to SEOvault AI > Analytics
- Check Anonymize IP Addresses
- Click Save Changes
This adds the anonymize_ip parameter to the gtag config.
Track logged-in users
Section titled “Track logged-in users”By default, tracking is disabled for logged-in users to exclude your own activity from analytics.
To track logged-in users:
- Go to SEOvault AI > Analytics
- Check Track Logged-in Users
- Click Save Changes
This is useful for:
- Testing tracking on your own account
- Monitoring admin activity
- Sites with user-generated content
Configure custom tracking code
Section titled “Configure custom tracking code”Use custom tracking code for:
- Other analytics services (Matomo, Plausible, etc.)
- Custom Google Analytics implementations
- Tag manager containers
- Advanced tracking configurations
To configure:
- Go to SEOvault AI > Analytics
- Select custom as the tracking method
- Paste your tracking code in the text area
- Click Save Changes
Example custom code:
// Matomo Analytics examplevar _paq = window._paq = window._paq || [];_paq.push(['trackPageView']);_paq.push(['enableLinkTracking']);(function() { var u="https://analytics.example.com/"; _paq.push(['setTrackerUrl', u+'matomo.php']); _paq.push(['setSiteId', '1']); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);})();Tracking code output
Section titled “Tracking code output”The tracking code is automatically injected into your site’s <head> section:
- Output location:
wp_headhook (priority 99) - Output condition: Only when tracking is enabled
- Logged-in user exclusion: Respects the “Track Logged-in Users” setting
- No output on: admin pages, feeds, embeds, previews
gtag.js output example
Section titled “gtag.js output example”<!-- Analytics Tracking --><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', {"anonymize_ip":true});</script><!-- /Analytics Tracking -->Privacy considerations
Section titled “Privacy considerations”IP anonymization
Section titled “IP anonymization”Enable IP anonymization to comply with privacy regulations like GDPR:
- Masks the last octet of IPv4 addresses
- Masks the last 80 bits of IPv6 addresses
- Recommended for EU-based sites
- Does not affect analytics accuracy significantly
Logged-in user exclusion
Section titled “Logged-in user exclusion”By default, logged-in users are not tracked to:
- Exclude your own activity from analytics
- Prevent skewing of data
- Maintain privacy for logged-in users
- Focus on visitor behavior
Data retention
Section titled “Data retention”Google Analytics data retention is managed in your Google Analytics account, not in the plugin. Configure data retention settings in Google Analytics Admin.
Verification
Section titled “Verification”Verify tracking is working
Section titled “Verify tracking is working”Using Google Analytics:
- Go to your Google Analytics property
- Go to Realtime > Overview
- Visit your site in a new browser or incognito window
- Verify your visit appears in the Realtime report
Using browser tools:
- Open your site in a browser
- Open Developer Tools (F12)
- Go to the Network tab
- Reload the page
- Look for requests to
google-analytics.comorgoogletagmanager.com
Check source code
Section titled “Check source code”View your page source to verify the tracking code is present:
- Right-click on your page
- Select View Page Source
- Search for “Analytics Tracking” or “gtag”
- Verify the code is present in the
<head>section
Troubleshooting
Section titled “Troubleshooting”Tracking code not appearing
Section titled “Tracking code not appearing”If the tracking code is not in your page source:
- Verify tracking is enabled in settings
- Check that you’re not logged in (if “Track Logged-in Users” is disabled)
- Clear your cache if using a caching plugin
- Check for conflicts with other analytics plugins
- Verify the Measurement ID is correctly entered
No data in Google Analytics
Section titled “No data in Google Analytics”If no data appears in Google Analytics:
- Verify the Measurement ID is correct
- Check that the property is receiving data in Realtime
- Verify your site is not blocking Google Analytics
- Check browser extensions that might block tracking
- Verify the tracking code is present in page source
Tracking logged-in users not working
Section titled “Tracking logged-in users not working”If logged-in users are being tracked when they shouldn’t be:
- Verify “Track Logged-in Users” is unchecked
- Clear your cache
- Log out and log back in
- Check for other analytics plugins that might be tracking
Custom code not executing
Section titled “Custom code not executing”If custom tracking code is not working:
- Verify the code is valid JavaScript
- Check for syntax errors
- Test the code in browser console
- Verify the tracking method is set to “custom”
- Check browser console for JavaScript errors
Best practices
Section titled “Best practices”Use GA4 for new implementations
Section titled “Use GA4 for new implementations”Google Analytics 4 (GA4) is the current standard:
- Future-proof tracking
- Enhanced measurement features
- Better cross-platform tracking
- Improved privacy controls
Test tracking setup
Section titled “Test tracking setup”After configuring tracking:
- Test with Realtime reports
- Verify events are tracked
- Check conversion tracking
- Monitor data for 24-48 hours
Exclude internal traffic
Section titled “Exclude internal traffic”Use filters in Google Analytics to exclude:
- Your office IP address
- Your home IP address
- Development environments
- Staging sites
Document your setup
Section titled “Document your setup”Keep records of:
- Measurement ID
- Custom events configured
- Filters applied
- Goals and conversions
Migration from Universal Analytics
Section titled “Migration from Universal Analytics”If migrating from Universal Analytics (UA):
- Create a GA4 property in Google Analytics
- Set up the GA4 Measurement ID in SEOvault AI
- Run both UA and GA4 in parallel during migration
- Update any custom event tracking to GA4 format
- Disable UA tracking after migration is complete