# How to Install Content Targeting Integration

Azion **Content Targeting** is a *serverless* integration from Azion Marketplace.

This integration allows you to manipulate cookies and headers for flexible usage logics. This function can handle specific application contexts, business rules, or other customer-defined scenarios, as well as content segmentation.

You can create different scenarios and define variants and distribution percentages for each scenario using the Content Targeting integration. This allows a greater assertiveness without taxing resources and interactions at the source. Furthermore, you can create processing logic at the edge, broadening the function's application possibilities and reaping benefits such as targeted cache, absorption of access peaks, high performance, distributed processing logic, and event registration via Data Stream.

---

## Getting the integration

To use the Content Targeting integration provided at Azion Marketplace, follow these steps:

1. Access [Azion Console](/en/documentation/products/guides/how-to-access-azion-console/) > **Marketplace**.
2. On the Marketplace homepage, look for the **Content Targeting** card and select it.
3. On the integration's page, click the **Install** button.

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 

Once you've gotten your integration on Marketplace, you'll have to select an application to use the integration.

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

To configure your integration, proceed as follows:

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 **Content Targeting** integration.
3. In the **Main Settings** tab, click the **Functions** switch to enable functions on your application.
4. Click the **Save** button.

You'll receive a success message indicating that your 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.
:::

---

## Instantiating the integration

To enable this function, while still on the **Application** page:

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 **Content Targeting [Global]** function.
  - This action will load the **Arguments** tab.
5. On the **Arguments** tab, add the parameters in a `JSON` file that will look like this:

```json
{
  "cookie_name": "azion-cookie",
  "header_name": "azion_header",
  "domain": ".azion.com",
  "max_age": 600,
  "expires": "Tue, 19 Jan 2038 03:14:07 GMT",
  "path": "/",
  "values": [
    {
      "value": "A",
      "weight": 7.1,
      "cache_key": "custom_a"
    },
    {
      "value": "B",
      "weight": 14.9
    }
  ]
}
```

Where:

| Key | Data Format | Required | Description | Notes |
|---|---|---|---|---|
| `cookie_name` | String | Yes | Represents the cookie which will be used to store the chosen value | - |
| `header_name` | String | Yes | Represents the header which will be used to store the chosen value | - |
| `domain` | String | Yes | Defines the domain for which the cookie will be set | - |
| `max_age` | Integer | No | Defines how long (in seconds) the cookie value will be valid | While `max_age` and `expires` aren't require, it's highly recommend using at least one of them, otherwise the cookie won't be stored.<br /><br />Another important fact is that these field don't replace one another, in fact, the `expires` one is just a fallback for older browsers which still doesn't work with the `max_age` directive. |
| `expires` | String | No | Legacy way to define how long a cookie will be stored. <br /><br />When using this format you must input a complete date. | - |
| `path` | String | Yes | Defines the path to where the cookie will be valid | - |
| `values` | Object | Yes (the list must have at least one entry) | Describes each possible value to be chosen | `value` (required) represents the value which will be set in the cookie/header if this option is chosen.<br /><br />`weight` (required) defines the odds of the option being chosen.<br /><br />`cache_key` (optional) defines a custom cache key for the request whenever this option is chosen. |

---

## Configuring a rule on Rules Engine

Now you have to configure the rules you want (*criteria* and *behavior*) to apply to run your function.

Still in the **Applications** page, follow these steps:

1. Select the **Rules Engine** tab.
2. Click on **Default Rule**.
    - You can't change the criteria field for the **Default Rule** on **Rules Engine**.
3. On the *Behavior* field, select **Run Function** from the dropdown menu.
4. Select the **Content Targeting** function, according to the name you gave it in the instantiation step.
5. Click the **Save** button.

Done. Now you have your **Content Targeting** function running on the edge.

---