Published
PostHog
In brief: Give TestChimp a PostHog personal API key with only the feature_flag:read scope, plus your project ID. Sync reads feature flags, multivariate variants and rollout percentages for the project.
The PostHog integration reads the feature flags of one PostHog project, so feature flag coverage can list every variant and show the ones no test ran.
What you need
- A PostHog personal API key. Create it in PostHog under your account settings, in Personal API keys. Give it only the
feature_flag:readscope, and limit it to the project TestChimp will read. - The project ID: the number in your PostHog project URL and project settings.
TestChimp never writes to PostHog, so the key needs no write scopes. Do not use the project API key that your app sends events with; that key cannot read the flags API.
Configure TestChimp
An org admin opens Project settings → Integrations → Feature flags:
- Pick PostHog.
- Enter the Personal API key (it starts with
phx_). - Enter the Project ID.
- If your project is on PostHog EU Cloud, set the base URL to
https://eu.posthog.com. The default ishttps://us.posthog.com. - Choose Test connection, then save. The first sync runs right away.
The base URL must use HTTPS on a posthog.com host. Self-hosted PostHog on your own domain is not supported yet.
How the environment is mapped
The PostHog flags API has no environments, so a PostHog connection has one environment, shown as Project. If you use separate PostHog projects for test and production, connect the project your tests run against.
- Multivariate flags: each variant key is an arm, with its rollout percentage.
- Boolean flags: the arms are
trueandfalse. A rollout is shown only when the flag has exactly one release condition with no property filters; thentruegets that condition's percentage andfalsethe rest.
What sync reads
- Feature flags in the project: key, name, tags, archived state, and the release conditions and multivariate variants.
- Deleted flags are skipped. Flags no longer in PostHog are marked archived in TestChimp, not deleted.
Sync runs when you save the connection, once a day, and when you choose Sync now.
Capture in your app
The connection supplies the catalog. To record which variants your tests run, add @testchimp/flags to your app:
- Browser: call
instrumentPostHog(posthog)once afterposthog.init. Lookups withsend_event: falseare not recorded. - Node backend:
instrumentPostHogNode(posthogClient)coversgetFeatureFlag,isFeatureEnabledandevaluateFlags. On a multivariate flag,isFeatureEnabledanswerstruewithout naming the variant, so it counts no arm: usegetFeatureFlagorevaluateFlagsthere. Add the collection middleware and setTESTCHIMP_FLAG_ECHO=1in test environments.
Tests that mock PostHog's /decide or /flags endpoints with route.fulfill are recorded as forced. See Setup.
Troubleshooting
- 401 or 403: check that the key has the
feature_flag:readscope and access to this project. - 404 on test: check the project ID and the base URL (US or EU Cloud).
- No rollout on a boolean flag: the flag has more than one release condition, or property filters. Coverage still lists both arms.
Rotation
Create a new personal API key with the same scope, edit the connection, paste it in, test and save. Leaving the key field blank keeps the stored one. Then delete the old key in PostHog.
FAQ
Which PostHog key should I use?
A personal API key with only the feature_flag:read scope, limited to the project TestChimp reads. Not the project API key your app sends events with.
Is PostHog EU Cloud supported?
Yes. Set the base URL to https://eu.posthog.com. Self-hosted PostHog on your own domain is not supported yet.