---
title: addCartRows
slug: js-api/addcartrows
description: Overview of the Monetate JavaScript API addCartRows method and how to use it
image:  https://archbee-image-uploads.s3.amazonaws.com/ceIfEvQHzQk1IVxoRWUh7/K9eTL4jKm7UQINb6zNziJ-20250912-181225.png
docTags: 
createdAt: 2024-04-30T17:11:35.304Z
---

:::CodeblockTabs
addCartRows Method

```javascript
// addCartRows Method
window.monetateQ.push([
  "addCartRows", [{
    "productId": "pidString",
    "quantity": "quantityString",
    "unitPrice": "priceString",
    "sku": "pidString",
    "currency": "currencyString"
  }]
]);
```
:::

The `addCartRows` method is used to add products a customer has added to their cart.

:::hint{type="info"}
To unlock full targeting functionality for your cart, include the `addCartRows` method to all pages and not just your cart page.
:::

Each row is an object with properties specific to the product added to the cart. Some object properties are required, and others are optional.

:::hint{type="warning"}
A product ID can have a maximum of 50 characters. Any product ID that exceeds this length is truncated after 50 characters.
:::

If items are in the cart and a visitor adds a new one, the `addCartRows` method overwrites any existing cart details that your site passed to the Monetate platform. As a result, you should pass all products currently in the cart in each `addCartRows` method call.

The cart state is persistent throughout the [Monetate session](https://docs.monetate.com/docs/the-monetate-session). Therefore, the best practice is to call this method any time items are added or removed from the cart.

## Required and Optional Properties

These object properties are required:

- `productId`
- `quantity`
- `unitPrice`

These object properties are optional:

- `sku`
- `currency`

:::hint{type="warning"}
If your site doesn't use US dollars (USD) for purchases, then you must include currency information in this method.
:::

Don't send empty strings for optional property values. Only send properties that have a value.

## Monetate Inspector View

This screenshot shows the required properties—product ID, quantity, and unit price—as they appear in the [Monetate Inspector browser plug-in](https://docs.monetate.com/docs/install-the-monetate-inspector-browser-plug-in).

![The Components tab of Monetate Inspector, with cart in the Page Type row and with product IDs, quantity, and unit price in two Cart Products rows](https://dyzz9obi78pm5.cloudfront.net/app/image/id/64f7626d6bf53f603f4f6623/n/monetate-inspector-components-tab-event-viewpage-viewcart-page-type-cart-cart-products-product-id-product-sku.png)

This code example contains the method in use that results in the Monetate Inspector results shown in the previous screenshot.

:::CodeblockTabs
addCartRows Example

```javascript
// addCartRows Example
window.monetateQ = window.monetateQ || [];
window.monetateQ.push([
  "addCartRows", [
  {
    "productId": "21296",
    "quantity": "1",
    "unitPrice": "69.99",
    "currency": "EUR"
  },
  {
    "productId": "127115",
    "quantity": "1",
    "unitPrice": "34.99",
    "currency": "EUR"
  }]
]);
window.monetateQ.push([
  "trackData"
]);
```
:::

## Reporting Empty Carts

You can indicate an empty cart by calling `addCartRows` once with an empty array, as shown in this code example.

:::CodeblockTabs
Empty Cart Example

```javascript
// addCartRows Empty Cart Example
window.monetateQ = window.monetateQ || [];
window.monetateQ.push(["addCartRows", []]);
window.monetateQ.push(["trackData"]);
```
:::

