Advanced: How to run experiments without feature flags

Last updated:

|Edit this page

You may want to run experiments without using PostHog's feature flags. There are 2 reasons why you may want to do this:

  1. You're using a different library for feature flags rather than PostHog's, and you want to run your experiment using this library.
  2. Feature flag support is not yet available in the PostHog SDK that you are using.

This doc walks you through how to set up an experiment without using PostHog's feature flags.

Step 1: Create your experiment in PostHog

Create a new experiment in the experiments tab and follow the same steps as you would when creating a regular one.

Note: Although you won't be using feature flags directly in your experiment, you still need to name your feature flag key for submitting events so PostHog can calculate your experiment results.

Step 2 (optional): Call the decide endpoint

If feature flag support is not yet available in your PostHog SDK, but you still want to leverage PostHog's feature flag infrastructure, use the PostHog API to call the decide endpoint. This enables you to calculate the feature flag value for a given user.

This step is not necessary if you are using your own feature flag library.

Step 3: Add the feature flag property to your events

In order to attribute events to their correct experiment variants, you'll need to include a $feature/experiment_feature_flag_key: variant-name property when submitting your events. You only need to do this for events that you'd like to track in your experiment.

This is similar to the same step when setting up regular experiments. The key difference is that now you need to include this property wherever you capture events for the experiment, not just server-side SDKs.

posthog.capture('event_name_of_your_goal_metric', {
"$feature/experiment-feature-flag-key": "variant-name"
})

Step 4 (optional): Send the $feature_flag_called event

This step is only required if your experiment goal metric is set to "trend". This is not required for funnel goals:

You need to capture the $feature_flag_called event. This ensures that we record which experiment variant each user was assigned to. This is also referred to as "exposure logging", and without it you would not be able to analyze your results.

You need to include two properties with this event:

  1. $feature_flag_response: this is the name of the variant the user has been assigned to e.g., "control" or "test"
  2. $feature_flag: This is the key of the feature flag in your experiment.

Important: For accurate results, you must submit this event whenever you retrieve the value of your feature flag.

posthog.capture('$feature_flag_called', {
"$feature_flag_response": "variant-name",
"$feature_flag": "feature-flag-key"
})

Questions?

Was this page useful?

Next article

Surveys overview (beta)

Surveys is currently in beta. Surveys are a great way to collect qualitative feedback from your users. Qualitative feedback enables you to gain more insight into your users' and how they view their experience with your product. With PostHog, you can target surveys based on page URL, selectors, feature flag, and user properties. Then, you can analyze the results right in PostHog too!

Read next article