# Experiment with audiences

**URL:** https://heroiclabs.com/docs/satori/concepts/experiments/experimenting-with-audiences/
**Summary:** A guide for configuring and using audience filtering in Satori
**Keywords:** experiiment guide, custom content delivery, experiment example, experiment use case, audience guide
**Categories:** satori, experiment, liveOps

---


# Experiment with audiences

In this guide you'll learn how to use audiences to create experiments that deliver custom data to clients based on their progress through the game. To accomplish this, you'll:

* [Create a custom event](#creating-a-custom-event)
* [Create an audience](#creating-the-audience)
* [Send the event from the client](#sending-the-event-from-the-client)
* [Create an experiment](#creating-an-experiment)
* [Create variants of the experiment](#examples-of-experiment-variants)

## Creating a custom event

Start by creating a custom event: `firstLevelCompleted`. This event is used to indicate to Satori that a particular identity has participated in and completed the first level of the game.

1. Navigate to the **Settings** -> **Events** screen in the Satori Console.
2. Click the **Create New Event** button.
3. For **Event Name** enter: `firstLevelCompleted`.
4. For **Type** leave it as `string`, there will be no associated value beyond the time the event occurred.

{{< screenshot src="images/pages/satori/guides/experimenting-with-audiences/custom-event.png" alt="Creating the firstLevelCompleted event" width="60%" >}}

## Creating the audience

Next create an audience that segregates players based on whether or not they've recently (in the last 7 days) completed the first level. 

1. Navigate to the **Audiences** screen.
2. Click **Create New Audience**.
3. For **Audience Name** enter `Recent-First-Level-Completers` and give it an appropriate **Description**.
4. Click **Create**.

{{< screenshot src="images/pages/satori/guides/experimenting-with-audiences/create-audience.png" alt="Creating the audience" >}}

5. On the next screen, enter the appropriate [filter](../../segmentation/understand-audiences/). This filter should check that the `firstLevelCompleted` event occurred at least once within the last 7 days.


{{< note "important" "Filtering" >}}
You can make use of the `firstLevelCompletedLastSeen` [computed property](../../segmentation/understand-player-properties/#computed-properties) that indicates when the `firstLevelCompleted` event last occurred for the identity.
{{< / note >}}

```
Now() - PropertiesComputed("firstLevelCompletedSeenLast", 0) < Duration("7d") and PropertiesComputed("firstLevelCompletedCount", 0) > 0
```

## Sending the event from the client

An identity must send a `firstLevelCompleted` event to Satori to be added to the new audience. This should be done via the client:

```csharp
var session = await client.AuthenticateAsync("<playerId>");
await client.EventAsync(session, new Satori.Event("firstLevelCompleted", DateTime.Now));
```

{{< note "important" "Audience refresh interval" >}}
By default the Satori server will refresh the identities in an audience every **10 minutes**, so an identity may not be added immediately. This can be configured with the `audience.processor_interval_sec` configuration parameter.
{{< / note >}}

## Creating an experiment

Experiments allow you to deliver variant data to identities in your audiences. They also provide you with valuable metrics that can be used to determine the success and impact of the variants you make available as part of them.

You can use experiments and variants to deliver different data values to different users in the audiences you have selected, based on a random distribution.

### Defining the metric

Create a new metric you'll use to measure the effect of the experiment. 

1. Navigate to the **Metrics** screen.
2. Click on **Create New Metric**
3. For **Name** enter `firstLevelCompletersEx1Binomial` and provide a meaningful **Description**.
4. For **Type** select `Binomial`.
5. For **Order** select `High`.

{{< screenshot src="images/pages/satori/guides/experimenting-with-audiences/create-metric.png" alt="Creating the firstLevelCompletersEx1Binomial metric" >}}

### Defining the experiment

Next we'll create an experiment that measures player engagement with various in-app purchase offers (either a booster or a coin pack) after they have recently completed the first level.

1. Navigate to the **Experiments** screen.
2. Click **Create New Experiment**.
3. For **Name** enter `firstLevelCompletersEx1` and provide a meaningful **Description**.
4. For **Audience** select the audience you created earlier: `Recent-First-Level-Completers`.
5. For **Goal Metric** select the metric you created earlier: `firstLevelCompletersEx1Binomial`.
6. Click **Create**.

{{< screenshot src="images/pages/satori/guides/experimenting-with-audiences/create-experiment.png" alt="Creating the firstLevelCompletersEx1 experiment" >}}

Once created, click the experiment to see the experiment details screen.

{{< screenshot src="images/pages/satori/guides/experimenting-with-audiences/experiment-details.png" alt="The experiment details screen" >}}

### Defining the variants

Variants define the different values that can be delivered to users as part of an experiment. One value will be chosen for each participating identity as defined by the random split distribution configured in the active phase (see next section).

This variant will define which IAP offer the player receives after completing the first level, either a Booster or a Coin Pack.

Create two new variants: `booster` and `coinPack`.

1. Click on the **Variants** tab.
2. Click **Create New Variant**.
3. For **Name** enter `Booster` and for **Value** enter `booster`.
4. Click **Create**.
5. Repeat steps 2-4 to create a second variant with the name `CoinPack` and value `coinPack`.

{{< screenshot src="images/pages/satori/guides/experimenting-with-audiences/variants.png" alt="Create the two variants" >}}

### Defining the phases

Experiments can consist of one or more phases. Phases are fixed time periods where different variants can be tested and measured against the specified metric.

We'll create a single phase for this experiment that will last for one week. This phase configures a 50/50 split between the two variant values, meaning 50% of users will receive the value `booster` and 50% will receive the value `coinPack` when they request the value of this experiment.

1. Navigate to the **Phases** tab.
2. Click **Create New Phase**.
3. For **Phase Name** enter `PhaseOne` and provide a meaningful **Description**.
4. Under **Variant**, enter a **Split %** value of `50` for both the `booster` and `coinPack` variants.
5. For **Start Date** enter the date and time you want the phase to start.
6. For **End Date** enter the date and time you want the phase to end.
7. Click **Save**.

{{< screenshot src="images/pages/satori/guides/experimenting-with-audiences/create-phase.png" alt="Creating the phase" >}}

With the phase created, the experiment is now active and players can begin receiving their assigned variant value.

### Receiving the experiment variant value

From the client, check if the user is part of this experiment and if so get the variant value.

```csharp
var result = await client.GetExperimentsAsync(session, new [] { "firstLevelCompletersEx1" });
if (result.Experiments.Any())
{
    var experiment = result.Experiments.First();

    switch (experiment.Value)
    {
        case "booster":
            // Offer the user a discount on a Booster IAP
            break;
        case "coinPack":
            // Offer the user a discount on a Coin Pack IAP
            break;
    }
}
```

### Evaluating experiment metrics

Once the phase is finished you can inspect the associated metrics by clicking into the phase from the **Phases** tab. 

Here you'll be presented with a table that represents how the users in your experiment interacted with the associated variant values and how those interactions impacted the assigned metrics.

## Examples of experiment variants

The above example demonstrates how you can offer different IAP discounts to your users. However, variants aren't limited to simple string values but can contain entire JSON objects, allowing you to get creative with what data to present to users taking part in your experiments.

### Available store items

These variants allow you to change the order that items are displayed in an In-App Store, or change the available items completely.

**Variant 1 - ConsumablesFirst**

```json
{
  "items": [
    "xpBooster",
    "energyBooster",
    "coinPackSmall",
    "coinPackLarge"
  ]
}
```

**Variant 2 - CurrenciesFirst**

```json
{
  "items": [
    "coinPackSmall",
    "coinPackLarge",
    "xpBooster",
    "energyBooster",
  ]
}
```

**Variant 3 - ExtraCurrencies**

```json
{
  "items": [
    "coinPackSmall",
    "coinPackLarge",
    "coinPackMassive",
    "xpBooster",
    "energyBooster",
  ]
}
```

### Available tournaments

These variants allow you to offer different tournaments to users.

**Variant 1 - Default**

```json
{
  "tournaments": [
    "standardLeagueWeekly",
    "proLeagueWeekly"
  ]
}
```

**Variant 2 - VIP**

```json
{
  "tournaments": [
    "standardLeagueWeekly",
    "proLeagueWeekly",
    "vipLeagueWeekly"
  ]
}
```

### UI themes

These variants allow you to change the theme of the game's UI.

**Variant 1 - Default**

```json
{
  "theme": {
    "backgroundColor": "#F5F5F5",
    "fontColor": "#333333",
    "splashImage": "default"
  }
}
```

**Variant 2 - Christmas**

```json
{
  "theme": {
    "backgroundColor": "#00FF00",
    "fontColor": "#FF0000",
    "splashImage": "xmas-trees"
  }
}
```

**Variant 3 - Halloween**

```json
{
  "theme": {
    "backgroundColor": "#000000",
    "fontColor": "#FFBF00",
    "splashImage": "pumpkins"
  }
}
```