addCartRows
The addCartRows method is used to add products a customer has added to their cart.
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.
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. Therefore, the best practice is to call this method any time items are added or removed from the cart.
These object properties are required:
- productId
- quantity
- unitPrice
These object properties are optional:
- sku
- currency
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.
This screenshot shows the required properties—product ID, quantity, and unit price—as they appear in the Monetate Inspector browser plug-in.
This code example contains the method in use that results in the Monetate Inspector results shown in the previous screenshot.
You can indicate an empty cart by calling addCartRows once with an empty array, as shown in this code example.