# Dynamic contextual variables

Dynamic contextual variables are the **real-time inputs** that power:

* **Personalization** (based on viewed, bought, or carted products)
* **Dynamic filtering and rule application** (brand, category, stock, etc.)
* **Algorithm scoring** (via `recency`, `frequency`, `score`)
* **User segmentation and localization** (`country`, `language`, `device_type`)

The table below lists the Dynamic contextual variables:

| Variable            | Type           | Description                                                                                                 | Example                                                                     |
| ------------------- | -------------- | ----------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
| **`page_type`**     | string         | Identifies the type of page currently viewed. Used to adapt recommendations or merchandising logic.         | `"homepage"`, `"category"`, `"product"`, `"cart"`, `"checkout"`, `"search"` |
| **`viewed_items`**  | array          | List of product IDs viewed by the user during the current session or historically.                          | `["SKU123", "SKU456"]`                                                      |
| **`bought_items`**  | array          | List of product IDs previously purchased by the user.                                                       | `["SKU987"]`                                                                |
| **`cart_items`**    | array          | List of product IDs currently in the user’s cart.                                                           | `["SKU111", "SKU222"]`                                                      |
| **`array_item_id`** | array          | Input list of item IDs dynamically passed into a strategy (for example, “items viewed” or “items bought”).  | `["SKU123", "SKU456"]`                                                      |
| **`referrer`**      | string         | URL of the previous page; used to infer user intent or navigation path.                                     | `"https://www.google.com"`                                                  |
| **`recency`**       | number         | Time elapsed since the user’s last interaction (view, add\_to\_cart, or purchase). Used to weigh freshness. | `24h`, `3d`                                                                 |
| **`frequency`**     | number         | Number of user interactions (views, clicks, purchases) over a given period.                                 | `5`                                                                         |
| **`monetary`**      | number         | Total monetary value associated with the user’s purchases.                                                  | `250.00`                                                                    |
| **`segment`**       | string / array | Dynamic segment assigned to the user (e.g., VIP, returning, new).                                           | `["returning_user", "FR"]`                                                  |
| **`device_type`**   | string         | Device detected in the current session.                                                                     | `"mobile"`, `"desktop"`                                                     |
| **`country`**       | string         | User’s detected country based on IP or site configuration.                                                  | `"FR"`                                                                      |
| **`currency`**      | string         | Currency currently displayed on the site.                                                                   | `"EUR"`                                                                     |
| **`language`**      | string         | Language of the current page or session.                                                                    | `"en"`, `"fr"`                                                              |
| **`session_id`**    | string         | Unique identifier for the current browsing session.                                                         | `"session-abc123"`                                                          |
| **`anonymous_id`**  | string         | Persistent anonymous identifier used for non-logged users (cookie, localStorage, or cookieless ID).         | `"anon-9876"`                                                               |
| **`score`**         | number         | Relevance score computed by the recommendation algorithm for a given item.                                  | `0.87`                                                                      |
| **`rule_id`**       | string         | ID of a dynamic filter or business rule applied during recommendation computation.                          | `"filter-brand-exclude-Nike"`                                               |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.abtasty.com/recommendations-and-merchandising/concepts/dynamic-contextual-variables.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
