WordPress IntegrationWordPress & WooCommerce

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.

Istiak Rayhan
Istiak RayhanCo-Founder & Product Lead, DotCamp & TrimStats
Tested against WordPress & live TrimStats APIs
Seeded demo workspace
TrimStats Overview dashboard measuring WordPress content routes in cookie-less mode with 29,991 visitors, 36.8% bounce rate, and 2m 28s active dwell timeTrimStats Overview dashboard measuring WordPress content routes in cookie-less mode with 29,991 visitors, 36.8% bounce rate, and 2m 28s active dwell time
Measure true single-post reader engagement with visibility-aware active dwell time and bounce rules that never penalize 3-minute blog readers.
Direct answer

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. 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.phpphp
    1<?php
    2add_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. 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. 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.jsjs
    1document.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. 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.

Recommended taxonomy

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 nameWhen to fireSample properties
newsletter_subscribedReader submits an email opt-in form in the blog sidebar or article footer.{"placement":"inline_post"}
contact_form_submittedVisitor completes a WPForms, Gravity Forms, or Fluent Forms inquiry.{"form":"quote_request"}
lead_magnet_downloadedVisitor downloads a PDF guide or template asset (file downloads also track automatically).{"asset":"seo-checklist.pdf"}
affiliate_link_clickedReader clicks a sponsored or affiliate recommendation link.{"partner":"host_a"}
woocommerce_checkout_startedShopper 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)

KB
TrimStats t.js (Brotli)(1,732 B)
1.73 KB1x baseline
TrimStats t.js (Gzip)(1,964 B)
1.96 KB1.1x
Google Analytics 4 (base gtag.js)
~35-45 KB23.1x
GA4 + Google Tag Manager
~135 KB78.0x

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.

Source: TrimStats dist/t.js & public tag transfer benchmarks
View chart data table
LabelGzipped 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?
Local WordPress analytics plugins write hit rows directly into your WordPress MySQL database on every pageview, bypassing page caches and slowing down wp-admin queries. TrimStats ingests beacons externally into ClickHouse in Nuremberg, Germany so your WordPress origin stays 100% static-cacheable.
Will WP Rocket, LiteSpeed Cache, or Autoptimize break TrimStats?
Aggressive JS delay or minify combine settings can strip custom data-site attributes or defer execution until user interaction. Excluding collect.trimstats.com/t.js from combine and delay rules ensures accurate tracking with negligible 1.96 KB transfer weight.
Can I exclude logged-in WordPress editors and admins from analytics?
Yes. Wrapping the wp_head output in current_user_can("manage_options") prevents the script from rendering for logged-in administrators, or editors can set localStorage.setItem("trimstats_ignore", "1") in their browser.
Does TrimStats count single-page WordPress blog readers as bounces?
No. TrimStats counts a bounce only when a session has 1 or fewer pageviews AND less than 10 seconds of visibility-aware active dwell time. Readers who land from Google and read an article for 3 minutes count as engaged sessions.
Can I attribute WooCommerce sales to blog posts and referrers?
Yes. Forward the window.trimstats.attribution() snapshot into WooCommerce order meta and send a signed POST request on woocommerce_payment_complete to TrimStats Custom HMAC webhook endpoint (/v1/webhooks/custom/{siteId}).
Does TrimStats require a cookie consent banner on European WordPress sites?
Not in default cookie-less mode. TrimStats sets zero browser cookies, writes zero localStorage, discards raw IP addresses in memory on German EU servers using 24-hour rotating salts, and lets WordPress publishers avoid analytics-only consent popups.
Istiak Rayhan
Integration guide verified by
Istiak Rayhan (Co-Founder & Product Lead, DotCamp & TrimStats)

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.

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.

Verified against live TrimStats APIs and tracker bundle.