BetterStarter logo
BetterStarter
Docs
Features

Analytics

Enable product analytics with PostHog in BetterStarter.

Docs are in beta — content is improving rapidly. Found something missing? Open an issue on GitHub or reach out on Twitter (X).

BetterStarter includes a PostHog analytics provider that is wrapped around your app when analytics is enabled.

Enable Analytics

Open src/appConfig.ts and set:

features: {
  analytics: {
    enabled: true,
  },
}

When enabled, the app mounts AnalyticsProvider from src/features/analytics/provider.tsx.

Add Environment Variables

Set these in your .env.local file:

VITE_PUBLIC_POSTHOG_KEY=phc_xxxx
VITE_PUBLIC_POSTHOG_HOST=https://us.i.posthog.com
  • VITE_PUBLIC_POSTHOG_KEY: your PostHog project API key
  • VITE_PUBLIC_POSTHOG_HOST: your PostHog ingestion host

If analytics is enabled and these values are missing, env validation will fail at startup.

Verify Locally

  1. Start the app:
pnpm dev
  1. Open your app and navigate between pages.
  2. In PostHog, confirm events are being received for your project.

Disable Analytics

Set features.analytics.enabled to false in src/appConfig.ts.

When disabled, BetterStarter does not mount PostHog and the PostHog env vars are no longer required.

On this page