What problem does it solve?
This Skill streamlines adding PostHog analytics to Next.js applications using the App Router, removing uncertainty about where to initialize tracking, how to identify users, and how to correlate client and server events.
Core Features & Use Cases
- Client initialization: Use instrumentation-client to initialize posthog-js for consistent client-side analytics and feature flag evaluation.
- User identification & event capture: Add posthog.identify on login and posthog.capture in user event handlers to link behavior to people.
- Server-side tracking & error capture: Use posthog-node in API routes with explicit shutdown to record server-side events and capture exceptions during authentication and critical flows.
- Use Case: Instrument a login endpoint to capture server_login on the backend, identify the user on the frontend after authentication, and capture product interactions and errors across client and server.
Quick Start
Initialize PostHog using instrumentation-client, add posthog.identify and posthog.capture on login and UI events, and add server-side captures in your app/api routes while keeping keys in environment variables.