# Getting started with experiments - Docs

## 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:

-   [![](https://res.cloudinary.com/dmukukwp6/image/upload/dotnet_logo_7e446176f2.svg).NET](/docs/experiments/installation/dotnet.md)

-   [![](https://res.cloudinary.com/dmukukwp6/image/upload/Android_robot_bec2fb7318.svg)Android](/docs/experiments/installation/android.md)

-   [![](https://res.cloudinary.com/dmukukwp6/image/upload/posthog.com/contents/docs/integrate/frameworks/angular.svg)Angular](/docs/experiments/installation/angular.md)

-   [![](https://res.cloudinary.com/dmukukwp6/image/upload/astro_icon_dark_23a13977ad.svg)Astro](/docs/experiments/installation/astro.md)

-   [![](https://res.cloudinary.com/dmukukwp6/image/upload/posthog.com/contents/docs/integrate/frameworks/bubble.svg)Bubble](/docs/experiments/installation/bubble.md)

-   [![](https://res.cloudinary.com/dmukukwp6/image/upload/posthog.com/contents/docs/integrate/frameworks/django.svg)Django](/docs/experiments/installation/django.md)

-   [![](https://res.cloudinary.com/dmukukwp6/image/upload/posthog.com/contents/images/docs/integrate/flutter.svg)Flutter](/docs/experiments/installation/flutter.md)

-   [![](https://res.cloudinary.com/dmukukwp6/image/upload/framer_logo_icon_169149_d72b90e48e.svg)Framer](/docs/experiments/installation/framer.md)

-   [![](https://res.cloudinary.com/dmukukwp6/image/upload/posthog.com/contents/images/docs/integrate/go.svg)Go](/docs/experiments/installation/go.md)

-   [![](https://res.cloudinary.com/dmukukwp6/image/upload/posthog.com/contents/images/docs/integrate/ios.svg)iOS](/docs/experiments/installation/ios.md)

-   [![](https://res.cloudinary.com/dmukukwp6/image/upload/posthog.com/contents/docs/integrate/frameworks/laravel.svg)Laravel](/docs/experiments/installation/laravel.md)

-   [![](https://res.cloudinary.com/dmukukwp6/image/upload/posthog.com/contents/images/docs/integrate/frameworks/nextjs.svg)Next.js](/docs/experiments/installation/nextjs.md)

-   [![](https://res.cloudinary.com/dmukukwp6/image/upload/posthog.com/contents/images/docs/integrate/nodejs.svg)Node.js](/docs/experiments/installation/node.md)

-   [![](https://res.cloudinary.com/dmukukwp6/image/upload/posthog.com/contents/images/docs/integrate/frameworks/nuxt.svg)Nuxt](/docs/experiments/installation/nuxt.md)

-   [![](https://res.cloudinary.com/dmukukwp6/image/upload/posthog.com/contents/images/docs/integrate/php.svg)PHP](/docs/experiments/installation/php.md)

-   [![](https://res.cloudinary.com/dmukukwp6/image/upload/posthog.com/contents/images/docs/integrate/python.svg)Python](/docs/experiments/installation/python.md)

-   [![](https://res.cloudinary.com/dmukukwp6/image/upload/posthog.com/contents/images/docs/integrate/react.svg)React](/docs/experiments/installation/react.md)

-   [![](https://res.cloudinary.com/dmukukwp6/image/upload/posthog.com/contents/images/docs/integrate/react.svg)React Native](/docs/experiments/installation/react-native.md)

-   [![](https://res.cloudinary.com/dmukukwp6/image/upload/rr_logo_light_970950178e.svg)React Router](/docs/experiments/installation/react-router.md)

-   [![](https://res.cloudinary.com/dmukukwp6/image/upload/remix_letter_glowing_49183adce2.svg)Remix](/docs/experiments/installation/remix.md)

-   [![](https://res.cloudinary.com/dmukukwp6/image/upload/posthog.com/contents/images/docs/integrate/ruby.svg)Ruby](/docs/experiments/installation/ruby.md)

-   [![](https://res.cloudinary.com/dmukukwp6/image/upload/posthog.com/contents/images/docs/integrate/rust.svg)Rust](/docs/experiments/installation/rust.md)

-   [![](https://res.cloudinary.com/dmukukwp6/image/upload/posthog.com/contents/docs/integrate/frameworks/svelte.svg)Svelte](/docs/experiments/installation/svelte.md)

-   [![](https://res.cloudinary.com/dmukukwp6/image/upload/posthog.com/contents/images/docs/integrate/frameworks/vue.svg)Vue](/docs/experiments/installation/vue.md)

-   [![](https://res.cloudinary.com/dmukukwp6/image/upload/posthog.com/contents/images/docs/integrate/js.svg)Web](/docs/experiments/installation/web.md)

-   [![](https://res.cloudinary.com/dmukukwp6/image/upload/webflow_63b6678590.svg)Webflow](/docs/experiments/installation/webflow.md)

[Install PostHog SDK](/docs/experiments/installation.md)

## Create your first experiment

Once PostHog is installed, create your experiment by going to the [Experiments](https://app.posthog.com/experiments) section and clicking **New experiment**.

This opens a guided creation wizard that walks you through three steps:

1.  **Description** – Name your experiment, write a hypothesis, and set the feature flag key
2.  **Variant rollout** – Configure variants, split percentages, and rollout percentage
3.  **Analytics** – Set inclusion criteria and add metrics to measure results

When you're done, click **Save as draft** on the final step. You can launch the experiment from its detail page after saving.

![How to create an experiment in PostHog](https://res.cloudinary.com/dmukukwp6/image/upload/q_auto,f_auto/wizard_step_1_light_c7e16a15d1.png)![How to create an experiment in PostHog](https://res.cloudinary.com/dmukukwp6/image/upload/q_auto,f_auto/wizard_step_1_dark_ddc4372ce6.png)

The following section goes into more detail on each step.

[Create an experiment](/docs/experiments/creating-an-experiment.md)

## 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

PostHog AI

```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](/docs/experiments/adding-experiment-code.md)

## Add metrics

Metrics define how you measure the experiment's impact. You can add them in step 3 of the creation wizard, after saving the experiment, or even after launching the experiment.

There are two categories:

-   **Primary metrics** – The main measurements that determine whether your experiment succeeded.
-   **Secondary metrics** – Additional measurements to monitor for side effects or supplementary insights.

You can create metrics directly or reuse **shared metrics** defined at the project level. We recommend defining your metrics upfront to avoid biasing your analysis.

[Learn about experiment metrics](/docs/experiments/metrics.md)

## 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](https://res.cloudinary.com/dmukukwp6/image/upload/Clean_Shot_2025_01_22_at_10_05_11_2f5017a50c.png)![Viewing experiment results](https://res.cloudinary.com/dmukukwp6/image/upload/Clean_Shot_2025_01_22_at_10_05_31_0e81dd9c8e.png)

When your experiment reaches significance, you can end the experiment and choose a variant to keep using the **End experiment** 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](/experiments.md#pricing) for more up-to-date details

---

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

[Create your first experiment](/docs/experiments/installation.md)

1/7

[**Install PostHog SDK** ***Required***](#quest-item-install-posthog-sdk)[**Create your first experiment** ***Required***](#quest-item-create-your-first-experiment)[**Add experiment code** ***Required***](#quest-item-add-experiment-code)[**Add metrics** ***Required***](#quest-item-add-metrics)[**Monitor and analyze results** ***Recommended***](#quest-item-monitor-and-analyze-results)[**Advanced features** ***Optional***](#quest-item-advanced-features)[**Use for free** ***Free 1M requests/mo***](#quest-item-use-for-free)

**Install PostHog SDK**

***Required***

### Community questions

Ask a question

### Was this page useful?

HelpfulCould be better