Skip to main content
PostHog feature flags reuse your PostHog project for boolean flags, multivariate experiments, and user targeting — normalized into Refract’s CachedFeatureFlag shape.

Why

If you already run PostHog for analytics, feature flags can share the same API key and ingestion host. The backend evaluates flags server-side with user and organization context attached as person properties.

Setup

  1. Add tooling-feature-flags-posthog to apps/backend/package.json (already present in the template).
  2. Run make deps-install.
  3. Configure production:
  1. Set POSTHOG_API_KEY (and optional POSTHOG_HOST) in the deployment environment.

Evaluation context

FeatureFlagContext maps to PostHog person properties:
  • userId → distinct id (falls back to anonymous)
  • organizationId, environment, and attributes → person properties

Gotchas

  • Multivariate flag values are exposed through getVariant() with enabled: true.
  • Boolean false flags remain in the normalized cache with enabled: false.
  • Shared cache TTL is controlled by cacheMs; request caching is always on for HTTP traffic.

What’s next?