Self-Hosted, Privacy-Respecting Analytics for a Static Blog

I put off adding analytics to this site for a long time. Early on, it felt like premature optimization, and I didn’t want third-party trackers on my pages. Now that I’ve shared around ten posts and tools on Twitter, I’m curious what people actually read and use, without cookies or an ad-tech company sitting in the middle. (If I change any of this later, the GitHub repo is the live source of truth.)

Running Umami at home

Architecture diagram showing a reader's browser sending only /script.js, /api/send, and /api/heartbeat through a Cloudflare Tunnel at stats.risukh.in to Umami and PostgreSQL on a home Linux box, with /login and /dashboard returning 404 from the public internet and the author accessing the dashboard only over SSH.
Only the three collector paths cross the public tunnel; the admin UI is unreachable from the internet.

I think people should own their own data and services. I didn’t want Google Analytics, and I didn’t want every page load pinging a SaaS analytics vendor either. Even Umami’s hosted free tier loads JavaScript from cloud.umami.is and drops your history after six months.

Self-hosting cuts out the middleman. Readers’ browsers only talk to stats.risukh.in. On my home Linux box, Umami and PostgreSQL run in two Docker containers bound strictly to localhost with restart: unless-stopped, so they come back after a reboot or crash and nothing listens on my local network or router.

To put the collector behind HTTPS without opening port 443 or exposing my home IP, I moved DNS for risukh.in to Cloudflare and set up cloudflared as a persistent user systemd service. The tunnel only forwards /script.js, /api/send, and /api/heartbeat and returns 404 for everything else. The login page and dashboard don’t exist on the public internet; I only open the UI locally over SSH.

One DNS gotcha worth knowing upfront: Cloudflare’s free Universal SSL wildcard covers one subdomain level (*.risukh.in), not two (stats.andrey.risukh.in). Putting the collector at stats.risukh.in saved me from needing a paid certificate.

What I track (and what I don’t)

The Umami script is 9.3 KB, sets no cookies, and stores no persistent visitor IDs. Beyond basic pageviews, I added a small deferred script (assets/js/umami-reading-depth.js) for three things I actually want to know:

  • Reading depth (posts): fires read-depth once at 25%, 50%, 75%, and 100% scroll.
  • Active reading time (posts): fires read-time at 30s, 60s, 180s, and 300s, pausing whenever the tab is hidden.
  • Outbound clicks (site-wide): records the destination host and path (with query strings stripped) when someone clicks an external link.

Both Umami (data-do-not-track="true") and my script check navigator.doNotTrack === "1". If you opt out in your browser, nothing gets sent.

Living with home hardware

The obvious trade-off with a home server is uptime. Because the tracker loads with defer, a power or internet outage at home never breaks andrey.risukh.in on GitHub Pages. I just miss analytics during the gap, which I can live with.

Still, I want to know when there’s a gap and not lose the database. Two systemd timers handle that:

  1. Daily backups: dumps and compresses PostgreSQL automatically and keeps 30 days of history.
  2. Uptime checks (every 5 minutes): probes /api/heartbeat both locally and over stats.risukh.in, logging status and latency so I can check 24-hour, 7-day, and 30-day availability. Pairing that with an external HTTP monitor catches home internet or power outages that a local probe can’t see.

It’s a small setup, but it gives me the feedback I was missing without handing my readers’ browsing habits to someone else.