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_sourcedai_engineai_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.

author avatar
Sean Chaudhary Founder & CEO
Sean Chaudhary is the Founder and CEO of AlchemyLeads, a specialized, revenue-first SEO and content marketing agency in the Los Angeles area (Calabasas, California). He founded the agency in 2017 on a simple principle: measure SEO by revenue, not vanity metrics. Over 15+ years in search marketing, Sean developed the Good SEO® framework and has led organic growth programs for B2B and ecommerce brands, with a focus on technical SEO, content strategy, and link building. He writes regularly on SEO and content marketing, with bylines on platforms including Zapier and GoDaddy. Connect with Sean on LinkedIn to follow his work on SEO, GEO, and AI-era search.

Suggested

Image

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
September 3, 2026
Questions to Ask AI Search Agency

Questions to Ask an AI Search Agency Before You Sign

You have two or three agency calls booked, and every agency on the list is using the same three words. GEO. AEO. Somewhere in the deck, LLM optimization. They all describe the same goal, which is getting your brand named when a buyer asks ChatGPT, Perplexity, or Google’s AI answers a question. But herein lies the problem: most agencies get bookings by relabeling
August 25, 2026
Hero graphic with orange network lines radiating from a central rounded code panel labeled 'ai-catalog.json' on a dark hex-pattern background. Title reads 'Agentic Resource Discovery'.

Agentic Resource Discovery: A Practical Walkthrough

Agentic resource discovery is the new standard that tells AI agents what your website can do for them. Most sites have no answer yet. They are invisible to the agents that will soon book, buy, and research for real customers. Here is the problem. Search is moving from people typing queries to agents acting on their behalf. If an agent
July 6, 2026
Infographic showing AI Search Attribution: a funnel from Visit to Buy ending at Direct, with an orange credit arc and callouts on the right side.

How to Solve the AI Search Attribution Funnel

Your AI search work is paying off. People are finding you in ChatGPT and Perplexity, your brand shows up in the answers, and demand feels warmer than it did last year. Then you open your analytics. The channel that grew is “Direct.” The report says AI sent you almost nothing. That gap is not a traffic problem. It is an
July 2, 2026
Comparison: left panel shows top 3 page rankings with #1 highlighted in orange; right panel shows AI recommendations with identical top item.

SEO Isn’t Dead. The Unit Just Changed.

Every quarter someone declares SEO dead. This year AI search is holding the knife. The logic sounds clean: if ChatGPT and Perplexity answer the question, nobody clicks a blue link, so why rank at all? We wanted a real answer, not a hot take. So we ran the test. We sent 8 buyer-style “best tool” questions through Perplexity and logged
June 29, 2026
    Contact us
    We value your privacy and won't share your email with others. We'll only contact you with curated content.