> ## Documentation Index
> Fetch the complete documentation index at: https://launchdarkly-preview.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Example experiments

> This guide provides examples of experiments you can build in LaunchDarkly.

> For the complete documentation index, see [llms.txt](/llms.txt). For the full documentation snapshot, see [llms-full.txt](/llms-full.txt).

## Overview

This guide provides examples of experiments you can build in LaunchDarkly.

The three examples include:

* [Determining the best time to ask customers to opt-in to notifications](#example-1-notifications-opt-in)
* [Deciding which third-party libraries to use](#example-2-third-party-library-assessment)
* [Finding out if longer trial times results in higher conversions to paid accounts](#example-3-trial-account-conversions)

## Example 1: Notifications opt-in

When a customer downloads your app onto their phone or tablet for the first time, it may ask them to opt-in to notifications from the app. Some apps ask the customer to opt-in right away, and others wait until the customer has interacted with your app for a certain amount of time before asking.

Asking the customer to opt-in right away may feel premature, as the customer might not know yet if they like your app enough to want notifications. However, waiting too long may also result in fewer opt-ins, as the customer may have become comfortable using your app without notifications.

The Apple app store allows apps to ask customers to opt-in only once. This means it's important to time your one opt-in request at a point when the customer is most likely to opt-in. You can use Experimentation to find out when this time is.

### Hypothesis

To begin, create a hypothesis for your experiment. Here is an example:> If we prompt a customer to opt-in to notifications on the fifth time they open our app, customers will opt-in to notifications significantly more often than those who are prompted the first time they open our app, and slightly more often than those who are prompted on the tenth time they open our app. This is because they will have had more time to use the product, but won't have gotten used to using it without notifications.

### Sample size

Next, determine the sample size you need for your experiment. If you are running a [frequentist](/guides/experimentation/bayesian-frequentist) experiment, we recommend you use LaunchDarkly's [sample size calculator](https://launchdarkly.com/sample-size-calculator/) to determine your sample size and run time.

If you are running a Bayesian experiment, we generally recommend you run experiments for at least one week. After you begin running an experiment, the experiment's **Results** tab displays a sample size estimator in the "Summary" section that gives an estimate of how much more traffic needs to encounter your experiment before reaching your chosen probability to be best.

In this example, you know that about 2,000 people download your app per day, and you'd like to have at least 40,000 customers in your experiment. You decide to include 100% of your new customers in the sample to get the fastest results. So, you will run this experiment for 21 days to include about 42,000 customers.

Here is the sample size calculation:`2,000 customers x 21 days x 100% of customers = 42,000 customers in experiment`As you decide on the sample size, you may want to consider the number of Experimentation keys you have available in the LaunchDarkly plan you subscribe to. For example, if you have 50,000 Experimentation keys per month included in your plan, and you run ten experiments per month, you may want to limit your experiment audiences to no more than 5,000 keys each. To learn more, read [Experimentation keys](/home/account/calculating-billing#experimentation-keys).

### Metric

You will use a clicked or tapped conversion metric to track when customers opt-in to notifications. To learn how to create a clicked or tapped conversion metric, read [Clicked or tapped conversion metrics](/home/metrics/click).

Select the following options for the metric:

* measure **Occurrence**
* for the percentage of **User** units that clickedHere is what your metric will look like:

<Frame caption="The &#x22;Create metric&#x22; dialog for a click conversion metric.">
  ![The "Create metric" dialog for a click conversion metric.](https://files.buildwithfern.com/https://launchdarkly.docs.buildwithfern.com/docs/437269c60658b15aee3b5d339a63c7e4f417b0587aad5ae5f7a9d2c52834ec83/assets/images/auto/experiment-example-opt-in-metric.auto.png)
</Frame>

### Variations

Create your flag with three variations. Use the **Experiment** flag template and **Number** flag type:

* Opt-in prompt on 1st open, which acts as the control
* Opt-in prompt on 5th open
* Opt-in prompt on 10th openHere is what your flag's variations will look like:

<Frame caption="A flag's three variations.">
  ![A flag's three variations.](https://files.buildwithfern.com/https://launchdarkly.docs.buildwithfern.com/docs/40c8decee01a277ddabd153872d8642f8fd46bcc15771d3a54704cbfe3eea6bd/assets/images/auto/experiment-example-opt-in-flag-variations.auto.png)
</Frame>

### Audience

You want to include only customers who have newly downloaded the app. To accomplish this, you can build a rule on your flag to exclude customers that have already made an opt-in decision. To learn how, read [Target with flags](/home/flags/target).

Here is what your flag's **Targeting** tab will look like with a targeting rule:

<Frame caption="A flag's &#x22;Targeting&#x22; tab including a targeting rule.">
  ![A flag's "Targeting" tab including a targeting rule.](https://files.buildwithfern.com/https://launchdarkly.docs.buildwithfern.com/docs/e8d032ff6c6aec0eb610350f2805e00ff13a96f0b1aaee5cda972006682f19f6/assets/images/auto/experiment-example-opt-in-flag-targeting.auto.png)
</Frame>

<Note title="You must run experiments on the correct rule">
  When you build an experiment, you can choose which flag targeting rule to run the experiment on. This ensures you include the right group of customers in your experiment. In this example, run the experiment on the flag’s targeting rule that you just created, not the flag’s default rule.
</Note>

### Experiment design

Finally, combine your hypothesis, metric, flag, and audience into an experiment. To learn how, read [Creating experiments](/home/experimentation/create).

Here is what your finished experiment will look like in LaunchDarkly:

<Frame caption="A complete opt-in experiment.">
  ![A complete opt-in experiment.](https://files.buildwithfern.com/https://launchdarkly.docs.buildwithfern.com/docs/20dc3580224052835da9922238eacdf8f5f627bd51bb84e3c829399e1f4b37a7/assets/images/auto/experiment-example-opt-in-experiment-design.auto.png)
</Frame>

## Example 2: Third-party library assessment

Adding JavaScript libraries to your front end has both benefits and drawbacks. Each library adds latency to your site load time, but can also enable functionality with benefits to your organization such as analytics, personalization, ad revenue, audience assessment, surveys, and more.

To find the balance between site load time and total revenue, you can use experimentation to measure your site revenue with different third-party JavaScript libraries installed.

### Hypothesis

To begin, create a hypothesis for your experiment. Here is an example:> If we install third-party libraries X and Y on two different versions of our site will yield total revenue increases for both versions, compared to the control with neither library X nor library Y installed, because customers will spend more when the site offers more functionality.

### Sample size

Next, determine the sample size you need for your experiment. In this example, you do not want to include your entire user base in your experiment, so decide to limit your experiment to 10% of your customers. You know that about 60,000 people visit your site per day, and you'd like to have at least 120,000 customers in your experiment. So, you will run this experiment for 20 days.

Here is the sample size calculation:`60,000 customers x 20 days x 10% of customers = 120,000 customers in experiment`As you decide on the sample size, you may want to consider the number of Experimentation keys you have available in the LaunchDarkly plan you subscribe to.

### Metric

You will use a custom numeric metric to track total revenue. To learn how to create a custom numeric metric, read [Custom numeric metrics](/home/metrics/custom-numeric).

Select the following options for the metric:

* **Average** for multiple event value aggregation
* **Average** `value`
* of the per **User** event `average`
* where **Higher is better**Here is what your metric will look like:

<Frame caption="The &#x22;Create metric&#x22; dialog for a custom numeric metric.">
  ![The "Create metric" dialog for a custom numeric metric.](https://files.buildwithfern.com/https://launchdarkly.docs.buildwithfern.com/docs/e4258fa50e77b155033221f2533a2ae861ea8fc1bebf656253be17547f75cf45/assets/images/auto/experiment-example-library-metric.auto.png)
</Frame>

When you create the metric, enter the appropriate event key from your codebase. In this example, the event key is "Total revenue."

<Note title="Event keys and metric keys are different">
  Sending custom events to LaunchDarkly requires a unique **event key**. You can set the event key to anything you want. Adding this event key to your codebase lets your SDK track actions customers take in your app as events. To learn more, read [Sending custom events](/sdk/features/events).

  LaunchDarkly also automatically generates a **metric key** when you create a metric. You only use the metric key to identify the metric in API calls. To learn more, read [Creating and managing metrics](/home/metrics/create-metrics).
</Note>

Although you will limit your decision-making based on the results of your primary metric, you are also curious about the latency time each third-party library adds. You will add a secondary custom numeric metric with a "lower is better" success criteria to measure time to first byte (TTFB) for each variation.

Select the following options for the metric:

* **Average** for multiple event value aggregation
* **Average** `value`
* of the per **Request** event `average`
* where **Lower is better**
* Exclude units that that did not send any events from the analysisHere is what your secondary metric will look like:

<Frame caption="The &#x22;Create metric&#x22; dialog for a secondary custom numeric metric.">
  ![The "Create metric" dialog for a secondary custom numeric metric.](https://files.buildwithfern.com/https://launchdarkly.docs.buildwithfern.com/docs/001f003e05e497994880b2303260557cc94e6b2c89ed38412752099a6cbf6f8c/assets/images/auto/experiment-example-library-metric-2.auto.png)
</Frame>

When you create the metric, enter the appropriate event key from your codebase. In this example, the event key is "Time to first byte."

### Variations

Create your flag with three variations. Use the **Experiment** flag template and **String** flag type:

* No third-party library installed, which acts as the control
* Library X installed
* Library Y installedHere is what your flag's **Variations** tab will look like:

<Frame caption="A flag's &#x22;Variations&#x22; tab with three variations.">
  ![A flag's "Variations" tab with three variations.](https://files.buildwithfern.com/https://launchdarkly.docs.buildwithfern.com/docs/1e323f2f69be994f7d8752686c6720552379996ed8127d34c27ae2b8c7429133/assets/images/auto/experiment-example-library-flag-variations.auto.png)
</Frame>

### Audience

In this experiment, you want a random sample of your entire user base in the experiment, so you will not create any targeting rules for the flag.

### Experiment design

Finally, combine your hypothesis, metrics, flag, and audience into an experiment. To learn how, read [Creating experiments](/home/experimentation/create).

Here is what your finished experiment will look like in LaunchDarkly:

<Frame caption="A complete third-party library experiment.">
  ![A complete third-party library experiment.](https://files.buildwithfern.com/https://launchdarkly.docs.buildwithfern.com/docs/f132e6e3ec1d3936cde47eb33b381b68dc911739da0f6ede84ec3a79e2c4fc2e/assets/images/auto/experiment-example-library-experiment-design.auto.png)
</Frame>

## Example 3: Trial account conversions

You offer 14-day trial accounts to potential customers. When the 14-day trial ends, customers have the option to convert to a paid account. You chose the 14-day trial arbitrarily, and would like to find out if giving customers a longer trial period results in more conversions to paid accounts.

### Hypothesis

To begin, create a hypothesis for your experiment. Here is an example:> If we give customers an extra week in their free trial for a total of 21 days, it will increase conversions to a paid account compared to the control of 14 days because customers will have more time to use the product.

### Sample size

Next, determine the sample size you need for your experiment. In this example, you know that about 750 customers sign up for a free trial per day, and you'd like to have at least 10,000 customers in your experiment. So, you will run this experiment for 14 days to include about 10,500 customers.

Here is the sample size calculation:`750 customers x 14 days x 100% of customers = 10,500 customers in experiment`As you decide on the sample size, you may want to consider the number of Experimentation keys you have available in the LaunchDarkly plan you subscribe to.

### Metric

You will use a custom conversion binary metric to track conversions to paid accounts. To learn how to create a custom conversion binary metric, read [Custom conversion binary metrics](/home/metrics/custom).

Select the following options for the metric:

* Percentage of **User** units that sent the event
* where **Higher is better**Here is what your metric will look like:

<Frame caption="The &#x22;Create metric&#x22; dialog for a custom conversion binary metric.">
  ![The "Create metric" dialog for a custom conversion binary metric.](https://files.buildwithfern.com/https://launchdarkly.docs.buildwithfern.com/docs/fcd098c3294292120e40f7c5586badf709b62a7252aefb45e970fa647b436499/assets/images/auto/experiment-example-trial-metric.auto.png)
</Frame>

When you create the metric, enter the appropriate event key from your codebase. In this example, the event key is "Conversion to paid accounts."

### Variations

Create your flag with two variations. Use the **Experiment** flag template and **String** flag type:

* A 14-day trial, which acts as the control
* A 21-day trialHere is what your flag's variations will look like:

<Frame caption="A flag's with two variations.">
  ![A flag's with two variations.](https://files.buildwithfern.com/https://launchdarkly.docs.buildwithfern.com/docs/568b3635e2fa9d186396f9e0ccbab8cd42a59fad11da0333686c41e041ac4445/assets/images/auto/experiment-example-trial-flag-variations.auto.png)
</Frame>

### Audience

In this experiment, you do not want to include students who may be using your trial service for school projects, so you will exclude customers with email addresses that end with `.edu`. To accomplish this, you can build a rule on your flag. To learn how, read [Target with flags](/home/flags/target).

Here is what your flag's **Targeting** tab will look like with a targeting rule:

<Frame caption="A flag's &#x22;Targeting&#x22; tab including a targeting rule.">
  ![A flag's "Targeting" tab including a targeting rule.](https://files.buildwithfern.com/https://launchdarkly.docs.buildwithfern.com/docs/fa07faa1788097de8f1d67b64ab221f9c6f0fcf6c513f74535098d5dc5830d38/assets/images/auto/experiment-example-trial-flag-targeting.auto.png)
</Frame>

<Note title="You must run experiments on the correct rule">
  When you build an experiment, you can choose which flag targeting rule to run the experiment on. This ensures you include the right group of customers in your experiment. In this example, run the experiment on the flag’s targeting rule that you just created, not the flag’s default rule.
</Note>

### Experiment design

Finally, combine your hypothesis, metric, flag, and audience into an experiment. To learn how, read [Creating experiments](/home/experimentation/create).

Here is what your finished experiment will look like in LaunchDarkly:

<Frame caption="A complete trial period length experiment.">
  ![A complete trial period length experiment.](https://files.buildwithfern.com/https://launchdarkly.docs.buildwithfern.com/docs/20dc3580224052835da9922238eacdf8f5f627bd51bb84e3c829399e1f4b37a7/assets/images/auto/experiment-example-trial-experiment-design.auto.png)
</Frame>

## Conclusion

In this guide, we present three use cases for LaunchDarkly Experimentation that cover app notification optimization, measuring the value of third-party libraries, and testing trial account conversions. For more examples of what you can measure with metrics, read [Choose a metric type](/home/metrics/choose).

<Tip title="You can also send data to and run experiments with Snowflake">
  Snowflake users who want to explore this data more in-depth can send all of the experiment data to a Snowflake database using the Snowflake Data Export integration. By exporting your LaunchDarkly experiment data to the same Snowflake warehouse as your other data, you can build custom reports in Snowflake to answer product behavior questions. To learn more, read [Snowflake Data Export](/integrations/data-export/snowflake).

  You can also run experiments using warehouse native metrics. To learn more, read [Snowflake native Experimentation](/home/warehouse-native/snowflake).
</Tip>

We hope this guide gets you started on the path to creating your own experiments. To get started building your own experiment, follow our [Quickstart for Experimentation](/home/experimentation/quickstart).
