← All help articles

Feature flags

Feature flags: conditions, rollouts and stopping flicker

Set up your flag so the right people get it, it stays the same through login, and the page never flashes the wrong version first.

Is your flag false for everyone?

Every new flag starts at 0% rollout, so it's false for everyone until you raise it. And when a flag isn't Enabled, all SDKs return false without checking release conditions. Here's how to set one up that reaches the right people.

  1. Open Feature flags and click New.

    The Feature flags list with the New button highlighted in the top-right corner
  2. Click Start from scratch.

    The template picker with the Start from scratch card highlighted
  3. Type new-share-dialog in Flag key.

    The new flag form with new-share-dialog typed in the Flag key field
  4. Under Flag type, keep Boolean. It's a simple on/off flag.

    The three flag type options, with Boolean selected and highlighted
    • Boolean: a release toggle with an optional static payload.

    • Multivariate: several variants, each with a rollout percentage, for A/B/n tests.

    • Remote config: a single payload without feature flag logic, so it has no release conditions.

  5. In Release conditions, add an Email address filter that contains @hedgebox.net, and set Rollout percentage to 100%.

    The first condition set, with an Email address filter for @hedgebox.net at 100% rollout

    A condition set matches when all its filters pass and the person falls within its rollout percentage.

  6. Click Add condition set, leave the new set without filters and set its rollout to 20%.

    Two condition sets: the team set at 100% on top, and a second set with no filters at 20%

    Condition sets are joined with OR. PostHog checks them from top to bottom and the first one that matches wins. Keep the team set first: a set for everyone at 100% at the top would mean the sets under it are never reached.

  7. Optional: open Advanced options and, under Persistence, turn on Persist flag across authentication steps. This keeps flag values the same before and after login. It needs anonymous user profiles.

    Advanced options open, with the Persist flag across authentication steps switch turned on

    Skip this step if you'll bootstrap the flag or evaluate it locally (both are explained below). Neither works on a flag that persists.

  8. Click Save.

Stop the flicker

When the page loads, the SDK fetches flags from PostHog. That takes about 100–500 ms, and during that time the flag is off. So the page shows the off version first, then switches. The fix is bootstrapping: send the flag values with the page, so the SDK has them from the start.

  1. If you turned on persistence in step 7, turn it off first. Then, on the flag, click Show implementation to open the Implementation panel, keep JavaScript, and tick Show bootstrap option.

    The implementation panel for JavaScript with the Show bootstrap option checkbox ticked

    The option is only available for JavaScript and React Native, and only when the flag doesn't persist across authentication steps.

  2. On your server, get the user's flag values with getAllFlags(distinctId) and add them to the page.

  3. Pass them to posthog.init as bootstrap, using the same distinct ID your server used.

posthog.init('<ph_project_token>', {

api_host: '<ph_client_api_host>',

bootstrap: {

distinctID: 'distinct_id_used_on_the_server',

isIdentifiedID: true,

featureFlags: serverEvaluatedFlags,

},

})

Bootstrapping only seeds flags that are on: true, or a variant name for a multivariate flag. The SDK drops false and empty values.

Can't bootstrap? Hide the element until flags have loaded, then show it from inside posthog.onFeatureFlags().

On a server: local evaluation

A server SDK with a secret API key can download your flag definitions and evaluate them itself, with no network call for each check. It fetches the definitions again every 30 seconds.

  • In Node, pass your key as secretKey (version 5.40.0 and later; earlier versions call it personalApiKey). Use a key from Project secret API keys in your project settings.

  • Until the first fetch finishes, flags return undefined, so give a fallback value.

  • Local evaluation doesn't work for flags with persistence turned on, flags that use static cohorts, or filters that use is_not_set.

  • In the app, Show implementation has a Show local evaluation option for Node.js, Python, Ruby, PHP, Go and C#/.NET.

Common problems

My flag returns false for everyone. Check the rollout percentage: new flags start at 0%, so raise it. Check that the flag is enabled. If both are fine, you may be reading the flag before flags have loaded: read it inside posthog.onFeatureFlags().

Show bootstrap option is greyed out. The flag persists across authentication steps, or the library you chose isn't JavaScript or React Native. Turn persistence off, or pick one of those two libraries.

The flag still flickers after bootstrapping. The distinct ID on the server and in the browser must be the same. If they differ, the browser can get a different value when it fetches flags. Also check what you sent: a false or empty value is dropped, so the SDK waits for PostHog as before.

The value changes after login. Turn on Persist flag across authentication steps in Advanced options. Remember that the flag then can't be bootstrapped or evaluated locally.

Watch it

Prefer to watch? The video Feature flags: conditions, rollouts and payloads (4:08) covers the same ground.

  • 0:00 Create a flag

  • 0:29 The basics

  • 1:10 Who gets it

  • 1:59 Combining condition sets

  • 2:31 Variants and payloads

  • 3:13 Stable across login