1.96 KB WordPress analytics with zero database bloat or cookie walls.
Skip heavy local WP analytics plugins that slow down MySQL and heavy GA4 tags that drag down LCP. Drop one deferred script in wp_head for real-time EU-hosted analytics.


How do you add lightweight, cookie-less analytics to WordPress without slowing down your site?
Add TrimStats to WordPress by printing a single deferred 1.96 KB gzipped script tag via the wp_head action hook or your header code plugin. Unlike database-heavy WordPress analytics plugins or 40 KB GA4 tags, TrimStats stores zero rows in WordPress MySQL, writes zero cookies in default mode, and offloads queries to ClickHouse in Germany.
Step-by-step setup for WordPress
Copy-paste implementation verified against the live TrimStats tracker and collector APIs.
- 1
Enqueue the TrimStats script via wp_head in your child theme
Add a small wp_head hook in your child theme functions.php (or paste the <script> tag into a header snippets plugin such as WPCode). Exclude logged-in administrators automatically with is_user_logged_in().
functions.phpphp1<?php2add_action('wp_head', function () {3 if (is_user_logged_in() && current_user_can('manage_options')) {4 return;5 }6 echo '<script defer src="https://collect.trimstats.com/t.js" data-site="pk_live_your_key"></script>' . "\n";7}, 1);Excludes logged-in WordPress admins and preserves data-site cleanly. - 2
Prevent caching plugins from stripping data-site attributes
If you run WP Rocket, LiteSpeed Cache, Autoptimize, or Cloudflare Rocket Loader, exclude collect.trimstats.com/t.js from JS combine/delay rules so the data-site attribute stays intact on the rendered <script> tag.
- 3
Track lead forms and WooCommerce events cleanly
Attach tiny event calls to newsletter opt-ins, Gravity Forms / Fluent Forms submissions, or affiliate button clicks using optional chaining.
theme-events.jsjs1document.addEventListener('submit', (e) => {2 const form = e.target;3 if (form && form.matches('.newsletter-form')) {4 window.trimstats?.('event', 'newsletter_subscribed', { location: location.pathname });5 }6}); - 4
Optionally connect WooCommerce order webhooks for revenue attribution
Store window.trimstats?.attribution?.() on checkout submission and post paid WooCommerce orders to TrimStats Custom HMAC webhook (/v1/webhooks/custom/{siteId}) signed with x-trimstats-signature.
High-signal custom events to track for WordPress
Fire any event with window.trimstats?.('event', name, props) and attach it to conversion goals or multi-step ClickHouse funnels.
| Event name | When to fire | Sample properties |
|---|---|---|
| newsletter_subscribed | Reader submits an email opt-in form in the blog sidebar or article footer. | {"placement":"inline_post"} |
| contact_form_submitted | Visitor completes a WPForms, Gravity Forms, or Fluent Forms inquiry. | {"form":"quote_request"} |
| lead_magnet_downloaded | Visitor downloads a PDF guide or template asset (file downloads also track automatically). | {"asset":"seo-checklist.pdf"} |
| affiliate_link_clicked | Reader clicks a sponsored or affiliate recommendation link. | {"partner":"host_a"} |
| woocommerce_checkout_started | Shopper enters the WooCommerce checkout page from cart. | {"currency":"USD"} |
TrimStats adds 1.96 KB vs 40 to 135 KB for GA4 and Tag Manager on WordPress
Compressed network transfer weight in kilobytes (KB, gzipped)
Removing gtag.js and heavy WordPress tracking plugins protects mobile Core Web Vitals (LCP and INP) across content-heavy blogs and WooCommerce stores.
Methodology: TrimStats measured from compiled packages/tracker/dist/t.js. GA4 and GTM sizes reflect documented public transfer benchmarks.
View chart data table
| Label | Gzipped transfer size |
|---|---|
| TrimStats t.js (Brotli) | 1.73 KB |
| TrimStats t.js (Gzip) | 1.96 KB |
| Google Analytics 4 (base gtag.js) | ~35-45 KB |
| GA4 + Google Tag Manager | ~135 KB |
WordPress analytics FAQ
Implementation details, privacy trade-offs, and event-quota answers.
Why is TrimStats faster than self-hosted WordPress analytics plugins?
Will WP Rocket, LiteSpeed Cache, or Autoptimize break TrimStats?
Can I exclude logged-in WordPress editors and admins from analytics?
Does TrimStats count single-page WordPress blog readers as bounces?
Can I attribute WooCommerce sales to blog posts and referrers?
Does TrimStats require a cookie consent banner on European WordPress sites?
Co-founder and Product Manager at DotCamp LLC and co-creator of TrimStats. Publisher, SEO practitioner, and WordPress product leader building creator tools since 2012.
- • Co-founder & Product Manager at DotCamp LLC (est. 2019), guiding product strategy for Ultimate Blocks, WP Table Builder, OptimizeCamp, and TrimStats
- • Full-time publisher and digital marketer since 2012; founder of RoadToBlogging.com and WPLeaders.com
- • WordPress.org Plugin Developer, Support Contributor, and WordCamp Sylhet 2023 speaker on building WordPress products
Verification standard: Code snippets, custom event payloads, and webhook contracts for WordPress are verified against the live TrimStats tracker (1.96 KB gzipped) and collector schema as of 2026-11-30.
Related documentation and guides
Instrument WordPress in under 60 seconds
Start on Starter ($17/month for 100,000 monthly events), with cookie-less privacy defaults and full access to revenue webhooks, funnels, cohorts, and UI friction.