Disclosure: I work on Get AI Vizible, which tracks how AI assistants mention brands. Nothing below needs it: just a log file and the Python standard library. This post was drafted by an AI agent for our team; the script was run against a test log before publishing.
Everyone is talking about "AI search traffic", but most analytics dashboards lump it into "referral" or "direct". If you have server access logs, you can get a real number in a few minutes, and see which pages the assistants are sending people to.
When someone clicks a link inside an AI assistant's answer, the visit usually carries the assistant's domain in the Referer header:
| Assistant | Referrer host |
|---|---|
| ChatGPT | chatgpt.com (older links:chat.openai.com ) |
| Perplexity | perplexity.ai /www.perplexity.ai |
| Gemini | gemini.google.com |
| Microsoft Copilot | copilot.microsoft.com |
| Claude | claude.ai |
| DeepSeek | chat.deepseek.com |
| Grok | grok.com |
ChatGPT also appends utm_source=chatgpt.com to the links it shows. That matters, because the mobile apps often strip the referrer: the UTM tag is then the only trace left in the request.
It reads the standard Apache/Nginx "combined" format, keeps successful GET requests, and counts the ones that came from an assistant, with the top landing pages for each:
#!/usr/bin/env python3
"""Count visits that AI assistants send to your site, from an access log.
Usage: python ai_referrals.py access.log [access.log.1 ...]
Reads Apache/Nginx "combined" format. Standard library only.
"""
import re
import sys
from collections import Counter, defaultdict
from urllib.parse import urlsplit, parse_qs
AI_HOSTS = {
"chatgpt.com": "ChatGPT",
"chat.openai.com": "ChatGPT",
"perplexity.ai": "Perplexity",
"gemini.google.com": "Gemini",
"copilot.microsoft.com": "Copilot",
"claude.ai": "Claude",
"chat.deepseek.com": "DeepSeek",
"grok.com": "Grok",
}
AI_UTM = {"chatgpt.com": "ChatGPT"}
LINE = re.compile(
r'(?P<ip>\S+) \S+ \S+ \[(?P<time>[^\]]+)\] "(?P<method>\S+) (?P<path>\S+) [^"]*" '
r'(?P<status>\d{3}) \S+ "(?P<ref>[^"]*)" "(?P<ua>[^"]*)"'
)
def assistant_for(ref, path):
host = (urlsplit(ref).hostname or "") if ref not in ("", "-") else ""
for known, name in AI_HOSTS.items():
if host == known or host.endswith("." + known):
return name
source = parse_qs(urlsplit(path).query).get("utm_source", [""])[0].lower()
return AI_UTM.get(source)
def main(files):
by_ai, pages = Counter(), defaultdict(Counter)
total = 0
for name in files:
with open(name, encoding="utf-8", errors="replace") as fh:
for line in fh:
m = LINE.match(line)
if not m or m["method"] != "GET" or not m["status"].startswith("2"):
continue
total += 1
ai = assistant_for(m["ref"], m["path"])
if ai:
by_ai[ai] += 1
pages[ai][urlsplit(m["path"]).path] += 1
found = sum(by_ai.values())
print(f"{found} of {total} successful page views came from an AI assistant")
for ai, n in by_ai.most_common():
top = ", ".join(f"{p} ({c})" for p, c in pages[ai].most_common(3))
print(f" {ai:<11}{n:>6} top pages: {top}")
if __name__ == "__main__":
if len(sys.argv) < 2:
sys.exit(__doc__)
main(sys.argv[1:])
Run it on today's log, or on a week of rotated logs at once:
python ai_referrals.py /var/log/nginx/access.log /var/log/nginx/access.log.1
On a small test log it prints:
6 of 8 successful page views came from an AI assistant
ChatGPT 3 top pages: /pricing (2), /blog/llms-txt (1)
Perplexity 1 top pages: /blog/llms-txt (1)
Gemini 1 top pages: / (1)
Claude 1 top pages: /pricing (1)
A few details worth noting:
www.perplexity.ai counts but a look-alike such as notchatgpt.com doesn't.2xx GET requests are counted, so 404s, redirects and form posts don't inflate the number.
Treat the result as a floor, not the full picture:
Referrer-Policy settings drop the header. Apart from ChatGPT's UTM tag, those visits land in "direct".google.com, exactly like a normal search click. Search Console is the only place Google reports it.
Even with those gaps, the landing-page list is useful. The pages assistants link to are the ones they consider the best answer, which tells you what to keep accurate and up to date.
robots.txt.
If you run this on your own logs, I'm curious which assistant comes out on top for you. Let me know in the comments.