← Back to Docs
Recipe

PostHog Setup

Wire Meridian analytics into PostHog in under five minutes.

1. Install the SDK

npm install posthog-js

2. Initialize in _app.tsx

import posthog from 'posthog-js'

if (typeof window !== 'undefined') {
  posthog.init('<YOUR_API_KEY>', {
    api_host: 'https://us.i.posthog.com',
    loaded: (ph) => {
      if (process.env.NODE_ENV === 'development') ph.opt_out_capturing()
    },
  })
}

3. Track a custom event

import posthog from 'posthog-js'

posthog.capture('license_activated', {
  plan: 'pro',
  fingerprint: licenseFingerprint,
})

4. Verify

Open your PostHog dashboard and check the live events feed. You should seelicense_activatedevents flowing within seconds. Use feature flags to gate premium features without redeploying.

Pro tip: Setposthog.opt_out_capturing()in dev to keep your dashboard clean. Meridian's loader already fingerprints hardware — pipe that ID into$set_once for durable user profiles.