@nadiamohamed/ai-referral-tracker
v0.1.0
Published
Detect and isolate AI-search referral traffic (ChatGPT, Perplexity, Gemini, Copilot, AI Overviews) from GA4 exports and server logs.
Maintainers
Readme
📖 Docs & full guide: How to track AI referral traffic in GA4 Built by Nadia Mohamed — SEO Engineer · Technical SEO + GEO for SaaS. Try the free companion tools at nadiamohamed.me/ai-tools.
Referrals from AI assistants are the fastest-growing traffic source almost nobody measures cleanly. In GA4 they're scattered across dozens of referral rows — chatgpt.com, perplexity.ai, gemini.google.com — with no built-in "AI search" channel to group them.
ai-referral-tracker does that grouping. Point it at a GA4 CSV export or a raw access log and it tells you exactly how much of your traffic came from AI search, broken down by engine.
Zero dependencies. The engine list lives in a single, editable JSON file so you can keep it current as new assistants ship.
Install
npx @nadiamohamed/ai-referral-tracker ga4-export.csv
# or
npm install -g @nadiamohamed/ai-referral-trackerUsage
ai-referral <file|-> [options]| Option | Description |
| --- | --- |
| -f, --format <fmt> | auto · ga4 · log (default auto) |
| --json | Emit JSON instead of a table |
Read from stdin with -:
cat ga4-export.csv | ai-referral -Example
$ ai-referral examples/ga4-export.csv
AI-search referral traffic
ChatGPT 612 ████████████████████████ 45.7%
Perplexity 344 █████████████ 25.7%
Gemini 151 ██████ 11.3%
Copilot 96 ████ 7.2%
Claude 54 ██ 4.0%
You.com 12 ▌ 0.9%
1373 of 7657 sessions (17.9%) came from AI search.Inputs it understands
GA4 CSV export — from Reports → Acquisition → Traffic acquisition, use the export button. The tool skips GA4's # comment preamble and auto-detects the Session source and Sessions columns (it also accepts Source / medium, First user source, etc.).
Server access logs — Common or Combined Log Format (nginx/Apache). The referrer field is read from each line and hits are grouped by referrer.
What counts as "AI search"
The full, versioned list is in data/ai-sources.json — ChatGPT, Perplexity, Gemini, Google AI Overviews, Copilot, Claude, You.com, Poe, Phind, Grok, DeepSeek, Mistral, Meta AI, and more. Each entry maps a friendly engine name to the hostname fragments that identify it. PRs welcome as new assistants launch — this file is meant to be a community-maintained reference.
Programmatic API
import { loadSources, classify, summarize } from '@nadiamohamed/ai-referral-tracker';
const engines = await loadSources();
classify('https://www.perplexity.ai/search', engines);
// -> { isAI: true, engine: 'Perplexity', vendor: 'Perplexity', matched: 'perplexity.ai' }
summarize(
[ { source: 'chatgpt.com', sessions: 100 }, { source: 'google', sessions: 900 } ],
engines
);
// -> { totalSessions: 1000, aiSessions: 100, aiShare: 0.1, engines: [...] }Why not just a GA4 segment?
You can build one by hand — and then rebuild it every time a new assistant launches, in every property, forever. This keeps the source-of-truth list in version control, works on server logs GA4 never sees (bots that don't run JS), and drops straight into a reporting script or CI job.
Part of the GEO toolkit
Open-source tools I maintain for AI-search visibility:
- llms-txt-generator — spec-compliant
/llms.txtfrom any sitemap - geo-audit-cli — score any URL on AI-search readiness
- json-ld-schema-templates-seo — production JSON-LD templates optimized for AI citation
- awesome-generative-engine-optimization — curated GEO resources
Web-based versions (no install): AEO Analyzer, Keyword Clustering & more →
License
MIT © Nadia Mohamed — SEO Engineer, Technical SEO + GEO for SaaS & tech.
