> For the complete documentation index, see [llms.txt](https://docs.intelligems.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.intelligems.io/developer-resources/theme-and-storefront-setup/custom-add-to-cart-and-order-completed-events.md).

# 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](/analytics/overview/custom-events/custom-javascript-events.md) 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](/analytics/overview/custom-events/custom-javascript-events.md) to Intelligems on order creation with the Shopify order ID:

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.intelligems.io/developer-resources/theme-and-storefront-setup/custom-add-to-cart-and-order-completed-events.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
