A private counter for each site, built from the edge server’s access log. No browser script is needed for this counter: the edge already writes down every request.
Update, October 10, 2026: this post describes the shared access-log counter, which stays private on all three sites and is again the only analytics this blog used at the time. From October 3 to October 10 the blog also ran its own application analytics, with first-party cookies, a browser script and stored IP addresses; they went away with the move to Next.js, and their data was deleted. The privacy page describes what the blog records now.
The three sites I run send a Content-Security-Policy in which every source is the site itself, so a hosted analytics script was never an option, and I did not want one. I did want to know whether anyone reads this. The edge server in front of the sites already writes a line for every request it answers. That line has everything a page-view counter needs: the time, the host, the path, the status, the referrer, the browser string, and the visitor’s address as Cloudflare passed it on. The counter is a Go program of about 1,300 lines, 1,700 with its tests, standard library only, that follows the log and serves a page. The result is a page at /analytics on each site that only I can open: the edge asks for a password before it proxies the request, so the counts are kept for my own curiosity rather than published.
Where the log comes from
The edge is Caddy. Its site snippet, which all three hostnames import, now has two loggers: the console one that docker compose logs shows, and one that writes JSON to a file.
log console-log {
output stdout
format console
}
log analytics {
output file /var/log/caddy/access.log {
roll_size 32MiB
roll_keep 4
roll_keep_for 720h
}
format json
}
The file is on a named volume. The edge mounts it to write, the counter mounts the same volume read-only, and neither container has any other way to reach the other. Caddy rolls the file at 32 MiB by renaming it and starting a new one, and keeps four of the old ones for thirty days, so the log on disk is bounded whatever the traffic does.
Because the edge is told which addresses are Cloudflare’s and which header carries the real client, the client_ip field in each line is the visitor’s own address, not the Cloudflare node’s. Cloudflare also adds a Cf-Ipcountry header with a two-letter country code, and that is the only location information there is.
Following a file that gets renamed
The counter opens the log, reads to the end, hands over the complete lines, sleeps two seconds and reads again. Two things make it slightly more than that. A line can be half written when the reader reaches the end of the file, so bytes after the last newline are kept and joined with the next read. And the file can be rolled between two reads. The reader notices because the inode of the path has changed while its own descriptor still points at the renamed file, which it drains before it opens the new one.
ino, size := identityOf(t.path)
switch {
case ino != 0 && ino != cur.Inode:
f.Close()
f = nil
continue
case ino != 0 && size < cur.Offset:
if _, err := f.Seek(0, io.SeekStart); err != nil {
return err
}
cur.Offset = 0
partial = partial[:0]
continue
}
The position, as an inode and a byte offset, is written to a small file after every batch, after the events themselves. On a restart the reader opens the log, compares inodes and seeks to the offset, so a restart neither re-counts nor skips anything. If the process dies between writing a batch and writing the position, that batch is counted twice; the order is chosen so that the failure is a few seconds of traffic doubled rather than lost. The test for this starts the reader, finishes a torn line, renames the file the way Caddy does, appends to the renamed file and to the new one, stops the reader, starts it again and checks that every line arrived exactly once.
What counts as a page view
Most of what hits a public web server is not a person. The classifier reads one JSON line and decides, in this order. The host has to be one of the three sites. The method has to be GET and the status 200 or 304, because a 304 is a page the browser already had and asked about again, which is still someone opening it. The path is cleaned and the query string dropped, so /writing/x/?utm_source=y is /writing/x/. Then the path says what kind of request it was: the Atom feed is counted on its own as a fetch, the health check, the sitemap, the error page and the analytics page itself are ignored, and so is anything with an asset extension. What is left is a page, and for a page three more things have to hold. A browser that sends fetch metadata must say the destination is a document, which rules out prefetches, embeds and the requests a page makes for itself. A Purpose or Sec-Purpose header that says prefetch rules the line out. And the browser string must not match a list of words that programs use and browsers do not.
var botRE = regexp.MustCompile(`(?i)bot|crawl|spider|slurp|fetch|curl|wget|python|go-http-client|java/|libwww|httpclient|okhttp|axios|node-fetch|headless|phantom|lighthouse|pagespeed|pingdom|uptime|monitor|scan|check|validator|preview|facebookexternalhit|whatsapp|telegram|discord|slack|twitter|embedly|yandex|baidu|bing|duckduck|ahrefs|semrush|mj12|dotbot|petal|bytespider|gptbot|claude|anthropic|openai|ccbot|perplexity|applebot|amazonbot|dataprovider|netcraft|censys|shodan|masscan|zgrab|nmap|nikto|sqlmap|wpscan|feed|rss|reader|newsblur|inoreader|feedly|miniflux|tiny tiny|akregator|netnewswire|reeder`)
That list is the weakest part of the program, and it is weak in a known direction. A crawler that sends a real browser’s string gets counted, and nothing on the server side can tell it apart without the fingerprinting I am avoiding. So the numbers are an upper bound on people, with the bulk of the obvious machines removed. The feed is the exception: a feed reader is a program by nature, so feed fetches are counted whatever the string says, and shown separately.
A visitor is a hash that expires at midnight
The counter never stores an address. A visitor is the first eight bytes of an HMAC-SHA256 over the local date, the address and the browser string, keyed with a 32-byte secret the program generates on first start and keeps in its data directory.
func (s *Store) VisitorID(day, ip, userAgent string) string {
mac := hmac.New(sha256.New, s.secret)
mac.Write([]byte(day))
mac.Write([]byte{0})
mac.Write([]byte(ip))
mac.Write([]byte{0})
mac.Write([]byte(userAgent))
return hex.EncodeToString(mac.Sum(nil)[:8])
}
The date is part of the input, so the hash for one person changes at midnight in Los Angeles and the stored events cannot be joined across days. This is the same compromise Plausible and GoatCounter make, and it has the same consequence: there is no such thing as a returning visitor. “Visitors” for a month is the sum of each day’s distinct hashes, and someone who reads a post on Monday and comes back on Tuesday is two of them. The page says so next to the number. Without the secret, the hash is not reversible in any useful sense; with it, anyone who could guess an address and a browser string could confirm them for one day, which is why the secret is a file with mode 0600 inside a volume that only this container mounts.
What an event keeps, then: a timestamp, the host, the path, the referring host with www. removed and a few redirectors mapped to the site they belong to, the country code, the daily hash, a device class and a browser family. The browser string itself is not kept either; the family is one of six names.
Storage is a file per month
Events are appended as JSON lines to events-YYYY-MM.jsonl in the data volume, one object per line, flushed and synced after every batch. On start the program reads every month into memory and serves from there. At the traffic these sites get, a year is a few megabytes, and the report is a linear scan over a slice, which takes less time than the TLS handshake in front of it. If that stops being true the fix is an index, not a database. A damaged last line, which is the only shape of damage a crash can leave, is skipped with a note on stderr and costs one event.
The page
Each site serves /analytics by having the edge route that prefix to the counter instead of the site’s own container.
https://example.com {
import site /etc/caddy/certs/origin.pem /etc/caddy/certs/origin.key
handle /analytics* {
reverse_proxy stats:8080
}
handle {
reverse_proxy blog:8080
}
}
The counter reads the Host header to know which site is being asked about, so one process serves all three. The page shows page views and visitors for seven, thirty, ninety or 365 days or everything, a bar chart by day (by week beyond 120 days), the pages, the referrers with the share that sent none, the countries, the browser families and the device classes, and then a section that says how each number was counted. It is rendered with html/template from a template compiled into the binary. The security headers the edge adds to every response apply to it too, including the policy that forbids inline styles, so the chart is an SVG whose bars carry their coordinates as attributes and take their colours from a stylesheet, and the bars in the tables are tiny SVGs with a width attribute, because a style="width: 37%" is exactly what the policy blocks. The report is also available as JSON at /analytics/export.json.
The container
The image is built in two stages: a Go stage that runs go vet and the tests, so a failing test leaves no image to deploy, and a final stage that is FROM scratch with the binary and an empty data directory in it. There is no shell. The time zone database is compiled in with time/tzdata, and the container health check runs the binary itself with -check, which asks its own /healthz. It runs as the same unprivileged user as the other containers, with a read-only root filesystem, no capabilities and no way to gain any; its only writable paths are the data volume and a small tmpfs.
What this does not do
It does not measure time on page, scroll depth or anything that happens after the HTML arrives, because nothing runs in the browser. It does not see pages Cloudflare serves from cache, which for these sites is none, because the HTML is sent with must-revalidate and Cloudflare does not cache HTML unless told to. It does not know that two requests from one person on one device over two days are the same person, by design. And it counts well-disguised crawlers as people. For the question I had, which was whether anyone reads this and where they came from, that is enough, and the whole of the data stays on one disk I control.
