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 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 call with AlchemyLeads.

Suggested

Marketing strategist reviewing AI brand sentiment charts and a reputation gauge on a large monitor at night

AI Reputation Management: What LLMs Say About Our Brand, and What We Do About It

Our real AI sentiment data: what ChatGPT, Perplexity and Google AI Overviews get right and wrong about AlchemyLeads, and how we manage LLM reputation.
October 13, 2026
Marketing lead reviewing a sharp rise in direct traffic on an analytics dashboard next to an AI answer

The Dark Funnel: Why Direct Traffic Spikes When AI Search Visibility Grows

Direct traffic doubled and nobody can explain it? That is the dark funnel. Why AI search hides attribution, how to rule out other causes, and the client data that shows what it is worth.
October 13, 2026
Engineers reviewing a satellite component on a test stand in an advanced manufacturing facility with a robotic arm, battery modules and a cleanroom

Industrial Marketing for the Builders: Why We Bet on Hard Tech

Why AlchemyLeads put industrial and hard tech companies at the center of its work in 2023, what reindustrialization changes, and who we’re built for now.
October 12, 2026
Abstract chart of three rising bars showing a health score climbing.

Our Ahrefs Health Score Went From 74 to 96. Here’s What Our AI SEO Agent Found.

Seven problems our AI SEO agent found on our own site, from leads GA4 never recorded to 195 pages linking through redirects, and how we fixed them.
October 8, 2026
Abstract chart of error bars dropping to zero beside a check mark.

How Our AI SEO Agent Cleared 1,186 Schema Errors in One Day

How our AI SEO agent and team took a Shopify store from 1,186 structured data errors, 12 404s and 155 broken links to zero in one day.
October 8, 2026
    Contact us
    We value your privacy and won't share your email with others. We'll only contact you with curated content.