Testing your feature flag
Contents
Once you've written your code, it's a good idea to test that each variant behaves as you'd expect. There are 4 ways you can do this:
Method 1: Assign a user a specific flag value
For boolean flags, you can roll out the flag to a specific user. For multivariate flags, you can assign a user to a specific variant by adding an optional override to your release conditions.
To do this:
Go to your feature flag.
Ensure the feature flag is enabled by checking the "Enable feature flag" box.
Add a new condition set with the condition to
email = your_email@domain.com. Set the rollout percentage for this set to 100%.- You can also target with
distinct_id equals. The value field searches persons by name, email, or distinct_id, which is useful whenemailisn't set as a person property but the user is identified. - In cases where
emailis not available (such as when your users are logged out), you can use a parameter likeutm_sourceand append?utm_source=your_variant_nameto your URL.
- You can also target with
- If it is a multivariant flag, set the optional override to the variant you want to assign these users to.
- Click "Save".
Method 2: Use posthog.featureFlags.overrideFeatureFlags()
Note: The
posthog.featureFlags.overrideFeatureFlags()method is only available in the JavaScript web and React Native SDKs.
You can add a manual override directly in your code by calling posthog.featureFlags.overrideFeatureFlags():
Method 3: Use the PostHog toolbar
Note: The PostHog toolbar is only available for the JavaScript web SDK.
The toolbar enables you to test your feature flags. You can enable, disable, or override your feature flags, and then view how your website or app changes with the new feature flags values.
To do this, click on the "Feature Flags" button in the toolbar, search for any feature flag, and click on the toggles to change its value.
Overriding feature flags will only affect your browser. You may also need to refresh the page to see how your change affect your website. It does not affect feature flags evaluation for your backend.
You can also view feature flags as another user by clicking the person icon and entering their distinct ID. This loads the flag values that user would see, displaying "Viewing as: [distinct_id]" at the bottom of the panel. Click Clear to return to your own flags.
Method 4: Use the testing tab
Every feature flag has a Testing tab where you can evaluate how the flag resolves for a specific person. To use it:
- Go to your feature flag and click the Testing tab.
- Search for and select a person.
- Optionally configure groups or a historical timestamp.
- Click Test evaluation.
The results panel shows the flag value, which condition matched, and the person properties used during evaluation.
Testing persons with multiple merged distinct IDs
Rollout and variant assignment are computed by hashing the distinct ID, so different distinct IDs that belong to the same person can bucket to different results. This is common when an anonymous session merges with a logged-in user – frontend and backend calls may evaluate against different IDs.
When the selected person has more than one merged distinct ID, the testing tab evaluates all of them at once instead of requiring you to test each one individually. Click Test all N distinct IDs (N is the count of merged IDs) and a results table shows how each ID evaluates side by side.
If the IDs produce different results, a warning banner highlights the divergence. Click any row to expand that ID's full condition analysis and person properties. If evaluating one ID errors, that error is isolated to its own row and doesn't affect the results for the other IDs.