Build notes
Your Unique Visitors Are Mostly Bots: What nginx Logs Can and Cannot Count
Batdorj Byambadorj · · 5 min read
I needed to know whether anyone was visiting my site and downloading the EA. I chose a log analyser — GoAccess, reading nginx's own access log — over a JavaScript tracker, and the first number it gave me was wrong in a way that took a while to see.
Why logs rather than a tracker
Three reasons, and the first decided it.
The thing I most need to count is a file download. An .ex5 does not run JavaScript, so a tracker only sees a download if I attach a handler to the link — which misses a direct link, a command line fetch, and a resumed download. Logs see the request itself.
Second, my privacy page says the site loads no analytics script. Adding one would mean rewriting that page and two others. The log analyser reads a log I already declared, and collects not one extra bit.
Third, it needed no new service, no database, no subdomain, no certificate. The logs were already on disk.
The first number
Two weeks, 61,088 requests. The status breakdown:
- 404 — 46,476, which is 76% of everything
- 200 — 6,278
- 301 — 5,264
- 400 — 1,335
- 308 — 566
Three quarters of all traffic to a site with a handful of pages was requests for things that do not exist. That is scanners, and it is normal, and it means any number computed before filtering is meaningless.
After ignoring those status codes and known crawlers: valid requests fell from 12,492 to 5,255, and "unique visitors" from 1,631 to 1,032.
Why 1,032 is not a number of people
The homepage was requested 1,136 times in that period. Each JavaScript chunk belonging to it was requested between 104 and 129 times. The favicon, 107.
A real browser fetches the HTML and then the assets. So roughly nine out of ten requests for my homepage took the HTML and nothing else. They are not people. They carry browser user agents, they are not on any crawler list, and from log data alone there is no rule that separates them from a human.
A second signature pointed the same way: in the breakdown by platform, one mobile OS and its browser showed many visitors and very few hits each — the fingerprint of a proxy network rather than a phone.
The number I kept
Unique IP addresses that fetched something under the static asset path.
A robot that wants to look like a visitor has no reason to download a JavaScript chunk; it costs bandwidth and buys nothing. A human with a browser cannot avoid it. The measure is not perfect, but it fails in the honest direction.
A small daily file now records four numbers: browsers counted that way, views of the download page, actual file downloads, and licence checks.
The import that counted a day twice
The first import fed a rotated log file to the analyser on standard input. The daily script later fed the same file by its path.
The analyser remembers the last line it has read per file path. Through standard input there is no path, so the second run did not recognise the first, and one day went into the persistent database twice.
I rebuilt the database and set the last-import marker by hand. The rule that came out of it: a day's log enters a persistent database by exactly one route. The structural protection, which matters more than the rule, is that only finished days are persisted at all — today's figures are read for the report and never written.
What the numbers actually said
Over five days: 72 visitors, 17 of them reached the download page, 5 downloaded the file. About 24% and about 29%.
Those are not bad conversion rates. They are good rates on almost no traffic. The funnel works and the traffic does not, and that told me the next piece of work was content rather than code — which is partly why this article exists.
One number that counts less than it looks
The licence-check figure only counts users who added my API domain to their terminal's whitelist. Without that line the call is refused inside the terminal in zero milliseconds and never reaches the network at all.
So anyone running the EA on the free tier is invisible to my server, by design. A zero there means "nobody added the whitelist line", not "nobody is running it". Downloads are the only proxy I have for installs, and they are a weak one.
That is the price of collecting as little as possible, and it is worth naming out loud, because a metric with a silent floor will eventually be read as a measurement by somebody — including by me, six months from now.
A note on retention
Choosing a log-based tool does not by itself make the analytics private. The analyser's own database turned out to keep full addresses with no expiry, which quietly contradicted what my site promised. That is a separate story about auditing a privacy policy against the code, and the short version is that the setting I thought covered it did not.
If you are counting visitors from logs
- Filter by status code first. Three quarters of my traffic was 404s.
- Never report "unique visitors" from logs. It is a count of addresses, not of people.
- Compare a page's hits against its assets' hits. The ratio tells you what is a browser.
- Pick a metric a robot has no incentive to fake.
- Let one day's log enter a persistent store by one route only.
- Write down what each number cannot see, next to the number.
Batdorj Byambadorj
Batdorj Byambadorj has been trading forex for his own account since 2007, mostly gold. He is the sole developer of fx-alert and writes every article on this site himself.