Getting started with experiments

Last updated:

|

Install PostHog SDK

Experiments enable you to test the impact of product changes and understand how they affect your users' behavior. For example, testing different onboarding flows, app designs, or pricing strategies.

The first step is to install PostHog with the library you want to run experiments in:

Install PostHog SDK

Create your first experiment

Once PostHog is installed, create your experiment by going to the experiments tab and clicking New experiment.

How to create an experiment in PostHog

Fill in the experiment details:

  • Feature flag key: This will be used in your code to check which variant a user gets
  • Variants: By default, you get control and test variants (you can add more)
  • Participants: Choose between user-level or group-level experiments
Create an experiment

Add experiment code

With your experiment created, add the code to check which variant users see. Simply fetch the feature flag and customize the experience based on its value:

JavaScript
// Example: Testing a new checkout flow
if (posthog.getFeatureFlag('new-checkout-flow') === 'test') {
// Show new checkout experience
showNewCheckout()
} else {
// Show current checkout (control)
showCurrentCheckout()
}

That's it! When you call getFeatureFlag(), PostHog automatically tracks exposures and starts collecting data for your experiment.

View code examples for all SDKs

Add metrics

Before launching, add at least one metric to measure your experiment's success. Go to your experiment and click Add metric in the Primary metrics section.

Choose from:

  • Funnel metrics: For conversion rates (e.g., signup → purchase)
  • Mean metrics: For averages and sums (e.g., revenue per user)
  • Ratio metrics: For custom calculations (e.g., revenue per order)
Primary metrics in PostHog experiments
Learn about experiment metrics

Monitor and analyze results

Once your experiment is running, monitor the results in real-time. PostHog shows:

  • Statistical significance: Whether your results are reliable
  • Win probability: The likelihood each variant is better
  • Confidence intervals: The range of possible effect sizes
Viewing experiment results

When your experiment reaches significance, you can ship the winning variant with confidence using the Ship a variant button.

Advanced features

Take your experiments to the next level with advanced PostHog features:

Session replay

See exactly what users experienced in each variant with session recordings tied to your experiment results.

Feature flags

Target specific user segments, implement gradual rollouts, or run experiments on user groups instead of individuals.

Advanced experimentation

Choose between Bayesian and frequentist statistical approaches, handle multiple variants, and configure outlier detection.

Use for free

PostHog's experiments is built to be cost-effective by default, with a generous free tier and transparent usage-based pricing. Our generous free tier means more than 90% of companies use PostHog for free.

Experiments are billed with feature flags requests.

TL;DR 💸

  • No credit card required to start
  • First 1 million feature flag requests per month are free
  • Above 1 million we have usage-based pricing starting at $0.0001/request with discounts as volume increases
  • Set billing limits to avoid surprise charges
  • See our pricing page for more up-to-date details

That's it! You're ready to start running successful experiments.

Create your first experiment

Questions? Ask Max AI.

It's easier than reading through 793 pages of documentation

Community questions

Was this page useful?

Next article

A/B testing installation

A/B testing enables you to test the impact of product changes and understand how they affect your users' behaviour. For example: How changes to your onboarding flow affect your signup rate. If different designs of your app's dashboard increase user engagement and retention. The impact a free trial period versus money-back guarantee to determine which results in more customers. A/B tests are also referred to as "experiments", and this is how we refer to them in the PostHog app. To start using A/B…

Read next article