# Add to cart

The following describes how add to cart tracking is done for Firework.

## How to implement the "add\_to\_cart" tracking event

```javascript
<script>
function onAddToCart() {
    window._fwn.analytics.addToCart({
        "order_id": "123456789",
        "currency": "USD",
        "subtotal": "40.00",
        "total_discounts": "5.00",
        "order_value": "50.00",
        "line_items": [{
                "sku": "TSHIRT-RED-M",
                "quantity": 2,
                "price": "15.00",
                "name": "Red T-shirt (M)"
            },
            {
                "sku": "BANANA",
                "quantity": 10,
                "price": "1.00",
                "name": "Organic Banana"
            }
        ]

    });
}

// Calls onAddToCart() whenever there is add to cart happening
</script>
```

Note: Please refer to the [payload section](/firework-for-developers/web/integration-guide/shopping-integration-v2/tracking/purchase.md#payload-for-purchase-tags) for the required fields.


---

# 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.firework.com/firework-for-developers/web/integration-guide/shopping-integration-v2/tracking/add-to-cart.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.
