Skip to content
all posts
Product 2 min read updated July 20, 2026

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.

By Sourav · Building sonex
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.

A heavy tag does not just cost its own download. It competes with your real code for the main thread at exactly the moment a visitor is trying to use the page.

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-event attributes 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
Questions

Frequently asked.

Cookies, install and pricing, answered. Still stuck? Ask us anything .

01 Can sonex show revenue next to my traffic?

Yes. Connect Stripe or Polar with a read-only key and sonex reads revenue straight from your payment provider, per website. Revenue then appears as a focusable series on the Overview chart and as its own report, beside the traffic that earned it. No tracked event is needed for it to work.

02 Does sonex use cookies?

No. sonex sets no cookies and needs no consent banner. It counts visits without cookies, fingerprinting, or any personal data, so it is GDPR, PECR and CCPA-ready by default.

03 How do I install sonex?

Add one script tag to your site's <head> with your website id. It is a single lightweight tracker — no build step and no SDK required.

04 Is sonex a Google Analytics alternative?

Yes. sonex gives you the reports that matter — visitors, pages, referrers, funnels, revenue and a world map — without surveilling your audience or drowning you in configuration.

05 How is sonex priced?

By monthly tracked events. Free covers 2k events, Pro is $20/mo for 200k events, and Business is $200/mo for 2M events with team seats.

See what your traffic actually earns.

Revenue beside the visitors that produced it. No cookies, no credit card, no consent banner.

Get started