DEV Community

Guillermo Llopis
Guillermo Llopis

Posted on

I Built a 510-Byte Analytics Script. Here's How (and Why).

Most analytics scripts are massive. Google Analytics loads ~82 KB of JavaScript. Even privacy-focused alternatives like Plausible (~1 KB) and Umami (~2 KB) are significantly larger than they need to be.

I built Fairlytics with a tracking script that's 510 bytes gzipped. Here's the technical story of why and how.

Why small matters

Every byte of JavaScript your page loads has a cost:

  • Parse time on mobile devices
  • Network transfer on slow connections
  • Render-blocking potential
  • Core Web Vitals impact

For an analytics script that runs on every page of your site, these costs multiply across every single page view.

The privacy pipeline

When a visitor loads a page with Fairlytics, here's what happens:

  1. The 510-byte script sends a POST request with 4 fields: site ID, page URL, referrer, and page title
  2. Server receives the request along with the IP address and User-Agent (standard HTTP)
  3. The IP is used for an in-memory GeoIP lookup → produces a 2-letter country code → IP is discarded (never stored)
  4. The User-Agent is parsed into browser family + OS family → raw string discarded
  5. Referrer is reduced to domain only
  6. Query parameters are stripped from the URL
  7. A daily-rotating anonymous hash is generated for unique visitor estimation (no cookies needed)

What gets stored: page_path, page_title, referrer_domain, country_code, browser_family, os_family, device_type, session_id, viewed_at

What never touches the database: IP addresses, full user agents, full referrer URLs, query parameters, any form of persistent user ID.

How the script works

The tracker is vanilla JavaScript, no dependencies. It:

  1. Reads the data-site and data-api attributes from its own script tag
  2. Sends a single POST request on page load
  3. Listens for popstate events for SPA navigation
  4. Checks for DNT and GPC signals — if either is set, it does nothing
  5. Uses navigator.sendBeacon when available for non-blocking requests

That's it. No event queue, no batching, no retry logic, no session management, no cookie handling.

What you get without cookies

Without setting any cookies, Fairlytics provides:

  • Page views and unique visitors (via daily-rotating hashes)
  • Top pages by traffic
  • Referrer sources (domain only)
  • Country, browser, OS, and device type breakdowns
  • Goal tracking for custom conversion events
  • Real-time dashboard

The comparison

Google Analytics Plausible Fairlytics
Script size ~82 KB ~1 KB 510 bytes
Cookies 2-4 0 0
Consent banner needed Yes No No
Data points per pageview 17+ ~8 4
IP storage Yes Temporary Never

Try it

Fairlytics is live and free to try (10K pageviews/month, no credit card):

<script src="https://app.fairlytics.dev/js/tracker.v1.js"
        data-site="YOUR_SITE_ID"
        data-api="https://app.fairlytics.dev"></script>
Enter fullscreen mode Exit fullscreen mode

One line. 510 bytes. Zero cookies.

Website: https://fairlytics.dev
Live demo: https://fairlytics.dev/demo/

Top comments (0)