Read Loaded PostHog Feature Flags Without Exposure Events

getAllFeatureFlags() returns each loaded flag’s key, enabled state, variant, and payload from local cache, making it useful for QA and support tools without extra network requests.

Part of How to run an A/B test in PostHog.

A flag cache of toggles and variant pills feeds two readers: a product screen with a person in front of it, and a debug panel listing every flag, labelled Debug read. Only the product screen sends a blue dot up a path labelled Exposure into the experiment's counter; there is no path from the debug panel.

PostHog’s JS web SDK includes getAllFeatureFlags(), which returns every currently loaded flag in one call. Each flag includes its key, enabled state, variant, and payload. It reads the local cache, makes no network request and sends no $feature_flag_called event. (+) Use the PostHog A/B testing guide to decide when the product should record exposure.

What the Cached List Contains

The list shows this browser’s effective cached state, which can include local overrides, rather than every flag in the project. It includes loaded false evaluations with enabled: false; flags omitted from the response can be absent. An empty list does not prove that the project has no flags. (+) An override can change a variant or add a key that the server never returned; clear local overrides before checking server assignment. (+)

For a flag with no payload, payload is undefined in the web SDK and null in core, React Native and js-lite. Handle both when sharing inspection code between SDKs. (+)

Why this matters

A debug-only visit should not count as exposure to the product experiment. When an experiment counts $feature_flag_called or its $experiment_exposure copy, a normal flag read for a debug-only visitor can admit that person even though they never reached the tested experience. (+)

Use it for:

  • debug interfaces that show current flag state;
  • support tools that help investigate user-specific rollout behavior;
  • internal forwarding logic that needs loaded flags but should not affect experiment counts.

Wait for Flags, Then Inspect the Cache

These examples were tested with posthog-js 1.433.9; update the SDK if getAllFeatureFlags() is unavailable. With an initialized posthog client, register onFeatureFlags so the inspector updates when flags are loaded or refreshed. Check errorsLoading before showing the values. (+)

const stopFlagInspector = posthog.onFeatureFlags(
  (_keys, _variants, context = {}) => {
    if (context.errorsLoading) {
      console.warn('Feature flags could not be loaded.')
      return
    }

    console.table(posthog.getAllFeatureFlags())
  }
)

The table shows key, enabled state, variant and payload, including false evaluations. It reads the cached list rather than the callback’s list of enabled keys. Call stopFlagInspector() when the inspector closes to unsubscribe. (+)

Read One Flag Without Recording Exposure

For one known key, use getFeatureFlag(key, { send_event: false }). The option suppresses that read’s $feature_flag_called event; it does not make the cached value fresh or disable the SDK’s other requests. (+)

const stopSingleFlagInspector = posthog.onFeatureFlags(
  (_keys, _variants, context = {}) => {
    if (context.errorsLoading) return

    const variant = posthog.getFeatureFlag(
      '010-pricing-page-toggle-design',
      { send_event: false }
    )
    console.log('Pricing experiment variant:', variant)
  }
)

Replace the key with yours and call stopSingleFlagInspector() when finished. For a multivariate experiment, require a configured value such as control or test before treating it as an assignment. A false or unavailable value is not an assigned control participant.

How to verify the setup

Check all of the following:

  • the returned list includes the expected flag keys;
  • enabled state, variant, and payload values match what the user should receive;
  • no network request is fired just to read the list;
  • no $feature_flag_called event is emitted from the inspection action;
  • your experiment exposure logic still depends on actual product experience, not admin-only flag reads.

Watch network requests and captured events while triggering only the inspection action. The SDK can load flags during initialization or refresh them separately; distinguish those requests from a cache read. Then exercise the actual product path and verify that its chosen exposure still arrives with the correct variant.

Keep Product Exposure at the Tested Surface

Repeated events for the same person and variant do not multiply unique participants; the error is including people who had no opportunity to experience the change. (+)

We prefer a semantic event at the first user-visible treatment boundary when flag assignment happens earlier. Send it at the same point in control and treatment, with the assigned variant in $feature/<flag-key>, and select it under Edit exposure criteria → Custom event. (+) A silent read used to display the real product must have that separate exposure path; otherwise the experiment can miss the participant.

Common mistakes to avoid

  • Treating flag retrieval as the same thing as experiment exposure.
  • Calling the method before flags are actually loaded.
  • Using internal debug reads to justify business conclusions about rollout coverage.
  • Mistaking a local override for the server’s assignment.
  • Treating an immediate cached callback as a fresh result while an identity-change refresh is pending.

For the broader assignment check, use the pre-launch QA procedure.

Frequently asked questions

Does getAllFeatureFlags() show every flag in my project?

No. It shows the evaluations currently loaded for this client. A flag absent from that response can be missing from the list, including a globally inactive flag. Use it to inspect this browser’s state, not to inventory project configuration. (+)

How do I refresh the values?

Call posthog.reloadFeatureFlags() and read the updated list in your onFeatureFlags callback. That refresh makes a request; getAllFeatureFlags() itself does not. Keep the listener active while changing identity: registering it can immediately show a previously loaded snapshot before a pending refresh finishes. (+)

Should I suppress events on the flag read that renders the product?

Use a silent read when a separate, correctly timed exposure event records the participant. If the experiment counts $feature_flag_called or its $experiment_exposure copy and the read is at the tested surface, suppressing it removes that exposure path. Choose the exposure definition first; the exposure step shows the two arrangements.

About the author

Moein Heshmati

Moein Heshmati

Moein Heshmati leads data systems and engineering at 99Ways, specializing in analytics engineering, tracking, and experimentation systems. He writes about data quality, measurement, technical implementation, and reliable experimentation.

More articles

Where is growth getting stuck?

Book a free 45-minute call with Iman. Show him your site and, if you can, your analytics. You’ll leave knowing what to fix or test first.

Book a free call