Inside the 3 kB analytics script
What a lightweight analytics script actually does, why script weight matters for Core Web Vitals, and how sonex fits realtime tracking into roughly 3 kB with no dependencies.
All posts
Analytics is supposed to observe your site, not slow it down. Yet the typical tag weighs 45 kB or more, before it fetches anything else. The sonex tracker is roughly 3 kB (2.9 kB brotli, 3.3 kB gzipped). This is what fits in that budget, and why the budget matters.
Why weight matters
Every kilobyte of JavaScript is downloaded over the network, parsed, and executed on the visitor’s device, often a mid-range phone on a slow connection. That work delays interactivity and shows up directly in Core Web Vitals like Interaction to Next Paint. Analytics that hurts the experience it measures is a bad trade.
What fits in 3 kB
The tracker is hand-written vanilla JavaScript with no third-party dependencies. In that space it:
- Loads with
defer, so it never blocks parsing or rendering - Sends a pageview using the browser’s own beacon and keepalive fetch, which survive the page unloading
- Tracks single-page-app navigation through the History API, so route changes count as pageviews
- Reads declarative
data-sonex-eventattributes for custom events, no extra code required - Honours Do Not Track and skips visitors who ask not to be counted
What is not in there
The size comes as much from what is absent as what is present. There is no cookie or consent logic, because nothing is stored on the device. There is no fingerprinting library, no identity graph, and no advertising code. Those are the parts that bloat conventional tags, and they are exactly the parts a privacy-first tool does not want.
Declarative by default
Because reading data-* attributes is cheap, most tracking needs no JavaScript at all:
<button data-sonex-event="signup" data-sonex-event-plan="pro">
Start free
</button>
The attributes ride along as event properties. For anything dynamic, a tiny API is available:
window.sonex.track("checkout", { value: 49 });
The payoff
Small, dependency-free, and deferred means the tracker is effectively invisible to your visitors and to your performance budget. You measure realtime visitors, pages, referrers, funnels and custom events, and your page still loads like the analytics is not there. That is the intended outcome: fast to insight, and quiet by default.
Frequently asked questions
- Why does analytics script size matter?
- Every kilobyte of JavaScript is downloaded, parsed and executed on your visitor's device, which delays interactivity and can hurt Core Web Vitals. A ~3 kB analytics script like sonex costs a fraction of a typical 45 kB tag, so measuring your site does not slow it down.
- How does sonex stay so small?
- It ships no third-party dependencies, no cookie or consent machinery, and no ad-tech identity code. It loads with defer, sends events with the browser's own beacon and keepalive fetch, and tracks single-page navigation through the History API, all in hand-written vanilla JavaScript.
- Does the sonex script block page rendering?
- No. It is loaded with the defer attribute, so it never blocks parsing or rendering, and it does its work after the page is interactive.
sonex is privacy-first web analytics. No cookies, no consent banner, no personal data. Drop one script and read realtime visitors, funnels and a world map in seconds.
Try sonex free