PostHog Analytics
Cookieless, privacy-friendly analytics with native MCP support for Claude Code.
What it does
PostHog provides product analytics (pageviews, funnels, retention, paths) with an official MCP server. That means Claude Code can query traffic data in the same conversation where it's writing code and managing content. No dashboard tab. No copy-pasting numbers. Just tool calls returning structured data.
We run it in cookieless mode: persistence: 'memory' and person_profiles: 'identified_only'. No cookies, no localStorage, no consent banner. Aggregate traffic data without the privacy overhead.
Why PostHog
- MCP server with ~27 tools. Trends, funnels, paths, retention, lifecycle queries, all as tool calls.
- True cookieless tracking. No data written to visitor devices. No GDPR consent flow needed for aggregate analytics.
- Free tier of 1M events/month. More than enough for content sites.
- Autocapture. Pageviews, page leaves, clicks, and form interactions tracked automatically. Named events available when you need finer control.
Setup
Add the PostHog snippet to your Astro layout's <head>. The key configuration for cookieless mode:
posthog.init('phc_...token...', {
api_host: 'https://us.i.posthog.com',
person_profiles: 'identified_only',
persistence: 'memory',
}); Then add the PostHog MCP server to your Claude Code configuration:
// In Claude Code MCP config:
{
"posthog": {
"command": "npx",
"args": ["-y", "@anthropic-ai/posthog-mcp-server"],
"env": {
"POSTHOG_API_KEY": "phk_...",
"POSTHOG_PROJECT_ID": "12345"
}
}
} What Claude Code can do with it
- Query which pages get the most traffic
- Check traffic trends over time for specific URLs
- Run funnel analysis (e.g., homepage to contact form submission)
- Identify top referral sources
- Spot pages with high bounce rates
- Correlate content publishes with traffic changes
Cost
PostHog Cloud free tier: 1 million events per month, unlimited team members. No credit card required. For a content site or small portfolio, you're unlikely to hit the ceiling.