Skip to main content

Analytics Config

Google Analytics, PostHog, and built-in enhanced analytics.

File: config/analytics.config.ts

The config is almost entirely driven by env vars — add a key, the corresponding tracker turns on. Remove the key, it goes silent.

Providers

Google Analytics 4

  1. Go to analytics.google.comAdmin → create a Property
  2. Add a Data Stream for your site → copy the Measurement ID (G-XXXXXXXXXX)
  3. Add to .env.local:
NEXT_PUBLIC_GA_MEASUREMENT_ID=G-XXXXXXXXXX

Restart the dev server. The GA script auto-loads in <head>.

GA4 Measurement ID in the admin

PostHog

  1. Sign up at posthog.com → create a project
  2. Project SettingsProject API Key (starts with phc_)
  3. Add to .env.local:
NEXT_PUBLIC_POSTHOG_KEY=phc_...
NEXT_PUBLIC_POSTHOG_HOST=https://app.posthog.com
# (or https://eu.posthog.com for EU region)

PostHog Project API Key in settings

Google Search Console verification

For SEO validation:

NEXT_PUBLIC_GOOGLE_VERIFICATION=your-verification-token

The site adds the meta tag automatically.

Built-in "enhanced" analytics

When the analytics feature flag is true (default), the app also writes analytics events to your own Supabase database — no third party involved. Tracked:

  • Device type, browser, OS
  • Country (from IP, no personal data)
  • Page views
  • Per-project views
  • Custom events

Results show up in /admin/analytics:

/admin/analytics dashboard with charts

This is independent of GA / PostHog — use it when you want fast, local, non-cookie analytics.

Turn it off by setting analytics: false in features.config.ts.

Mixing them

All three (GA, PostHog, enhanced) can run at the same time. Each one is useful for different things:

ToolBest for
GA4SEO reporting, traffic sources
PostHogFunnels, session replay, feature flags
Built-inFast admin dashboards, historical DB-backed data

See also

  • Analytics — what events the built-in system tracks