How to set up feature flags on PostHog
Feature flags in PostHog allow you to control feature rollouts and A/B tests by toggling functionality without code deployments. You create flags in the PostHog dashboard and use the SDK to check flag states in your application.
Prerequisites
- PostHog account with project created
- PostHog SDK installed in your application
- Admin or write access to your PostHog project
- Basic understanding of feature flag concepts
Step-by-Step Instructions
Navigate to Feature Flags in PostHog Dashboard
Configure Basic Flag Settings
new-checkout-flow or beta-feature-enabled.Set Up Release Conditions
email contains @yourcompany.com for internal testing.Configure Multivariate Options (Optional)
control, variant-a), Name, and Rollout percentage. Ensure all percentages add up to 100%.Set Feature Flag Filters
equals, contains, or greater than to define your criteria. Multiple filters work with AND logic by default.Save and Activate Your Feature Flag
Implement Flag in Your Application Code
posthog.isFeatureEnabled('your-flag-key') or posthog.getFeatureFlag('your-flag-key') for multivariate flags. For Python: posthog.feature_enabled('your-flag-key', 'user_id'). Wrap your feature code in conditional statements based on the flag response.Monitor and Adjust Flag Performance
Common Issues & Troubleshooting
Feature flag returns undefined or null in application
Verify that PostHog is properly initialized before checking flags, ensure the flag key matches exactly (case-sensitive), and confirm the user is identified with posthog.identify('user_id'). Check network connectivity to PostHog's servers.
Flag not showing for expected users
Review your Release conditions and Filters in the PostHog dashboard. Ensure user properties are being sent correctly and match your filter criteria. Use the Debug section in PostHog to see why specific users don't match conditions.
Flag evaluation is slow or timing out
Enable local flag evaluation by calling posthog.reloadFeatureFlags() on app startup and use posthog.isFeatureEnabled() for synchronous checks. Consider using flag overrides for development environments to avoid network calls.
Cannot create or edit feature flags
Verify you have the correct permissions in your PostHog project. Contact your organization admin to grant you Editor or Admin role. Ensure you're not on a read-only plan that restricts feature flag creation.