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:
Create your first experiment
Once PostHog is installed, create your experiment by going to the experiments tab and clicking New experiment.


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
andtest
variants (you can add more) - Participants: Choose between user-level or group-level experiments
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:
// Example: Testing a new checkout flowif (posthog.getFeatureFlag('new-checkout-flow') === 'test') {// Show new checkout experienceshowNewCheckout()} else {// Show current checkout (control)showCurrentCheckout()}
That's it! When you call getFeatureFlag()
, PostHog automatically tracks exposures and starts collecting data for your experiment.
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)


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


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.