The FeatureFlag resource allows you to create and manage feature flags for gradual rollouts, A/B testing, and targeted feature releases in PostHog.
Example Usage#
Basic Feature Flag#
Percentage Rollout#
Targeted Feature Flag#
Multi-Group Targeting#
A/B Test Experiment#
Feature Flag with Tags#
Complex User Targeting#
Resource Properties#
Required Arguments#
key(string): Unique identifier for the feature flag
Optional Arguments#
name(string): Display name for the feature flagactive(boolean): Whether the flag is active (default: true)filters(string): JSON string containing targeting and rollout configuration with groups, properties, and conditionsrolloutPercentage(number): Simple overall rollout percentage (0-100) - use this for basic rollouts orfiltersfor advanced targetingtags(string[]): Set of tags for the feature flag
Note: For advanced targeting with user properties and multiple groups, use the filters property. For simple percentage-based rollouts, you can use either rolloutPercentage or configure it within filters.
Attributes#
featureFlagId: Numeric feature flag IDkey: Feature flag keyactive: Current active status
Filter Structure#
The filters property accepts a JSON string with the following structure:
Best Practices#
1. Use Clear Naming#
2. Start with Small Rollouts#
3. Use Tags for Organization#
Common Use Cases#
Gradual Feature Rollout#
Start with a small percentage and gradually increase:
Beta Testing Program#
Target specific users for beta testing:
Premium Feature Gating#
Restrict features to premium users:
Troubleshooting#
Flag Not Updating#
Issue: Changes to feature flags don't take effect
Solution:
- Feature flags are cached client-side
- Wait for cache expiration or force refresh
- Verify the flag key is unique
Targeting Not Working#
Issue: Users aren't being targeted correctly
Solution:
- Check property names match exactly (case-sensitive)
- Verify property values are set on user profiles
- Use the PostHog debugger to test targeting
Invalid JSON in Filters#
Issue: Error when creating feature flag
Solution: