# Next.js boilerplate with PostHog

> Product analytics with a typed event catalogue. The browser client captures page views on App Router navigations. The server client flushes with `after()`, so events go out before the serverless function exits. Identity helpers refuse to send PII. An /ingest reverse proxy sends events through your own domain, so fewer get blocked.

Product analytics, session replay, feature flags and experiments behind one key.

- **Category:** Analytics
- **Pricing:** Free every month, card or not: 1M analytics events, 5,000 session recordings and 1M feature flag requests. Past that, each product bills by usage, and you can set a billing limit per product. Self-hosting exists, but PostHog does not support it.
- **Best for:** Product teams who want funnels, retention, replay, flags, experiments and surveys on one event stream. One stream means one definition of "active user", not four. Good for early-stage teams, and SQL access answers the questions the dashboards cannot.
- **Vendor docs:** https://posthog.com/docs

## Trade-offs

- The client bundle is not free. `posthog-js` with autocapture, replay and flags is a large third-party script, loaded on every page. Lazy loading and turning autocapture off are the two levers that matter.
- Ad blockers block it by default. PostHog says a reverse proxy typically lifts event capture by 10 to 30%, which is why this battery installs one.
- Autocapture cuts both ways. It gives you data before you instrument anything, and it fills your project with `$autocapture` events nobody can explain six months later. This battery captures named events on purpose and keeps autocapture as a backstop.
- Anonymous events are cheap, identified events are not. Person profiles drive the analytics price, which is why the client runs with `person_profiles: "identified_only"`.
- It is a warehouse of behaviour, not a source of truth for money. Revenue, entitlements and anything you would argue with a customer about belong in your database. PostHog is where you ask questions about them.

## Known fixes it ships

- [Ad blockers eat a third of your analytics: proxy ingestion through your own domain](https://agenticboilerplate.com/cookbook/posthog/ad-blocker-reverse-proxy): Blockers match on hostnames, not behaviour. A first-party /ingest route handler forwards events to PostHog server-side and recovers most of the missing traffic.
- [Event names that still make sense in twelve months](https://agenticboilerplate.com/cookbook/posthog/event-naming-that-survives): Why analytics projects rot into five spellings of "signup", and the object_verb convention plus a typed catalogue that stops it.
- [Feature flags without the flicker](https://agenticboilerplate.com/cookbook/posthog/feature-flags-without-flicker): Client-side flags render the control experience first and swap it a beat later. Evaluate on the server, pass the decision down, and keep a bootstrap for the client hooks.
- [The identify race that empties your signup funnel](https://agenticboilerplate.com/cookbook/posthog/identify-race-conditions): Events fired before identify() stay on the anonymous profile forever. Here is why the merge is not retroactive, and the ordering that fixes it.
- [Server events versus client events, and when each one lies](https://agenticboilerplate.com/cookbook/posthog/server-vs-client-events): A browser event is a claim, a server event is a record. Which side to fire from, why serverless drops events without after(), and how to keep the two from double-counting.

## Generate it

[Build a repo with PostHog](https://agenticboilerplate.com/build?b=posthog)

---

Agentic Boilerplate: A Next.js repo your agent already knows. Free during launch, then $99 once.

- Site map for agents: https://agenticboilerplate.com/llms.txt
- Public API: https://agenticboilerplate.com/openapi.json
- Contact: agenticstudio@gmail.com
