PostHog Integration
PostHog is a feature-rich, open-source analytics tool. In addition to basic analytics, it also supports session replay, which can be very helpful for understanding user behavior.
Good to know
- NEXTY.DEV disables tracking scripts in development to avoid polluting analytics data.
- To verify locally, open
app/[locale]/layout.tsxandcomponents/tracking/PostHogProvider.tsxand remove theprocess.env.NODE_ENV === "development"check.- If you don't need local verification, just set the production environment variables and the scripts will be enabled automatically.
Configuration Steps
Step 1: Create a PostHog account
- Visit PostHog and register an account
- Create a new project
Step 2: Get API Key
- In the PostHog dashboard, click Settings
- Copy your Project API Key
- Note your Host URL
Step 3: Set environment variables
In your .env.local or environment variable configuration, add:
.env
NEXT_PUBLIC_POSTHOG_KEY=phc_your_project_api_key_here
NEXT_PUBLIC_POSTHOG_HOST=your_posthog_host_url