Crawlers render pages now
Googlebot does not only fetch your HTML. It renders the page in a browser, which means it runs your scripts. Any script that reports a page view by calling back to your server will be called by the crawler as well.
Ace Crawl Enhancer has an optional view counter that works this way: the page loads, a small script sends one request, and the server adds one to that post's count. The counts feed the retention report, which uses them to tell posts that are still read from posts that are not.
What the logs showed
On one site I looked at what Googlebot was asking for and found that one request in five was the counter. Every one of those was refused by the server, which already ignored known crawlers. So no count was wrong. But each refused request still cost a full WordPress load to reach the code that said no, and it was a fifth of the crawler's visits spent on something of no use to it.
On a community site the picture was different again. Most counter requests there came from scripted clients presenting themselves as an ordinary desktop browser. They sent a believable Origin header. What they did not send was the Sec-Fetch-Site header that a real browser adds to a request made by a page.
Three changes
Do not send it in the first place. From 1.0.100 the counter script checks the same crawler list the server uses, and sends nothing from crawlers and automated browsers. The cheapest request is the one never made.
Count before WordPress loads. From 1.0.101 a plain, valid hit is recorded while the plugin is loading, before the rest of WordPress starts. Counting a view no longer costs a page's worth of server time.
Refuse early. From 1.0.102 a request with no sign of coming from a page in a real browser is turned away at that same early point. A same-origin request from a browser that sends no Origin header is still counted, because some browsers leave it out.
What to check on your own site
- Search your access log for your counter or analytics endpoint and group the requests by user agent. If crawlers appear, your script is running for them.
- Look at how long those requests take. If each one loads the whole application to record a single number, that is your server's time being spent on bookkeeping.
- Check whether the requests carry Sec-Fetch-Site. Real browsers send it on requests made by scripts. Its absence does not prove a bot, but its presence with the value same-origin is a good sign of a real page view.
- Do not "fix" refusals. A wall of 401 responses to scripted clients means the counter is working.
Why it matters for search
Crawl attention is finite. Every request a crawler spends on an endpoint that tells it nothing is one it did not spend on a page. Keeping housekeeping endpoints quiet for crawlers is a small thing, and it is the kind of small thing that adds up on a large site.