How to detect bot traffic on your website

Basic3 min readUpdated

GET /learn/detection/how-to-detect-bot-traffic/ Accept text/html text/markdown

Short answer

To detect bot traffic, compare your data with how people use the site. Look in analytics for spikes with no engagement, in server logs for high request rates, script User-Agents and clients that never load CSS or JavaScript, and in login, signup and checkout data for many failures from one source. Verify any visitor that claims to be a search crawler.

Bot traffic rarely shows up as one obviously bad request. It shows up as a pattern that does not match how people use your site: too fast, too regular, too narrow, or coming from places where people do not browse. You can find most of it with three sources you already have: analytics, server or CDN logs, and the results of your logins, signups and orders.

What are the signs of bot traffic in analytics?

Tag-based analytics tools only see visitors that run their JavaScript tag, and many bots never do. What they do catch tends to look like this:

  • Sudden spikes in sessions with close to zero engagement time, often from one city, one network or one screen size.
  • Direct traffic landing on deep pages, such as product or search URLs, at hours when your customers sleep.
  • Browser versions far behind current releases, or operating system and browser pairs that rarely exist.
  • Referral traffic from sites you have never heard of.

Google Analytics 4 excludes known bots automatically, but only those on its known list. For filters and segments, see how to identify and filter bot traffic in GA4.

How do you find bots in server logs?

Server logs record every request that reaches the server, including clients that never run JavaScript. These commands assume the nginx or Apache "combined" log format.

Top client IPs and top User-Agents:

bash
awk '{print $1}' access.log | sort | uniq -c | sort -rn | head -20
awk -F'"' '{print $6}' access.log | sort | uniq -c | sort -rn | head -20

Requests per IP per minute, to find clients that go faster than a person can click:

bash
awk '{print $1, substr($4, 2, 17)}' access.log | sort | uniq -c | sort -rn | head -20

HTTP libraries that keep their default User-Agent:

bash
grep -Ei 'python-requests|curl/|Go-http-client|okhttp|HeadlessChrome|Scrapy' access.log \
  | awk -F'"' '{print $6}' | sort | uniq -c | sort -rn

IPs that request many pages but never load a stylesheet or script. Real browsers fetch those files, simple scrapers do not. This only works when your origin serves the static files; if a CDN caches them, the asset requests never reach your origin logs, so run it on CDN logs instead.

bash
awk '$7 ~ /\.(css|js)(\?|$)/ {assets[$1]++; next} {pages[$1]++}
END {for (ip in pages) if (!(ip in assets) && pages[ip] > 50) print pages[ip], ip}' access.log \
  | sort -rn | head -20

Requests for files that should not exist on your site, such as /.env, /.git/config or /wp-login.php on a site that does not run WordPress, come from scanners looking for leaked secrets or weak admin pages:

bash
awk '$7 ~ /^\/(\.env|\.git|wp-login\.php|xmlrpc\.php|phpmyadmin)/ {print $1}' access.log \
  | sort | uniq -c | sort -rn | head

The threshold of 50 pages is a starting point. Shared IPs, such as offices and mobile carriers, put many real people behind one address, so check what an IP requested before you block it.

How do you check whether a Googlebot is real?

Anyone can put "Googlebot" in a User-Agent. Google's verification method is a reverse DNS lookup followed by a forward lookup:

bash
host 66.249.66.1
# 1.66.249.66.in-addr.arpa domain name pointer crawl-66-249-66-1.googlebot.com.
host crawl-66-249-66-1.googlebot.com
# crawl-66-249-66-1.googlebot.com has address 66.249.66.1

The hostname must end in googlebot.com, google.com or googleusercontent.com, and the forward lookup must return the original IP. A "Googlebot" that fails this check is a scraper using the name. Other search engines publish similar methods, listed in how to verify Googlebot and other good bots.

Which networks do the requests come from?

Look up the ASN, the network that owns an IP. Team Cymru runs a free lookup service:

bash
whois -h whois.cymru.com " -v 203.0.113.5"

Browsing from cloud and hosting networks is unusual for shoppers and readers, so a page-heavy client on a hosting ASN deserves a closer look. VPN users and corporate gateways also appear there, so treat it as one signal. Bots that rent home connections will look like normal broadband users here; detecting residential proxies needs other methods.

Where do bots show up in business data?

Your own application data often shows abuse before traffic graphs do. On login, look for many usernames tried from one IP or device with a low success rate, the shape of credential stuffing:

sql
SELECT ip,
       COUNT(*) AS attempts,
       COUNT(DISTINCT username) AS usernames,
       AVG(CASE WHEN success THEN 1.0 ELSE 0 END) AS success_rate
FROM login_events
WHERE created_at > now() - interval '1 hour'
GROUP BY ip
HAVING COUNT(DISTINCT username) > 10
ORDER BY usernames DESC;

At checkout, bursts of small payments with many declines point to card testing. At signup, look for bursts of accounts with similar email patterns or the same device. On search and listing pages, sessions that page through the whole catalogue in order are usually scrapers.

Tools that help

StopBots is published by Kairal, which is one of the tools listed. The list is not a ranking.

  • GoAccess is a free, open-source log analyser that runs in a terminal or builds an HTML report, enough for a small site that wants the views above without writing commands.
  • CrowdSec is open source and reads your logs, detects scanning and brute-force patterns, and can block IPs reported by its community.
  • Cloudflare Bot Management adds a bot score to each request at the edge, which fits sites already behind Cloudflare.
  • AWS WAF Bot Control labels and filters bot requests for applications behind CloudFront, an Application Load Balancer or API Gateway.
  • Kairal combines device, network and behaviour signals per endpoint, and its preview mode shows what it would block before you enforce anything.

Common questions

How do I check if my website traffic is bots?

Take one busy day and compare analytics sessions with server log requests for the same pages. A large gap usually means automated clients that never run your analytics script, and grouping the log by IP and User-Agent shows which clients make up the difference.

Does GA4 filter out bot traffic?

GA4 excludes traffic from known bots and spiders automatically, and you cannot switch this off or see how much it removed. It does not catch bots that hide behind a normal browser User-Agent, so filtered reports can still contain automated sessions.

What is malicious bot traffic?

It is automated traffic that works against you: credential stuffing on login, card testing at checkout, scraping of prices or content, fake signups and spam. Search crawlers and uptime monitors are also bots, but you usually want them.