Bot traffic in analytics: how I find the real visitors

Bot traffic in analytics hid my real audience: 31,261 requests, about 13 people. Fake Googlebots, scrapers that run JavaScript and the signals that held up.

By

Over five days, the access log for my own site recorded 31,261 requests. About 13 of those visitors were real people. Bot traffic in analytics is usually discussed as noise around the edges, and in these two cases it was most of the signal. On a photo marketplace I work on, a quarter of session replay entries came from visitors who never touched the page, and most counted visitors were crawlers. This post covers what I changed in the browser, what my nginx logs showed about fake Googlebots and scrapers that run JavaScript, the filter mistake that made it all look better than it was, and the signals that held up.

How do you spot bot traffic in analytics?

Start from raw server logs, because they show requests your analytics script never saw. Check whether claimed crawlers really come from their owners, look at what each client asks for, and test for behaviour a person produces and a script rarely bothers with. No single check is enough. Treat the result as an estimate and compare it with a source you trust, such as Search Console for search traffic.

Recording only after a real action

On the marketplace, session replay recorded every load. So a quarter of the entries showed nothing at all: a page opening and nobody touching it.

The fix was to stop recording on load and start on the first real input:

function recordOnFirstAction(mp: Mixpanel) {
  const actions = ['pointerdown', 'keydown', 'wheel'];
  const start = () => {
    actions.forEach((a) => removeEventListener(a, start, true));
    if (!navigator.webdriver) mp.start_session_recording();
  };
  actions.forEach((a) => addEventListener(a, start, { capture: true, passive: true }));
}

I listen for wheel over scroll because a script can scroll a page without any input device. There's a second benefit: the recorder download now waits for that first input too, so a visitor who never interacts never pays for it.

Browsers reporting navigator.webdriver send nothing at all. MDN describes the property as a standard way for co-operating user agents to say they are under automation. The word "co-operating" is the catch. A crawler that hides it still gets through, so this removes the honest automation and leaves the rest for filtering in reports. The same split between what the browser reports and what the server knows drove my server-side conversion tracking.

Most Googlebots in my logs were not Google

Then I went through the logs of my own site, and the user agent column stopped meaning much.

Over about 6 days, 1,057 requests carried a Googlebot user agent. Only 81 of them came from 66.249.x, the block that makes up most of Google's published crawler list. Most of the rest were scanners borrowing the name while probing for /.env, /.htpasswd and docker-compose.yml, and 664 of those requests got a 404.

You can run this count on any combined-format log. Splitting on the quote character makes the user agent field 6 and the request line field 2:

# Claimed Googlebot, split by source address
awk -F'"' '$6 ~ /Googlebot/ { split($1, f, " "); print (f[1] ~ /^66\.249\./ ? "66.249.x" : "other") }' access.log | sort | uniq -c

# What the "other" group asked for
awk -F'"' '$6 ~ /Googlebot/ && $1 !~ /^66\.249\./ { split($2, r, " "); print r[2] }' access.log | sort | uniq -c | sort -rn | head

That prefix is a quick first pass, and I'd keep it to that. Google's list also holds other ranges, so 81 is a floor. For a real answer, follow Google's guide to verifying its crawlers. It gives two methods: run a reverse DNS lookup on the address, confirm the name ends in googlebot.com, google.com or googleusercontent.com, then run a forward lookup and confirm it returns the same address. Or match the address against the published JSON lists of IP ranges, which suits anything at scale.

Referrers are no better. Other probes on the same kind of paths faked google.com as the referrer. A referrer is a header the client chooses to send, so it proves nothing on its own.

If you want to see what the real Googlebot receives from your pages, I covered that in Next.js metadata and Googlebot.

Running JavaScript doesn't prove a person

The common defence of script-based analytics is that bots don't run JavaScript. My logs disagree.

On the day I published a batch of posts, about 600 addresses that ran JavaScript hit the site, mostly in one hour right after the deploy. They came from a few cloud provider ranges, using old Chrome versions (107 to 133). On a chart that looks like readers arriving. Running JavaScript did not prove a person.

Three things gave it away, and each is cheap to check: the timing was tied to my deploy and nothing else, the addresses clustered in a handful of ranges, and the browser versions were old in a way that a crowd of real visitors with auto-updating browsers wouldn't be. Any one of those can be innocent. All three together are a pattern.

The filter that excluded nothing

My own mistake belongs in this post, because it's the one most likely to catch you.

My first filter dropped known address prefixes. The pattern required a space after each prefix, something like ^(203\.0\.113|198\.51\.100) . A real address continues with a dot and one more number, so no line ever matched. It excluded nothing, and it reported 478 visitors for a day that really had 4.

It printed a number with no error, which is the danger. A count that looks too good deserves a second look. The check I'd add now is small: after any filter, count how many lines it removed. Zero removed means the filter is broken or the data is clean, and with this much bot traffic it won't be clean. The same habit of testing evidence applies when you lean on logs to remove unused API endpoints.

The signals that held up

After those false starts, this is the order that worked on my site:

  1. Start with page data prefetches. Real browsers prefetch page data while someone is browsing. A scanner hunting for a config file has no reason to do that, so a client that prefetches is a better starting point than one that merely loaded HTML.
  2. Exclude known cloud ranges. People rarely browse from a data centre. Keep the list short and go back to it after each spike.
  3. Exclude verified crawlers. Check them properly, then count them separately. They matter for search, and they aren't readers.
  4. Then look at referrers. Once the rest is gone, referrers tell you something, because most of the fakes have gone with the scanners.

It's still an estimate, and that includes my figure of about 13 people. A person with a blocked script or a VPN can fall out, and a careful scraper can stay in. For search traffic I don't use it at all: Search Console is the source, since it reports what Google itself measured.

If bots are reaching your forms as well as your charts, the filtering needs to move from reports to the request, which is what Cloudflare Turnstile on Next.js forms is for.

The short version

Bot traffic in analytics can outnumber people by a wide margin, and every obvious signal can be faked. A user agent proves nothing until DNS or Google's IP lists back it up. Referrers are chosen by the client. Running JavaScript doesn't prove a person either. Start replay on real input, drop browsers that admit to automation, and count humans from behaviour, then subtract cloud ranges and verified crawlers. Check that each filter removes something. If you do one thing today, run that awk line on your own access log.

More of what I build is on the projects page.

Want this kind of work on your product?

Get in touch