How to Install Analytics on WordPress (the Clean Way)
WordPress sites are bloated. You know the feeling—your theme came with 12 megabytes of functions.php, you've got plugins for SEO, plugins for caching, plugins for analytics. Each one adds another layer of JavaScript, another database query, another thing to maintain. But analytics doesn't need to be part of that bloat.
Most WordPress sites use Google Analytics or Jetpack, both of which send your visitor data to third-party servers and add unnecessary overhead. The good news: you can drop a single 2 KB script into your WordPress header and get everything you need—without the plugin tax.
This guide shows you exactly how to add a lightweight, privacy-first analytics tracker to WordPress in under 5 minutes, exclude admin traffic automatically, and verify it's working.
Why Not Use an All-in-One SEO Plugin?
WordPress SEO plugins like Yoast and Rank Math have analytics features, but they come with a cost:
Plugin bloat. Yoast adds ~600 KB of JavaScript to every page. Rank Math adds meta boxes to every post and custom post type. These plugins are designed to do everything—SEO, readability, keyword research, analytics—but they do most of it poorly because they're trying to do too much.
Tracking overfeatures. Built-in analytics usually show visitor counts and page views. That's it. No conversion tracking, no funnel analysis, no traffic source attribution. You're paying the performance cost for features you can't use.
Admin UI bloat. Every page edit screen gets crowded with plugin panels and settings. It's distracting and doesn't improve your content.
Privacy concerns. These plugins often phone home to their own servers, even when showing analytics in your dashboard. Yoast sends data to Yoast's cloud; Rank Math sends data to Rank Math's cloud. If GDPR or privacy is a concern, you're outsourcing your data.
The better approach? Use a single lightweight tracker that sits on your site, collects data locally, and sends only what you need.
The Clean Approach: One Snippet
The entire WordPress analytics pipeline can be one script tag:
<script defer src="https://cdn.statalog.com/tracker.min.js"></script>
<script>
window.statalogConfig = {
siteId: 'YOUR_SITE_ID',
hashMode: false
};
</script>
That's 2 KB of JavaScript. It loads asynchronously (defer), so it doesn't block page rendering. It doesn't interfere with other plugins. And it gives you full analytics—traffic, sources, pages, goals, funnels—without the overhead.
Step-by-Step: Add the Tracker to WordPress
Method 1: Edit Theme Header (Easiest)
- Log in to WordPress admin
- Go to Appearance → Theme File Editor (or Appearance → Customize → Additional CSS if Theme File Editor is disabled)
- Find
header.phpin the file list on the right - Scroll to the closing
</head>tag - Add this code just before
</head>:
<!-- Analytics Tracker -->
<script defer src="https://cdn.statalog.com/tracker.min.js"></script>
<script>
window.statalogConfig = {
siteId: 'YOUR_SITE_ID',
hashMode: false
};
</script>
- Click Update File
- Test your site to ensure it loads normally
Note: Replace YOUR_SITE_ID with your actual Statalog site ID (found in Settings → Install Code).
Method 2: Child Theme (Recommended for Updates)
If your theme updates regularly, editing header.php directly means your changes will be overwritten on the next update. Use a child theme instead:
- Create a folder:
/wp-content/themes/your-theme-child/ - Add
style.css:
/*
Theme Name: Your Theme Child
Template: your-theme
Version: 1.0
*/
- Create
functions.php:
<?php
// Enqueue parent theme stylesheet
add_action( 'wp_enqueue_scripts', 'child_theme_enqueue_styles' );
function child_theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
// Add analytics tracker
add_action( 'wp_head', 'add_statalog_tracker' );
function add_statalog_tracker() {
?>
<script defer src="https://cdn.statalog.com/tracker.min.js"></script>
<script>
window.statalogConfig = {
siteId: 'YOUR_SITE_ID',
hashMode: false
};
</script>
<?php
}
?>
- Activate the child theme in Appearance → Themes
This way, when your parent theme updates, your analytics code stays intact.
Method 3: Using a Code Snippets Plugin (No Theme Editing)
If you're uncomfortable editing theme files, you can use a code snippets plugin like Code Snippets or WPCode:
- Install and activate Code Snippets
- Go to Snippets → Add New
- Paste this:
<?php
add_action( 'wp_head', 'add_statalog_tracker' );
function add_statalog_tracker() {
?>
<script defer src="https://cdn.statalog.com/tracker.min.js"></script>
<script>
window.statalogConfig = {
siteId: 'YOUR_SITE_ID',
hashMode: false
};
</script>
<?php
}
?>
- Click Save Changes & Activate
This approach doesn't touch your theme files at all—the snippet is stored in the database.
Exclude Admin Traffic
By default, the tracker collects data on every visitor—including you and other admins. To exclude logged-in WordPress users, add a check before the tracker loads:
<?php
add_action( 'wp_head', 'add_statalog_tracker' );
function add_statalog_tracker() {
// Don't track logged-in users
if ( is_user_logged_in() ) {
return;
}
?>
<script defer src="https://cdn.statalog.com/tracker.min.js"></script>
<script>
window.statalogConfig = {
siteId: 'YOUR_SITE_ID',
hashMode: false
};
</script>
<?php
}
?>
Now when you're logged in, your traffic won't be counted. This keeps your analytics clean and focused on actual visitor behavior.
Exclude Bots
Good news: bot exclusion is built-in. The Statalog tracker automatically filters out:
- Googlebot and Google crawlers
- Bingbot
- Facebook and Twitter crawlers
- Common user-agent strings for bots
You don't need to configure anything. Bots are excluded by default.
Verify It's Working
Open your WordPress site in an incognito window (not logged in):
- Right-click → Inspect → Network tab
- Reload the page
- Look for a request to
statalog.com/collect(or your custom domain) - Open that request and check the Preview tab—you should see event data
You'll see something like:
{
"name": "pageview",
"url": "https://yoursite.com/blog/post",
"referrer": "https://google.com/search?q=...",
"viewport_width": 1920,
"session_id": "abc123xyz"
}
If you see that request, your tracker is working. If you don't, double-check that:
- The script tag is in
<head>(not after</body>) - Your site ID is correct
- There are no JavaScript errors in the console
Performance Impact
The Statalog tracker is designed to be fast:
- Script size: 2 KB gzipped
- Loading: Loads with
defer, doesn't block page rendering - Network: One request per page view (batched if you configure it)
- CPU: Minimal—just sends a POST request asynchronously
Real-world impact on your site speed: < 1 millisecond added to page load time. Your WordPress site's database queries will have far more impact than the analytics tracker.
Compatibility
The tracker works with:
- All WordPress themes (custom, Divi, Elementor, GeneratePress, etc.)
- All WordPress versions (4.9+)
- No plugin conflicts—it's just a script tag, not a plugin
It also works alongside Google Analytics if you want to keep it (though we'd recommend replacing it to reduce bloat).
If You Use a Page Builder
If you build with Elementor, Divi, or Beaver Builder, you can add the tracker without touching theme files:
Elementor
- Go to Elementor → Settings → Integrations
- Paste your tracker script in the Header Code field:
<script defer src="https://cdn.statalog.com/tracker.min.js"></script>
<script>
window.statalogConfig = {
siteId: 'YOUR_SITE_ID',
hashMode: false
};
</script>
Divi
- Go to Divi → Theme Options → Integration
- Paste your tracker code in the Head section
Beaver Builder
- Go to Beaver Builder → Settings → Code
- Paste your tracker code in the Header Code field
All page builders have a code injection section specifically for this purpose.
Removing Existing Analytics Code
If you already have Google Analytics or another tracker installed, you should remove it to avoid duplicate data:
Remove Google Analytics
Go to Appearance → Theme File Editor, find header.php, and delete this line:
<!-- Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'GA_ID');
</script>
Remove Jetpack Analytics
Jetpack stores its code in the database, so go to Jetpack → Settings and toggle off Site Analytics.
Remove Other Trackers
Search your theme's header.php for:
google-analyticsgoogletagmanagerfacebook.com/en_US/sdk.js(if you're tracking Facebook pixels)gtag.js
Delete any of these if they're not needed.
FAQ
Q: Will this conflict with my other plugins?
A: No. The Statalog tracker is a script tag, not a plugin. It doesn't interact with plugin code or WordPress hooks in any way that would cause conflicts.
Q: Can I track WooCommerce orders and revenue?
A: Yes. You can send conversion goals to Statalog. Paste this in your WooCommerce order confirmation page or add it to a code snippet:
statalogTracker.goal('purchase', {
revenue: order_total,
currency: 'USD'
});
Q: Is the admin exclusion actually working?
A: Yes. When you're logged in, the tracker's is_user_logged_in() check will prevent the script from loading at all. You can verify this by:
- Logging out
- Reloading your site
- Checking the Network tab for the
/collectrequest
When you log back in, the request will disappear.
Q: Can I use this on multisite WordPress?
A: Yes. If you have a WordPress multisite, add the tracker to each site individually, or use a must-use plugin (/wp-content/mu-plugins/statalog.php) to apply it sitewide.
Q: What if my host disabled Theme File Editor?
A: Use the child theme method (Method 2) or a code snippets plugin (Method 3) instead. These don't require Theme File Editor access.
Next Steps
- Install the tracker using one of the methods above
- Set up conversion goals to track important actions (sign-ups, purchases, downloads)
- Create funnels to see where visitors drop off
- Check your dashboard in 30 minutes to see real data flowing in
Your WordPress analytics are now lightweight, private, and privacy-friendly. No bloat, no third-party trackers, no plugin maintenance. Just data.
Previous article
How to Install Analytics on Shopify, Webflow, Framer & GhostNext article
Cookies Are Dead. Here's What Replaces Them.