# How to Install A/B Testing from Marketplace

Mainly, you can use **A/B tests** to validate certain addresses, interfaces, or even workflows. Tests enable you to experiment with variations and how they work with your users, providing two options to access certain content or complete task.

---

## Getting the integration 

To use the **A/B Testing** integration provided through Azion **Marketplace**, access [Azion Console](/en/documentation/products/guides/how-to-access-azion-console/) and go to **Marketplace**.

On the Marketplace homepage, select the integration's card.

Once the integration's page opens, click the **Install** button, at the bottom-right corner of the page. A successful message appears to confirm your integration is installed.

:::tip
You can search any integration by browsing through the cards, using the filters, or typing a keyword in the search bar. 
:::

---

## Configuring the integration

Being an [Application function](/en/documentation/products/marketplace/integrations/#edge-application-functions), **A/B Testing** runs tasks and services on the edge, employing an *existing* application.

:::tip
Go to the [building](/en/documentation/products/guides/build/build-an-application/) section for more details on how to build an application.
:::

Follow the next steps to instantiate the integration.

1. On the upper-left corner, select **Products menu** > **Application** on the **BUILD** section.
2. On the listing page of your applications, select the one you want to use with the integration.
3. On the application page, open the **Main Settings** tab.
4. Enable the **Functions** and **Application Accelerator** switches to activate these modules.
5. Click the **Save** button.

A successful message appears informing that the application has been updated.

:::caution[Warning]
If a product or module is activated, it could generate usage-related costs. Check the [pricing page](/en/documentation/products/pricing/) for more information.
:::

---

## Adding origins

To configure the `JSON` file, you'll have to register the origins (websites) you want to redirect your integration. These origins will receive a unique ID called `Origin Key`.

Still on the page of the application, follow these steps:

1. Go to the **Origins** tab.
2. Click the **+ Origin** button.
3. Give an easy-to-remember name to this origin.
4. Select **Single Origin** for the type of origin.
5. Choose the protocol you want to use: **Enforce HTTP**, **Enforce HTTPS**, or **Preserve HTTP/HTTPS** to preserve the original protocol.
6. In **Address**, pass the URL you want to register for this origin.
7. Select `${host}` for the **Host Header** option.
8. You can pass an **Origin Path**, but this is optional.
9. Click the **Save** button.

After you save it, you'll be able to see the `Origin Key` generated by Azion Console for the origin you've registered. This will be used to fill the `originid` field on the **Arguments** box of the function.

:::note
You must register two origins.
:::

---

## Instantiating the integration

Still on the page of the application, follow these steps:

1. Select the **Functions Instances** tab.
2. Click the **+ Function Instance** button.
3. Choose an easy to remember name for your function.
4. On the dropdown function menu, select the **A/B Testing [Global]** function.

This action will load the **Arguments** tab, where you can add the parameters to execute your application.

:::note
The parameters have divisions of at least three sections: `params`, `a`, and `b`.
:::

The form will load the parameters as below:

```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"
		}
	}
}
```

Where:

| Variable | Description |
|---|---|
| `name` | The name of the cookie you'll choose. Give a unique and easy-to-remember name |
| `expiration` | The expiration date of the cookie |
| `max_age` | The time, in seconds, for the lifespan of the cookie  |
| `domain` | The domain where you're running the tests |
| `path` | The subdomain to the cookie. You can use `/` to set the subdomain to all the domains |

On the second section, called `a`, you can add the parameters to the first test, and then repeat it for the rest of the tests:

| Variable | Description |
|---|---|
| `cookie_value` | A value to identify the cookie for this test variation |
| `prob` | The probability to send this address to the user. This value should be between `0` and `1`, with `0` being `0%` of chance and `1` being `100%` of chance |
| `adressess_list` | The address for the `a` test. Example: `www.mytest_ab_of_my_site.com:443` |
| `originid` | The identification ID for the origin. This will be automatically generated by Azion Console |
| `live_ingest` | It indicates if the origin is a live streaming. A boolean value should be used here: `true` or `false` |
| `protocol_policy` | To force `HTTP` or `HTTPS`, or even keep the default value by passing the preserve value |
| `path` | It indicates the subdomain of the cookie. You can leave it blank, `""`, to indicate that it's valid for all domains |
| `cache_key` | A name to identify the cache. It should be unique and you can't repeat it elsewhere |
| `host` | The name of the host that the requisition sends |

---

## Configuring the Rules Engine

In **Rules Engine**, you'll pass the *criteria* and *behavior* to run the integration.

Still on the page of the application:

1. Select the **Rules Engine** tab.
2. Click the **Default Rule**.
    - Note that you can't change or configure the *criteria* for the **Default Rule**.
3. On the **Behavior** field, choose **Run Function** and, from the dropdown menu, choose the **A/B Testing integration** according to the name you gave it.
4. Add another behavior by clicking on the **+ Add Behavior** button right bellow the first one.
5. Pass the first behavior: **Bypass Cache**.
6. Click again on the **+ Add Behavior** button bellow the second behavior.
7. Pass the second behavior needed: **Forward Cookies**.
8. Click the **Save** button.

Done. Now you'll have to wait a few minutes for the application to propagate through Azion's edge nodes.

---