---
name: azion-install-the-content-targeting-integration
description: >-
  Install Content Targeting from Azion Marketplace and run it on an application to assign each user a weighted value in a cookie and a header.
---

# Install the Content Targeting integration

Content Targeting sets a cookie and a header on each request, with a value chosen from a weighted list. Use it to segment content by application context, business rule, or a scenario you define, with its own variants and distribution percentages. It is one of the [Marketplace integrations](/en/documentation/platform/marketplace/integrations/) that run on an application.

The function runs on Azion's distributed infrastructure instead of at your origin. A value can select its own cache key, and each event can be recorded through [Data Stream](/en/documentation/platform/data-stream/). Four objects must exist before a request receives a value: 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.

---

## 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/).
- 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 Content Targeting 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 `Content Targeting` 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 *Content Targeting \[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. To turn on the module:

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. **Select Save**

Azion Console confirms that the application was updated.

---

## Create the function instance

A function instance holds the arguments the Content Targeting 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: `content-targeting-home`.

4. **Select the function**

   In **Function**, select *Content Targeting \[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 scenario. Each key is described in the table below.

6. **Select Save**

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

### Arguments

The arguments are one JSON object. This example sets two values, `A` and `B`, and gives `A` its own cache key:

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

| Key           | Data format | Required                                   | Description                                                                |
| ------------- | ----------- | ------------------------------------------ | -------------------------------------------------------------------------- |
| `cookie_name` | String      | Yes                                        | The cookie that stores the chosen value                                    |
| `header_name` | String      | Yes                                        | The header that stores the chosen value                                    |
| `domain`      | String      | Yes                                        | The domain the cookie is set for                                           |
| `max_age`     | Integer     | No                                         | How long the cookie value is valid, in seconds                             |
| `expires`     | String      | No                                         | The legacy way to set how long the cookie is stored. Enter a complete date |
| `path`        | String      | Yes                                        | The path where the cookie is valid                                         |
| `values`      | Object      | Yes. The list must have at least one entry | Each value the function can choose                                         |

Neither `max_age` nor `expires` is required, but set at least one of them. Without both, the cookie is not stored. The two keys do not replace one another: `expires` is a fallback for older browsers that do not support the `max_age` directive.

Each entry in `values` takes these keys:

- `value`, required: the value set in the cookie and the header when this entry is chosen.
- `weight`, required: the odds of this entry being chosen.
- `cache_key`, optional: a custom cache key for the request when this entry is chosen.

---

## Create the rule

The instance runs only when a Rules Engine rule calls it. The rule below matches every request. 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 Content Targeting 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. **Select Save**

The rule appears in the **Rules Engine** tab, under the request phase, and runs the Content Targeting instance on every request.

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.
- [Data Stream](/en/documentation/platform/data-stream.md): How to send the events your application records to an endpoint you choose.
- [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.
