---
name: azion-install-the-a-b-testing-integration
description: >-
  Install A/B Testing from Azion Marketplace and run it on an application to split traffic between two variations with a cookie.
---

# Install the A/B Testing integration

A/B Testing sends each user to one of two variations of an address, an interface, or a workflow, and records the choice in a cookie. Use it to compare how users respond to each variation. It is one of the [Marketplace integrations](/en/documentation/platform/marketplace/integrations/) that run on an application.

Four objects must exist before a request reaches a variation: the installed function, an application with the **Functions** module turned on, a function instance that holds the arguments, and a Rules Engine rule with the **Run Function** behavior. Each section below creates one of them.

---

## Prerequisites

- An Azion account. To sign in, refer to [How to access Azion Console](/en/documentation/guides/platform/account-and-billing/how-to-access-azion-console/).
- An [application](/en/documentation/platform/applications/) served by a [workload](/en/documentation/platform/workloads/). To create one, refer to [Applications quickstart](/en/documentation/platform/applications/quickstart/).
- Two origins, one for each variation the test splits traffic between. Origins were redesigned as [Connectors](/en/documentation/platform/connectors/) in Azion Console. Each variation reads the ID of its own origin in the `originid` argument.
- Turning on a product or a module can generate usage costs. For more information, refer to [Pricing](/en/documentation/fundamentals/pricing/).

---

## Install the integration

The install adds the A/B Testing function to your account. To install it from Azion Console:

1. **Open Marketplace**

   Access [Azion Console](https://console.azion.com/) > **Marketplace**.

2. **Find the integration**

   Enter `A/B Testing` in the **Search on Marketplace** field, then select the integration's card. Browsing the cards and the categories reaches the same page.

3. **Select Install**

The card shows `Successfully installed!` and `Latest version installed!`. The function is then listed as *A/B Testing \[Global]* in the **Function** list of the **Create Instance** drawer.

---

## Turn on the Functions module

An application runs an installed function only when its **Functions** module is on. The rule that runs A/B Testing uses the **Bypass Cache** and **Forward Cookies** behaviors, which require the **Application Accelerator** module. To turn on both modules:

1. **Open your application**

   Access [Azion Console](https://console.azion.com/) > **Applications** > **your application**.

2. **Open the Modules section**

   In the **Main Settings** tab, go to the **Modules** section.

3. **Turn on the Functions switch**

4. **Turn on the Application Accelerator switch**

5. **Select Save**

Azion Console confirms that the application was updated.

---

## Create the function instance

A function instance holds the arguments the A/B Testing function reads for one application. To create the instance in your application:

1. **Open the Functions Instances tab**

   In **Applications**, select your application, then select the **Functions Instances** tab.

2. **Select + Function**

   An application with no instance yet offers the same action as **Function Instance**. The **Create Instance** drawer opens.

3. **Name the instance**

   In **Name**, enter a unique name that identifies the instance. For example: `ab-testing-home`.

4. **Select the function**

   In **Function**, select *A/B Testing \[Global]*. The **Arguments** editor fills with the default arguments of the integration.

5. **Edit the arguments**

   In **Arguments**, replace the default values with the values of your test. Each key is described in the tables below.

6. **Select Save**

The instance appears in the **Functions Instances** tab with the name you entered.

### Arguments

The arguments are one JSON object with a `param` key. Inside `param`, the `cookie` section configures the cookie that records the variation, and the `a` and `b` sections configure one variation each. The editor loads these defaults:

```json
{
	"param": {
		"cookie": {
			"name": "azion_abtest",
			"expiration": "Wed, 04 May 2011 10:16:00 GMT",
			"max_age": 600,
			"domain": "localhost",
			"path": "/"
		},
		"a": {
			"cookie_value": "A_TEST",
			"prob": 0.5,
			"addresses_list": "localhost:2006",
			"originid": "uuid1",
			"live_ingest": false,
			"protocol_policy": "http",
			"path": "",
			"cache_key": "test_a",
			"host": "localhost"
		},
		"b": {
			"cookie_value": "B_TEST",
			"prob": 0.5,
			"addresses_list": "localhost:2010",
			"originid": "uuid2",
			"live_ingest": false,
			"protocol_policy": "preserve",
			"path": "",
			"cache_key": "test_b",
			"host": "localhost"
		}
	}
}
```

The `cookie` section takes these keys:

| Key          | Description                                                                |
| ------------ | -------------------------------------------------------------------------- |
| `name`       | The name of the cookie. Use a unique name that identifies the test         |
| `expiration` | The expiration date of the cookie                                          |
| `max_age`    | The lifespan of the cookie, in seconds                                     |
| `domain`     | The domain where the test runs                                             |
| `path`       | The subdomain of the cookie. Use `/` to set the cookie for all the domains |

The `a` section configures the first variation, and the `b` section takes the same keys for the second one:

| Key               | Description                                                                                                            |
| ----------------- | ---------------------------------------------------------------------------------------------------------------------- |
| `cookie_value`    | The value that identifies this variation in the cookie                                                                 |
| `prob`            | The probability of sending a user to this variation, from `0` to `1`. `0` is a `0%` chance and `1` is a `100%` chance  |
| `addresses_list`  | The address of the variation. For example: `www.mytest_ab_of_my_site.com:443`                                          |
| `originid`        | The ID of the origin of this variation. Azion Console generates it when you register the origin                        |
| `live_ingest`     | Whether the origin is a live stream. Takes `true` or `false`                                                           |
| `protocol_policy` | The protocol used to reach the origin: force `HTTP` or `HTTPS`, or pass `preserve` to keep the protocol of the request |
| `path`            | The subdomain of the cookie for this variation. Leave it empty, `""`, to make it valid for all domains                 |
| `cache_key`       | A name that identifies the cache of this variation. Use a unique value that no other variation repeats                 |
| `host`            | The host name that the request sends                                                                                   |

---

## Create the rule

The instance runs only when a Rules Engine rule calls it. The rule below matches every request and also adds the **Bypass Cache** and **Forward Cookies** behaviors, which require the **Application Accelerator** module. To create the rule:

1. **Open the Rules Engine tab**

   In **Applications**, select your application, then select the **Rules Engine** tab.

2. **Select + Rule**

3. **Name the rule**

   In **Name**, enter a name for the rule. For example: `Run A/B Testing on every request`.

4. **Select the phase**

   In the **Phase** section, select *Request Phase*.

5. **Set the criterion**

   In the **Criteria** section, keep the `${uri}` variable and the *starts with* operator, then enter `/` as the argument.

6. **Add the Run Function behavior**

   In the **Behaviors** section, select *Run Function*, then select the instance you created by its name.

7. **Add the Bypass Cache behavior**

   Select **Add Behavior**, then select *Bypass Cache*.

8. **Add the Forward Cookies behavior**

   Select **Add Behavior**, then select *Forward Cookies*.

9. **Select Save**

The rule appears in the **Rules Engine** tab, under the request phase, and runs the A/B Testing instance on every request. The change takes a few minutes to propagate through Azion's distributed infrastructure, so wait before you test a variation.

For every criterion and behavior a rule accepts, refer to [Rules Engine](/en/documentation/platform/applications/rules-engine/).

---

## Next steps

- [Marketplace integrations](/en/documentation/platform/marketplace/integrations.md): The integrations Marketplace offers, and the application or firewall each one runs on.
- [Rules Engine](/en/documentation/platform/applications/rules-engine.md): The criteria and behaviors a rule accepts, including Run Function, Bypass Cache, and Forward Cookies.
- [Connectors](/en/documentation/platform/connectors.md): How to create the origins that each variation of the test sends traffic to.
- [Update an integration](/en/documentation/guides/application-development/integrations/update-an-integration.md): How to get the latest version of an installed integration, and what an update creates.
