engineering6 min read

Bounce Rate vs Active Engagement Time Analytics

How TrimStats tracks visibility-aware active dwell time in packages/tracker/src/index.ts and computes accurate bounce rates using a 10-second active threshold.

Istiak Rayhan
Istiak RayhanCo-Founder & Product Lead, DotCamp & TrimStats
Codebase verification: Direct walkthrough of the visibility-aware engagement timer in packages/tracker/src/index.ts (lines 125-167) and ClickHouse bounce calculation.(packages/tracker/src/index.ts)
Executive finding

Why is traditional single-pageview bounce rate misleading for blogs and documentation sites?

Traditional bounce rate marks every single-page visit as a bounce even if a developer spent four minutes reading your documentation, copied an API snippet, and solved their problem. TrimStats fixes this by pairing a Page Visibility API active-dwell timer in t.js with a ClickHouse bounce rule requiring both pageviews <= 1 and active duration under 10,000 ms.

Key takeaways
  • Legacy single-pageview bounce rules routinely report 75% to 88% bounce rates on successful technical docs and tutorials where readers get their answer on one page.
  • TrimStats pauses engagement timing whenever document.visibilityState === "hidden" so forgotten background browser tabs never inflate average visit duration.
  • Leave beacons flush on visibilitychange, pagehide, and SPA route transitions only when accumulated active time is at least 500 ms.
  • Combining visibility-aware dwell (< 10 seconds) with opt-in 90% scroll reach distinguishes genuine content engagement from accidental clicks.

Why classic bounce rate punishes your best content

In legacy web analytics, a "bounce" meant one thing: a session containing a single pageview and zero subsequent page transitions. That definition made sense for multi-page 2008 news slideshows, yet it breaks completely on modern developer documentation, technical blog posts, and answer-first landing pages.

Consider what happens when an engineer searches Google for "Stripe webhook signature verification," lands on your documentation page, reads carefully for three minutes, copies your TypeScript snippet, and closes the tab. Under single-pageview bounce math, that successful visit registers as a 100% bounce with 0 seconds of time on page because no second pageview ever fired to compute a timestamp delta.

Legacy single-page bounce rate dramatically overstates exits on docs and guides

Illustrative bounce rate (%) comparing single-pageview-only rules vs TrimStats (<10s active dwell)

%
TrimStats (<10s active + <=1 pv)
Legacy (<=1 pv only)
Legacy single-page bounce rate dramatically overstates exits on docs and guidesOn high-intent docs and technical guides, single-pageview bounce formulas misclassify roughly half of engaged readers as bounces.02141628231%82%Docs (/docs/*)34%79%Pillar Guides39%64%Comparison (/vs/*)44%58%Pricing (/pricing)

On high-intent docs and technical guides, single-pageview bounce formulas misclassify roughly half of engaged readers as bounces.

Methodology: Illustrative comparison demonstrating the structural gap between single-pageview-only bounce math and TrimStats active-dwell bounce math (pageviews <= 1 AND duration_ms < 10,000).

View chart data table
LabelTrimStats (<10s active + <=1 pv)Legacy (<=1 pv only)
Docs (/docs/*)31%82%
Pillar Guides34%79%
Comparison (/vs/*)39%64%
Pricing (/pricing)44%58%

Worse still, naive Date.now() - pageLoadTime timers fail in the opposite direction. A visitor who opens three comparison tabs in the background, goes to lunch for 40 minutes, and closes Chrome inflates average session duration by an order of magnitude even though they spent four seconds looking at the screen.

Seeded demo workspace
TrimStats Overview dashboard reporting 36.8% visibility-aware bounce rate (<10s single-page) and 2m 28s active visit time across 29,991 visitorsTrimStats Overview dashboard reporting 36.8% visibility-aware bounce rate (<10s single-page) and 2m 28s active visit time across 29,991 visitors
TrimStats labels its bounce metric explicitly (<10s single-page) alongside visibility-aware active visit time so teams never misread healthy single-page reads.

How TrimStats measures true foreground engagement in 25 lines

TrimStats solves both distortions inside packages/tracker/src/index.ts using the browser Page Visibility API (document.visibilityState), pagehide, and SPA navigation hooks, all compiled inside the 1.96 KB gzipped bundle:

// Visibility-aware engagement timer in packages/tracker/src/index.ts
let visibleStart = document.visibilityState === 'hidden' ? 0 : Date.now();
let elapsedMs = 0;

const flushEngagement = () => {
  if (visibleStart) {
    elapsedMs += Date.now() - visibleStart;
    visibleStart = document.visibilityState === 'hidden' ? 0 : Date.now();
  }
  if (elapsedMs >= 500) {
    send({ t: 'leave', d: elapsedMs });
    elapsedMs = 0;
  }
};

document.addEventListener('visibilitychange', () => {
  if (document.visibilityState === 'hidden') {
    flushEngagement();
  } else {
    visibleStart = Date.now();
  }
});
window.addEventListener('pagehide', flushEngagement);

Four deliberate engineering details make this tiny timer accurate in production:

  1. Pre-rendered and background-opened tabs start paused: If a user middle-clicks a link to open your post in a background tab, document.visibilityState starts as 'hidden', so visibleStart initializes to 0. Counting begins only when the user actually focuses the tab.
  2. pagehide instead of unreliable unload: Modern Chromium and Safari browsers preserve bfcache and frequently drop unload handlers, whereas visibilitychange (to 'hidden') paired with pagehide and navigator.sendBeacon reliably delivers the final leave beacon even on mobile Safari tab switches.
  3. 500 ms noise floor: Flushing only when elapsedMs >= 500 avoids cluttering ClickHouse with zero-duration redirect bounces or double-fired visibility transitions.
  4. Automatic SPA route flushing: Whenever Next.js App Router, React Router, or Vue calls history.pushState (or the user triggers popstate), onRouteChange() flushes elapsed active time against the departing pathname before sending the incoming pageview beacon.

Why text/plain + navigator.sendBeacon prevents lost exit beacons

Exit timing fails in many analytics scripts not because the JavaScript clock is wrong, but because the browser cancels outbound network requests during tab teardown. A standard fetch() call with Content-Type: application/json triggers a cross-origin CORS preflight (OPTIONS) round trip that mobile Safari and Chrome frequently abort mid-flight when a user closes a tab or switches apps.

Inside packages/tracker/src/index.ts, TrimStats serializes the compact JSON payload into new Blob([body], { type: 'text/plain' }) and hands it directly to navigator.sendBeacon(endpoint, blob) (with a fetch(..., { method: 'POST', body, keepalive: true }) fallback when sendBeacon is unavailable). Using text/plain qualifies as a CORS simple request, removing the preflight round trip completely so the final leave beacon survives tab closure cleanly without adding latency to page navigation.

Average visibility-aware active dwell time reveals which pages hold reader focus

Seeded acme.dev 30-day demo workspace measuring foreground tab seconds per page

sec
/blog/script-benchmark
3m 42s
/docs/quickstart
2m 48s
/vs/google-analytics-4
2m 22s
/pricing
1m 18s
/
54s

Excluding hidden background tabs exposes true foreground reading duration without 25-minute idle-tab outliers.

Methodology: Seeded acme.dev 30-day workspace demonstrating foreground active dwell aggregation (sum(active_duration_ms) / sessions).

Source: TrimStats seeded demo workspace (acme.dev)
View chart data table
LabelActive dwell
/blog/script-benchmark3m 42s
/docs/quickstart2m 48s
/vs/google-analytics-42m 22s
/pricing1m 18s
/54s

The ClickHouse bounce formula: pageviews <= 1 AND duration_ms < 10,000

On the analytics server, TrimStats computes bounce rate per session using both page depth and accumulated active foreground duration:

  • A session is counted as a bounce if and only if pageviews <= 1 AND active duration_ms < 10,000 (10 seconds).
  • Average visit time is computed as sum(active_duration_ms) / sessions, bounded per beacon (0 to 86,400,000 ms) and immune to background-tab inflation.
  • Sessions use a 30-minute sliding inactivity timeout refreshed automatically on every incoming event.

This 10-second active-focus boundary aligns cleanly with human reading behavior. Accidental clicks, mis-targeted search snippets, and slow-page abandonments leave within seconds and count as bounces; genuine readers who spend 90 seconds reading a guide or inspecting pricing count as engaged sessions.

How common visitor journeys compare across bounce formulas

Seeing concrete user journeys side by side clarifies why engineering and growth teams should stop optimizing for legacy single-pageview bounce rate:

Visitor ScenarioLegacy Bounce (<= 1 pv)Naive Load-to-Unload TimerTrimStats Active Dwell (< 10s)
Reads API docs for 3m 20s, copies code, closes tabBounce (0s)Engaged (3m 20s)Engaged (3m 20s)
Opens blog in background tab for 25m, glances 4s, closesBounce (0s)Engaged (25m 04s inflated)Bounce (4s active)
Clicks paid ad, hits slow hero, hits Back in 3sBounce (0s)Bounce (3s)Bounce (3s active)
Visits /pricing for 18s, navigates via SPA to /signupEngagedEngagedEngaged (both routes timed)

Passive requestAnimationFrame scroll reach without jank

When data-friction="true" is enabled, TrimStats attaches a single { passive: true } scroll listener gated by requestAnimationFrame. Instead of calculating layout geometry on every scroll pixel (which causes jank on long mobile guides), the callback checks (window.scrollY + window.innerHeight) / Math.max(document.documentElement.scrollHeight, 1) >= 0.9 at most once per animation frame. As soon as the visitor reaches 90% of document height, t.js sets scrolled90 = true, fires one { t: 'scroll', sc: 90 } beacon, and short-circuits every future scroll event until an SPA route transition calls trackPageview() and resets scrolled90 = false.

Seeded demo workspace
TrimStats UI Friction report displaying 36.5% 90% deep scroll reach alongside rage click and dead click metrics across landing pagesTrimStats UI Friction report displaying 36.5% 90% deep scroll reach alongside rage click and dead click metrics across landing pages
Pairing visibility-aware dwell with 90% deep scroll reach verifies whether single-page readers actually reached the bottom of long technical articles.

Auditing content performance with accurate engagement signals

Once noisy single-pageview bounces disappear from your dashboard, content and product teams can separate real problems from healthy behavior cleanly:

  • High bounce (> 65% under the 10-second rule) on a landing page: Indicates mismatched ad/SERP intent, slow LCP, or an unclear above-the-fold headline.
  • Low bounce (< 35%) + high active dwell (> 2m) + low conversions: Signals readers value the article, yet your CTA placement or internal funnel links need tightening.
  • High active dwell (> 2m) + low 90% scroll reach (< 20%): Points to an early wall of text, broken embedded table on mobile, or a confusing code snippet causing readers to stall above the midpoint.
  • Sudden bounce or conversion shift week over week: Triggers TrimStats' rolling 7-day conversion_dip or friction_spike anomaly detectors automatically without manual spreadsheet checks.

Verifying active dwell beacons locally in 30 seconds

You can verify visibility-aware timing on any site running t.js without reading server logs. Open Chrome DevTools, select the Network tab, enable Preserve log, and filter requests by /v1/collect. Load a page and read it for five seconds, then switch to another browser tab. A POST /v1/collect beacon fires immediately with t: "leave" and d close to 5000 milliseconds. Leave that tab hidden for two minutes, switch back for three seconds, and navigate to another route: the next leave beacon reports roughly 3000 milliseconds rather than 123000, confirming idle background time was excluded cleanly.

Read the full KPI formulas in Core Metrics & Sessions Docs or inspect how TrimStats pairs engagement with UI Friction Tracking.

Frequently asked questions

Why does TrimStats wait until 500 ms before sending a leave engagement beacon?
Filtering out sub-500 ms leave beacons prevents rapid redirect hops, instant accidental back-button taps, and double visibility flips from flooding ClickHouse with tiny noisy leave rows while keeping active dwell totals accurate.
Do background browser tabs inflate average visit duration in TrimStats?
No. TrimStats listens to the browser Page Visibility API (visibilitychange). As soon as a visitor switches to another tab or minimizes the window, elapsed foreground time flushes and the timer stops until the tab becomes visible again.
How does TrimStats measure active time across Next.js or React SPA route transitions?
Whenever history.pushState or popstate changes window.location.pathname, t.js immediately flushes the departing route active duration as a leave beacon, resets visibleStart and scrolled90, and sends the incoming route pageview beacon.
How does TrimStats active bounce rate compare to GA4 Engaged Sessions?
Both models reject legacy single-pageview-only bounce math by checking a 10-second engagement floor. TrimStats measures foreground-only active dwell via the Page Visibility API inside a 1.96 KB cookie-less script and defines a bounce strictly as <= 1 pageview AND < 10 seconds of active dwell.
Do leave engagement beacons count as extra billable events against my monthly quota?
Leave beacons transmit elapsed foreground milliseconds to compute accurate active dwell and bounce rate on page exits and route changes. TrimStats also drops bot traffic before billing and includes a 20% soft grace buffer on every plan tier from Starter to Scale.
Does active dwell tracking work in strict cookie-less mode without localStorage?
Yes. The engagement timer keeps visibleStart and elapsedMs purely in volatile JavaScript memory for the current tab lifecycle, writing zero cookies and zero localStorage keys while linking each leave beacon to the session on EU ClickHouse servers.

Sources & references

Istiak Rayhan
Written & 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: Codebase verification: Direct walkthrough of the visibility-aware engagement timer in packages/tracker/src/index.ts (lines 125-167) and ClickHouse bounce calculation.

Measure traffic, revenue, and UI friction in 1.96 KB gzipped

Cookie-less by default, powered by ClickHouse, and starting at $17/month for 100,000 monthly events with every feature unlocked.