# Email AB Testing with Customer.io

Statsig and Customer.io together run A/B tests on your email content: Customer.io splits recipients into groups and sends exposure events to Statsig, which then compares open, click, and conversion metrics across variants. Use this setup to find the best-performing email template and measure its impact on downstream product metrics.

{% callout type="info" %}
This guide assumes you have an existing Statsig account. If you don't have one, create a free account at https://statsig.com/signup
{% /callout %}

### Step 1: Create an experiment

Create a new Experiment in the Statsig console. Enter a name and leave the remaining fields at their default values.

{% figure %}
![Experiment creation interface](https://docs.statsig.com/images/guides/sendgrid-email-abtest/210731384-8bbfc1e1-076c-4ae3-959a-ef1507801e71.png)
{% /figure %}

### Step 2: Start the experiment

An experiment requires at least one parameter before it can start. Add a placeholder parameter now.

{% figure %}
![Experiment parameter configuration](https://docs.statsig.com/images/guides/sendgrid-email-abtest/210316935-99f13616-c412-47c1-b9ab-99b90462805e.png)
{% /figure %}

{% figure %}
![Experiment setup completion](https://docs.statsig.com/images/guides/sendgrid-email-abtest/210731687-0883c356-5cef-458d-a6aa-bfde9ad36f8b.png)
{% /figure %}

Save the experiment setup and select **Start**.

{% figure %}
![Experiment start confirmation](https://docs.statsig.com/images/guides/sendgrid-email-abtest/210731969-decf481a-b6a2-41ee-b1c1-6b917bb18fab.png)
{% /figure %}

Copy the **Experiment Name**. You need it in the next step.

{% figure %}
![Experiment name copy interface](https://docs.statsig.com/images/guides/sendgrid-email-abtest/210732298-34c0e1f4-6485-425b-af07-fa535ad86396.png)
{% /figure %}

### Step 3: Set up exposure webhooks

In your Customer.io campaign, create a **Random Cohort Branch** with a flow similar to the following:

{% figure %}
![Customer.io random cohort branch setup](https://docs.statsig.com/images/guides/customer-io-email-abtest/211873572-0966ae02-4a41-40a1-b55d-19378f1d0b98.png)
{% /figure %}

In the Webhook actions, add a POST request similar to the following, with your API key and experiment name filled in:

{% figure %}
![Webhook configuration for experiment exposure](https://docs.statsig.com/images/guides/customer-io-email-abtest/211873593-d48ed161-2a55-4099-8f06-7835ee82d011.png)
{% /figure %}

Pass in any other custom IDs and user attributes inside the post body.

For each webhook, expose the correct group to attribute the branch to. The webhook shown above exposes the "Control" group.

{% figure %}
![Experiment group exposure configuration](https://docs.statsig.com/images/guides/customer-io-email-abtest/211873585-1b2da267-cd72-4c29-acde-d1888500ac36.png)
{% /figure %}

In Statsig, you now have exposures for each of your experiment groups.

## Holdouts

To use Statsig Holdouts with Customer.io, identify users who are part of a holdout using Customer.io's identify function: https://customer.io/docs/sdk/ios/identify/

When you call Customer.io's identify method, check a Statsig holdout gate and add an attribute to the user to mark them as being in a holdout.

In your campaign, create a True/False branch to check whether a user is in the holdout.

{% figure %}
![Customer.io holdout branch configuration](https://docs.statsig.com/images/guides/customer-io-email-abtest/211888584-a164d8bf-0d78-4a6b-86ab-ea336fd2bc3a.png)
{% /figure %}
