Five Minutes to Analytics: PostHog, Cookieless Tracking, and an AI That Can Read Its Own Traffic
April 5, 2026. We added analytics to emdash-labs.com today. From creating a PostHog account to querying live visitor data through Claude Code's MCP: under five minutes. That's not a rounded-down estimate. It was genuinely faster than making coffee.
The problem
We use Claude Code as part of our daily workflow for building and managing sites. Part of that is understanding how sites perform. Which pages get traffic? Where do visitors come from? What content is working? An AI assistant that can't see analytics is missing context that should inform its suggestions.
We needed something that could feed data back to Claude programmatically. Google Analytics is the default answer, but it's designed for humans staring at dashboards. We needed an API-first analytics tool with native AI integration.
Why PostHog
PostHog won on three points. First, it has an official MCP server with roughly 27 tools. Claude can query trends, funnels, paths, retention, lifecycle data, and more, all through the same tool-use protocol it uses for everything else. No screen-scraping. No brittle API wrappers. Just native tool calls.
Second, it supports true cookieless tracking. Set persistence to memory, set person_profiles to identified_only, and PostHog tracks pageviews and interactions without writing a single byte to the visitor's device. No cookies. No localStorage. No consent banner. For a content site like this, that's the right tradeoff: we get aggregate traffic data without the privacy baggage.
Third, the free tier is 1 million events per month. We are, to put it gently, not going to hit that ceiling anytime soon.
The implementation
The entire implementation was adding a script tag to our Astro layout's head element. Here's what it looks like (minus the minified loader):
posthog.init('phc_...token...', { api_host: 'https://us.i.posthog.com', person_profiles: 'identified_only', persistence: 'memory' });
That's it. Three config options. PostHog's autocapture handles the rest: pageviews, page leaves, clicks, form interactions. Deploy, and events start flowing immediately.
We considered posthog-js-lite (a lighter SDK designed for environments where bundle size matters), but the full snippet is loaded async and doesn't block rendering. For a server-rendered Astro site, the performance impact is negligible.
The MCP connection
This is the part that makes it interesting. Adding the PostHog MCP server to Claude Code means we can query analytics in the same conversation where we're writing code and managing content. Within minutes of deploying the snippet, we ran a trends query and got back:
Three pageviews across three pages: the homepage, /plugins, and /plugins/postmark-email. We could see traffic broken down by URL. We confirmed cookieless mode was working (zero person records created). We verified three event types were being captured: $pageview, $pageleave, and $autocapture.
All from inside Claude Code. No browser tab. No dashboard login. Just tool calls returning structured data.
Where this goes
Today, Claude queries PostHog when we ask. But the tools are there for more. Check which blog posts are getting organic traffic and prioritize follow-up content. Spot pages with high bounce rates and suggest layout changes. Correlate a content publish with a traffic spike and learn what resonates. The analytical surface area (trends, funnels, paths, retention, lifecycle) is the same toolkit a human product manager works with, exposed as tool calls.
The five-minute timeline
For the record, here's what five minutes looked like:
Minute 1: Sign up for PostHog Cloud. Create project "Emdash Labs."
Minute 2: Copy the JS snippet into BaseLayout.astro. Set the three cookieless config options.
Minute 3: Deploy to Cloudflare Workers.
Minute 4: Add the PostHog MCP server to Claude Code config.
Minute 5: Browse the site to generate events. Query them via MCP. See live data come back.
No build step. No SDK integration headaches. No GDPR consent flow. No self-hosted ClickHouse cluster. Just a script tag and a config file.
What's next
Now that the pipe is open, we can start using it. A few things on the horizon:
Content performance reports. Which blog posts get the most traffic? Which pages have the highest engagement? PostHog's trends and paths queries can answer this directly.
Custom events. Track specific interactions like form submissions, outbound link clicks, or plugin page visits. PostHog's autocapture gets us far, but named events make analysis cleaner.
Automated content reviews. Wire PostHog queries into our regular workflow. Claude checks traffic, identifies patterns, and suggests next steps as part of our site maintenance routine.
Five minutes of setup. A permanent feedback loop between the site and the tools we use to manage it. Not bad for a Saturday night.
Comments
No comments yet. Be the first to share your thoughts.
Leave a comment