# Custom Add to Cart and Order Completed Events

## Add to Carts

Intelligems automatically tracks add-to-carts using a mixture of client-side and server-side data. This automatic tracking is very robust, and can detect add-to-carts where other tools, even Shopify’s reporting, fail to. However, it’s not compatible with headless setups that do not use Shopify’s cart backend. In these cases, you can send a [custom event](https://docs.intelligems.io/analytics/custom-events/custom-javascript-events) to Intelligems on add-to-carts so that built-in add-to-cart reporting works normally:

```javascript
{
    event: "igAddToCart",
    properties: {
        productVariants: [{variantId: 1234, productId: 1234}]
    }
}
```

## Order tracking

For orders to count towards experiment analytics, Intelligems needs to be able to associate orders with the visitor session that created the order. For nearly all setups, this works automatically out-of-the-box. However, if you are creating orders in a custom way or through a third-party app, Intelligems may not receive the data it needs to match orders to sessions. In this case, you can send a [custom event](https://docs.intelligems.io/analytics/custom-events/custom-javascript-events) to Intelligems on order creation with the Shopify order ID:

```javascript
{
    event: "orderPlaced",
    properties: {
       orderId: 123
    }
}
```


---

# 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.intelligems.io/developer-resources/custom-add-to-cart-and-order-completed-events.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.
