Analytics

Built-in analytics tracking with Google Analytics and PostHog.

Overview

DirectoryKit supports two analytics providers out of the box:

  • Google Analytics (GA4) — Page views, events, demographics
  • PostHog — Product analytics, feature flags, session replay

Setup

Set the relevant environment variables:

# Google Analytics
NEXT_PUBLIC_GA_MEASUREMENT_ID=G-XXXXXXXXXX
 
# PostHog
NEXT_PUBLIC_POSTHOG_KEY=phc_...
NEXT_PUBLIC_POSTHOG_HOST=https://app.posthog.com

Enhanced analytics

When the analytics feature flag is enabled, DirectoryKit tracks:

  • Device type and browser
  • Country-level geographic data
  • Per-project page view events
  • Submission funnel metrics

Analytics helpers are in lib/analytics.ts.