> For the complete documentation index, see [llms.txt](https://fredhopper.gitbook.io/product-discovery/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fredhopper.gitbook.io/product-discovery/tracking-and-sending-events/activities/add-to-cart.md).

# Add to Cart

Track add-to-cart actions to measure conversion rates. Send a new event for each distinct product added, including product, quantity, and variant details.

{% hint style="info" %}
This section is relevant for both **FHR** and **XO** customers.
{% endhint %}

**Add to cart** actions are used to calculate add to cart (or add to basket) **conversion rates**. Although typically restricted to a [PDP](/product-discovery/tracking-and-sending-events/acronyms-and-abbreviations.md), this action may be performed in a range of contexts.

Whenever a user adds a product to a cart (or basket) you should send an **add-to-cart** event.

{% hint style="warning" %}
You should send a new **add-to-cart** event for each distinct product, even if they are added to cart as part of the same action.
{% endhint %}

### **Properties** <a href="#lister-page" id="lister-page"></a>

```json
{
    "action":"add-to-cart",
    "target": {
        "product":"product-id"
    },
    "sourceId": "source-id",
    "metadata": {
        "quantity": 1,
        "variant": "variant-id"
    }
}
```

| Property            | Context                                              | Description                                                                                                                                                                                                                                      |
| ------------------- | ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `action`            | All                                                  | Must be specified as "add-to-cart"                                                                                                                                                                                                               |
| `target.product`    | All                                                  | The ID of the product that was added to cart; must be identical to the product ID used in FHR/XO, i.e. `secondID` [in the FHR response query](/product-discovery/tracking-and-sending-events/activities/activity-object.md#fhr-response-mapping) |
| `metadata.quantity` | All                                                  | The quantity of the product added to cart                                                                                                                                                                                                        |
| `sourceId`          | All                                                  | The [ID that associates the FHR or XO response with the event](/product-discovery/tracking-and-sending-events/activities/activity-object.md#source-id); i.e. response ID (`rid` in the FHR response query and `id` in the XO response query)     |
| `metadata.*`        | All                                                  | Additional information, such as **context** or **locale**                                                                                                                                                                                        |
| `metadata.query`    | The add-to-cart event is triggered on search results | The search terms that generated the viewed search results; the search term is available in the FHR response query (`searchterms.term.value`)                                                                                                     |
| `metadata.variant`  | All                                                  | The ID of the product variant that has been added to the cart; must be identical to the variant ID used in FHR/XO                                                                                                                                |

{% hint style="warning" %}
You should **only** include a **source ID** if the page the event is triggered on is powered by FHR or XO.
{% endhint %}

<details>

<summary>Example: Add to cart</summary>

```json
{
    "action":"add-to-cart",
    "target": {
        "product":"83647582"
    },
    "metadata": {
        "quantity": 1,
        "locale": "en_GB"
    },
    "sourceId": "5f0dfaf1-c79a-47fd-982f-b17de6533cf3"
}
```

</details>
