Creating an experiment

Last updated:

|Edit this page

To create a new experiment, go to the A/B testing tab in the PostHog app, and click on the New experiment button in the top right.

This presents you with a form where you can complete the details of your new experiment:

How to create an experiment in PostHog

Here's a breakdown of each field in the form:

Feature flag key

Each experiment is backed by a feature flag. In your code, you use this feature flag key to check which experiment variant the user has been assigned to.

The feature flag will be created for you automatically. Therefore, you must add a feature flag key which does not exist yet.

Advanced: It's possible to create experiments without using PostHog's feature flags (for example, if you're using a different third-party library for feature flags). For more info, read our docs on implementing experiments without feature flags.

Experiment variants

By default, all experiments have a control and test variant. You can add more variants if you like.

Participants are automatically split equally between variants. If you want assign specific users to a specific variant, see the section below on distribution and release conditions.

Participant type

By default, PostHog runs experiments at a user-level. This means that participants are assigned to a variant based on their person properties. However, if you've created groups, you can also run group-targeted experiments. This will test how a change affects your product at a group-level by providing the same variant to every member of a group.

Experiment goal

Setting your goal metric enables PostHog to calculate the impact of your experiment and if your results are statistically significant. You can select between a trend or conversion funnel goal.

Distribution and release conditions

By default, your experiment will target 100% of participants. If you want to target a more specific set of participants or change the rollout percentage, you need to do this by changing the release conditions for the feature flag used by your experiment.

You can do this by clicking on the Manage distribution or Manage release conditions button after saving your experiment as a draft.

Note: If you select a server-side event, you may see a warning that no feature flag information can be detected with the event. To resolve this issue, see step 2 of adding your experiment code and how to submit feature flag information with your events.

Experiment goal warning

Questions?

Was this page useful?

Next article

Adding experiment code

Once you've created your experiment in PostHog, the next step is to add your code: Step 1: Fetch the feature flag In your experiment, each user is randomly assigned to a variant (usually either 'control' or 'test'). To check which variant a user has been assigned to, fetch the experiment feature flag. You can then customize their experience based on the value in the feature flag: Since feature flags are not supported yet in our Java, Rust, and Elixir SDKs, to run an experiment using these SDKs…

Read next article