Skip to Content

PostHog

PostHog provides analytics, feature flags, and session replay for your app.

Setup

1. Create a PostHog Account

  1. Sign up at posthog.com 
  2. Create a new project
  3. Copy your Project API Key from Project Settings

2. Configure Environment Variables

Add to your .env file:

EXPO_PUBLIC_POSTHOG_KEY=phc_xxxxxxxxxxxx EXPO_PUBLIC_POSTHOG_HOST=https://us.i.posthog.com

Use https://eu.i.posthog.com for EU cloud hosting.

3. Configuration File

The PostHog config is in config/posthog.js:

export const posthogConfig = { apiKey: process.env.EXPO_PUBLIC_POSTHOG_KEY, host: process.env.EXPO_PUBLIC_POSTHOG_HOST || 'https://us.i.posthog.com', debug: __DEV__, };

Available Methods

The usePostHogAnalytics() hook provides:

MethodDescription
capture(event, properties)Track a custom event
identify(userId, properties)Identify a user
reset()Reset user identity (use on logout)
isFeatureEnabled(flag)Check if a feature flag is enabled
getFeatureFlag(flag)Get feature flag value
reloadFeatureFlags()Reload flags from server
isConfiguredWhether PostHog is configured

Session Replay

PostHog supports session replay to see user interactions. This requires a development build (not Expo Go).

Enable in your provider options:

<RNPostHogProvider apiKey={apiKey} options={{ host, enableSessionReplay: true, }} >