# Run your first A/B test

> For AI agents: a documentation index is available at [/llms.txt](/llms.txt). Append `.md` to any page URL for markdown, or send `Accept: text/markdown`.

An A/B test in Statsig compares two or more variants against a control to measure which performs best on your metrics. This tutorial walks through creating and implementing your first experiment end to end, from configuring it in the console to checking it in your application code. Set one up when you want to validate a change with real production traffic before rolling it out.

By the end of this tutorial, you have:

- Created a new user-level **Experiment** in the Statsig console, with **parameters** set for a Control and Test group
- **Checked the experiment** in your application code using the **Statsig Client SDK** `getExperiment` function

You need a [Statsig account](https://console.statsig.com/sign_up) and the [Statsig Client SDK](https://docs.statsig.com/sdks/quickstart) installed in an existing application.

## Step 1: In the Statsig console

### Create an experiment

1. Log in to the Statsig console at https://console.statsig.com/ and navigate to Experiments in the left-hand navigation panel.
2. Click on the **Create** button and enter the name `Quickstart Experiment` and enter a brief hypothesis. For example, "A new homepage banner will improve engagement."
3. Click **Create**.

### Set up scorecards

In the Experiment Setup tab, fill out scorecards for the metrics you want to track. For this SDK tutorial, leave most settings at their default values.

1. In the **Hypothesis** card, enter a hypothesis for what you are testing: "Showing a homepage banner will increase user engagement, measured by daily\_stickiness."
2. In the **Primary Metrics** card, add a new metric called `daily_stickiness`.
3. Leave the **Secondary Metrics** and **Duration** settings at their default values. For more details on experiment setup, refer to [Creating an experiment](https://docs.statsig.com/experiments/create-new).

### Configure groups and parameters

By default, the experiment runs on 100% of users: Statsig assigns 50% to a Control group and 50% to a Test group.

1. In the **Groups and Parameters** card, create a parameter called `enable_banner` and select the type as `Boolean`.
2. Set `enable_banner` to `false` for the Control group and `true` for the Test group.
3. Click **Save**.
4. Select **Save** in the bottom right to finalize this experiment setup.
5. The experiment isn't live yet. To launch it, select **Start** at the top of the page. This makes production traffic eligible for the experiment.

> **Note:**
>
> You can't configure experiment parameters and groups after launching an experiment. To test in a staging environment, refer to [using environments](https://docs.statsig.com/guides/using-environments/#configuring-environments).

## Step 2: In your application code

### Check the experiment

> **Note:**
>
> This tutorial assumes you have already [installed the Statsig Client SDK](https://docs.statsig.com/sdks/quickstart) in an existing application.

Use a Statsig Client SDK to check a user's assigned experiment group and parameters in real time. The SDK changes the user's experience according to the assigned variant. In this case, fetch the value of the `enable_banner` parameter created in Step 1.

#### Check Experiment

```tsx
const quickstartExperiment = myStatsigClient.getExperiment(user, "quickstart_experiment");

// the second parameter is the default fallback value if the experiment is not found
if (quickstartExperiment.get("enable_banner", false)) {
  showBanner();
}
```

In this snippet, users assigned to the Test group see the banner. Users assigned to the Control group don't.

You don't need to [hardcode the experiment group name](https://docs.statsig.com/experiments/implementation/getting-group) ("Control" or "Test") in the code. The Statsig SDK automatically fetches the experiment configuration and returns the correct value based on the user's variant.

## Step 3: Monitor experiment diagnostics

When you run your code, the SDK calls the `showBanner()` function for users in the Test group. Navigate to your experiment in the Statsig console and select the **Diagnostics** tab to see a live log stream of checks and events from your application.

Refer to the [Diagnostics tab documentation](https://docs.statsig.com/experiments/implementation/getting-group#rules) for more information.

![Experiment Diagnostics](https://docs.statsig.com/images/guides/abn-tests/b0ab8c0e-4f13-4b2b-bf58-1f8a09d8d4a7.png)

## Step 4: Read experiment results

Within 24 hours of starting your experiment, the **Results** tab in the Statsig console shows cumulative exposures and their impact on the scorecard metrics configured in the **Setup** panel.

Here's a sample of what that looks like:

![Example experiment results](https://docs.statsig.com/images/guides/abn-tests/7e203d73-dbf9-4f27-87fb-b05269dd4173.png)

## Log custom events and metrics

In this tutorial, you used `daily_stickiness` as the primary metric. Statsig logs this metric automatically, so you don't need to log it explicitly.

To measure other events or custom metrics that occur after the experiment check, log them to Statsig. Continue to the next tutorial to learn how to log custom events and metrics with the Statsig SDK.

### Related guides

- [Initialization techniques for Statsig SDKs](https://docs.statsig.com/client/concepts/initialize)
- [Run a device-level experiment](https://docs.statsig.com/guides/first-device-level-experiment)
- [Run an experiment on custom unit ID types](https://docs.statsig.com/guides/experiment-on-custom-id-types)
- [Configure the Statsig SDK for staging environments](https://docs.statsig.com/guides/using-environments)
