How We Built AI Traffic Tracking in PostHog, From Install to Funnel

Before PostHog, our AI traffic was a guess. We could see referral spikes in GA4 and a few “chatgpt.com” rows buried in source reports, but we couldn’t answer the questions that mattered. Which engines send us people? Which pages do they cite? Do those visitors do anything after they land?

So we built the answer. This is the full walkthrough of how AlchemyLeads instrumented its own site with PostHog to track AI traffic from first click to conversion: the install, the reverse proxy, the classifier, the one-line bug that nearly wrecked the data, and the first week of real numbers.

If you run a site that AI engines are starting to cite, this is the setup we’d hand you.

Life Before PostHog: Best Guesses

Here’s what “tracking AI traffic” looked like for us before this build.

GA4 lumped ChatGPT visits into generic referral traffic. Perplexity and Gemini showed up inconsistently or not at all. There was no way to segment by engine, no way to see which pages the engines were citing, and no way to connect an AI visit to a form fill or a booked call. When a client asked “how much of your traffic comes from ChatGPT,” the honest answer was a shrug with a confidence interval.

That’s a bad place to be for an agency selling AI search visibility services. We tell clients that AI engines are a real acquisition channel. We needed our own site to prove it with event-level data.

Step 1: Installing PostHog Behind Our Own Domain

The install itself is one snippet. We run WordPress, so the PostHog init script went into a site-wide header snippet in WPCode. Any tag manager or theme header works the same way.

The part most guides skip: we did not point the snippet at PostHog’s default ingestion domain. Ad blockers and privacy extensions kill requests to known analytics hosts, and the visitors we most wanted to measure (technical buyers researching agencies through AI tools) are exactly the crowd running blockers.

So we routed ingestion through a reverse proxy on our own domain using a small Cloudflare Worker:

  • alchemyleads.com/ph/static/* forwards to PostHog’s asset host
  • alchemyleads.com/ph/* forwards everything else to PostHog ingestion
  • The init config sets api_host: 'https://alchemyleads.com/ph' and ui_host: 'https://us.posthog.com'

First-party path, same-domain requests, far fewer dropped events. If you’re on Cloudflare already, the Worker is maybe 20 lines.

Step 2: Building the AI Traffic Classifier

PostHog doesn’t label AI traffic out of the box. We wrote a small classifier that runs before the first event fires and stamps every visitor with AI attribution properties.

It checks two signals:

  1. Referrer. Did the visitor arrive from chatgpt.com, perplexity.ai, gemini.google.com, copilot.microsoft.com, claude.ai, grok.com, chat.deepseek.com, or meta.ai?
  2. UTM source. Did the URL carry a utm_source naming one of those engines? ChatGPT in particular appends utm_source=chatgpt.com to outbound links, so the tag survives even when the referrer gets stripped.

When either signal hits, the classifier registers super properties on the session: ai_sourced, ai_engine, ai_detection_method, and ai_landing_page. Super properties ride along on every later event, so a form submission three pages deep still knows it started from ChatGPT. We also register a first_ai_engine property once and never overwrite it, which preserves first-touch attribution when someone returns through a different engine.

Total classifier size: about 40 lines of JavaScript in the same header snippet.

The One-Line Bug That Cost Us a Month of Data

Worth pausing on, because it will bite anyone building this from scratch.

Our first classifier version tested UTM values against bare engine names. The regex expected chatgpt. ChatGPT sends utm_source=chatgpt.com. The referrer pattern allowed the .com suffix; the UTM pattern didn’t. Result: whenever the referrer was stripped and only the UTM survived, our biggest AI source got stamped ai_sourced: false and vanished from every AI report.

The fix was one line, checking each UTM value against the referrer pattern as a fallback:

if (engines[i].utm.test(utm) || engines[i].ref.test(utm)) { ... }

The painful lesson: PostHog events are immutable after capture. The mislabeled history stays mislabeled. We rebuilt the August picture with a HogQL query keyed on raw utm_source values instead of the broken property, but the properties themselves can’t be repaired. Test your classifier against real engine URLs on day one, not week four.

What PostHog Tracks Natively: the AI Channel, Direct Traffic and AI Crawlers

PostHog now handles more AI traffic on its own than it did when we started this build. Here is what it does natively as of November 2026, and where a custom setup still earns its place.

AI is a default channel type. PostHog web analytics gives each visit a channel type based on the referring domain, UTM tags and ad click IDs on the landing URL. One of the default channels is AI. It matches a utm_source from PostHog’s list of AI sources (the docs give chatgpt, claude, gemini, perplexity and copilot as examples) or a referring domain such as chatgpt.com, claude.ai, perplexity.ai or gemini.google.com. If you want your own grouping, you can define custom channel types under Web analytics in project settings, and they take priority over the defaults.

Direct has a strict definition. A visit counts as Direct when the referring domain is the special value $direct, utm_medium is not set, and utm_source is empty or set to direct. PostHog checks its rules in order, and the Direct rule runs before the organic rules, AI included. So an AI click that arrives with no referrer and no UTM tag lands in Direct. That is the dark AI funnel, and no channel rule can pull it back out.

AI crawlers are a separate problem. PostHog’s bot detection sorts traffic at query time into Regular, AI Agent, Bot and Automation, with categories such as ai_crawler, ai_search and ai_assistant. Add an “Is bot equals false” filter to count humans only, or break down by traffic type to see AI agents on their own. The catch: most crawlers, GPTBot and ClaudeBot included, never run JavaScript, so the PostHog snippet never fires for them. To see them, forward your server or CDN logs to PostHog as $http_log events, with $raw_user_agent set on each one. A Cloudflare Worker running on your site’s routes is one way to do it.

We kept our classifier anyway. A channel type tells you a visit came from AI. Our super properties record which engine, how we detected it, where the visitor landed and their first AI engine, and every conversion event carries all four.

What We Can Finally See: Traffic by Engine

The fixed classifier and proxy went live on August 25. Here’s the first week of verified AI traffic to alchemyleads.com (August 25 to 31, 2026, internal tests excluded):

Engine Visitors Pageviews Pages per Visitor
ChatGPT 11 62 5.6
Claude 2 14 7.0
Gemini 1 7 7.0

Small absolute numbers. We’re a niche B2B agency site, not a publisher. But the behavior pattern is the insight: AI-referred visitors go deep. ChatGPT visitors averaged 5.6 pages each. Claude visitors averaged 7. These are not bounce-and-leave clicks. Someone who asked an AI engine a question, got our site as a cited source, and clicked through is in research mode, and they read like it.

That single behavioral fact changed how we think about AI referrals. They act less like social traffic and more like high-intent organic visitors evaluating a shortlist. Our take on what to ask an AI search agency covers why that intent profile matters when you’re deciding where to invest.

The Pages AI Engines Actually Cite

The second insight surprised us more. We assumed AI engines would mostly cite the homepage. Wrong.

The homepage took 8 of 83 AI-sourced pageviews, roughly 10 percent. The rest landed on deep pages: an email outreach template article, a web accessibility explainer, a WordPress database optimization post, industry pages for automotive aftermarket and eCommerce marketing, a paid media service page, and a pet pharmacy SEO case study. Dozens of distinct URLs, most receiving one or two visits each.

The long tail is the story. AI engines don’t funnel people through your front door. They cite whichever specific page answers the question being asked, so old blog posts you stopped thinking about in 2023 are suddenly acquisition surfaces. In PostHog this is one HogQL query: filter pageviews where ai_sourced is true, group by pathname, sort by count. Ten seconds to run, and it tells you exactly which content is earning citations and which money pages the engines ignore.

That last part is the actionable bit. If your service pages aren’t in the citation list, the engines aren’t seeing them as answers. That’s a content structure problem you can now measure instead of guess at.

Following AI Visitors Down the Funnel

Traffic is nice. Revenue is the point.

Because the classifier uses super properties, every conversion event on the site carries its AI attribution automatically. We track two conversion events, form_submit and booking_scheduled, wired to our HubSpot form and Calendly embed through their JavaScript callbacks. Both verified end to end with synthetic test events before we trusted them.

That gives us a per-engine funnel in PostHog: AI visit → pageview depth → form fill or booked call. For each engine we can see what share of visitors reach the contact page, which action they take, and how the paths differ. Does a ChatGPT visitor fill the form? Does a Claude visitor book straight to calendar? Or do they go dark and email us cold a week later? The first two are now measurable events. The cold email crowd, we’ll grant, still escapes attribution. Some things never change.

Full transparency on the current numbers: in the first week of clean data, the funnel is wired and verified but the AI-sourced conversion sample is too small to publish rates from. We’re not going to invent a conversion rate from a handful of visits. The value right now is the instrument itself. Every future AI-sourced lead arrives pre-labeled with its engine, detection method, and landing page, and the per-engine conversion picture builds itself from here.

What to Steal From This Setup

If you build one thing this quarter, build this. The whole stack is a reverse proxy, a 40-line classifier, super properties, and two conversion events. Rough order:

  • Install PostHog through a reverse proxy on your own domain
  • Classify AI referrals by referrer and UTM, and test against real engine URLs including utm_source=chatgpt.com
  • Stamp attribution as super properties so conversions inherit it
  • Wire your form and booking events, then verify with synthetic submits
  • Query top AI-cited pages monthly and feed the answer back into your content plan

We run this exact setup for clients who want AI search treated as a measurable channel instead of a mystery. AlchemyLeads builds the tracking first, because you can’t grow a channel you can’t see. If you want this instrumented on your site, book a strategy session with AlchemyLeads.

Frequently Asked Questions

Does PostHog track AI traffic out of the box?

Yes. PostHog web analytics includes a default AI channel type. It matches visits whose utm_source is on PostHog’s list of AI sources, such as chatgpt or perplexity, or whose referring domain is an AI assistant such as chatgpt.com, claude.ai or gemini.google.com. For engine-level attribution on every conversion event, add your own classifier that registers super properties.

Can PostHog track AI crawlers and AI agent traffic?

Yes, with a caveat. PostHog’s bot detection classifies events as Regular, AI Agent, Bot or Automation at query time. Most AI crawlers, such as GPTBot and ClaudeBot, never run JavaScript, so the PostHog snippet never sees them. To measure them, forward your server or CDN logs to PostHog as $http_log events that include the raw user agent.

How does PostHog define direct traffic?

PostHog counts a visit as Direct when the referring domain is the special value $direct, utm_medium is not set, and utm_source is empty or equal to direct. In practice that means someone typed the URL, used a bookmark, or arrived from a source that passed no referrer and no UTM tags.

Why does some ChatGPT traffic show up as direct in PostHog?

PostHog can only label a visit as AI if the referrer or a UTM tag survives the click. When an AI app or browser strips the referrer and the link carries no utm_source, PostHog has nothing to match and files the visit as Direct. ChatGPT often adds utm_source=chatgpt.com to links, so check UTM values before assuming the visit is lost.

Can PostHog capture phone number clicks on WordPress?

Yes. PostHog autocapture records clicks on link elements by default, so tel: links are captured, and you can filter autocapture events by href target. For a cleaner conversion event, add a short click listener to the same site-wide header snippet that calls posthog.capture with an event such as phone_click whenever someone clicks a tel: link. Super properties then attach the AI attribution.

Suggested

What five missed RFQs a month cost in lifetime revenue: $375K+ injection molding, $750K+ EMS, $1.13M+ power supplies, $1.88M+ large-part machining.

The Cost of Inaction in Manufacturing Lead Generation: What Five Missed RFQs a Month Cost in 15 Industries

What five missed RFQs a month cost in 15 manufacturing industries, with customer lifetime values, a conservative 15 to 20% close rate, and a cost of inaction calculator.
October 27, 2026
Card: search crawlers to allow. ChatGPT needs OAI-SearchBot, Perplexity needs PerplexityBot, Google AI Mode needs Googlebot; GPTBot and Google-Extended are training only.

How to Get Cited by ChatGPT, Perplexity and Google AI Mode

How ChatGPT, Perplexity and Google AI Mode choose sources, which crawlers to allow, and a five-step plan to get your company cited, based on official docs.
October 26, 2026
Card: where AI clicks land in GA4. Browser referrals in AI Assistant or Referral, ChatGPT UTM links in Unassigned, app links in Direct, AI Overviews in Organic Search.

How to Set Up AI Search Attribution in GA4: A Step-by-Step Guide for 2026

Step-by-step GA4 setup for AI search attribution: an AI Assistants channel, a copy-paste regex, ChatGPT UTM fixes and a self-reported AI source field.
October 26, 2026
Checklist card: voice search in the AI assistant era, with six of the 11 steps, from crawler access to asking assistants out loud each month.

Voice Search in 2026: How AI Assistants Pick Their Sources

We first wrote about voice search in 2022, when the question was whether “Hey Siri” and “OK Google” would change how people shop. Four years later, voice is back in a bigger form. People now talk to ChatGPT, Gemini, Siri, Alexa+ and Copilot the way they talk to a knowledgeable friend, and those assistants answer by reading the web in
October 17, 2026
Chart comparing 38,148 host visits, 4,160 cookieless visits and 1,375 GA4 sessions for alchemyleads.com, plus 32,837 verified AI crawler requests in 30 days

Log File Analysis for AI Search: Our Logs Showed 38,148 Visits. GA4 Showed 1,375.

Our host logged 38,148 visits. GA4 logged 1,375 sessions. We opened the server logs to see who was really there, and what AI crawlers read.
October 16, 2026
    Contact us
    We value your privacy and won't share your email with others. We'll only contact you with curated content.