Tracking cart status
This article presents one of the methods of tracking cart contents in a web environment.
While tracking the contents of a cart on a website, you may run into issues with session time or tracking events that add/remove items. To resolve this, you can retrieve and send custom events that include all the current contents of the cart.
An example usage of the cart status events is sending reminders to customers who leave their carts without completing a purchase and sending each update of the cart status to Synerise.
Authentication
Requests to the SDK may require customer authentication. For more details, see this article.
Updating cart status
You must send cart.status
immediately after the contents of the cart are modified. Example of a custom event that updates the status of a cart:
SR.event.trackCustomEvent('cart.status', {
products: [
{
sku: '236',
quantity: 2,
brand: 'brand1',
category: 'cat1'
},
{
sku: '436',
quantity: 1,
brand: 'brand1',
category: 'cat1'
}
],
totalAmount: 150,
totalQuantity: 3,
itemIds: ["236","436"]
},
'CartStatus');
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
products |
array | yes | An array of items in the cart. Cannot contain duplicates. |
sku |
string | yes | The SKU of the item. Must be the same as the product:retailer_part_no value in OG tags and <g:id> or g:item_group_id in the product feed. |
quantity |
float | yes | The quantity of the item in the cart |
brand |
string | no | The brand of the item |
category |
string/array | no | A category (string) or categories (array of strings) that the item belongs to. Must be the same as the og:category in OG tags and <g:product_type> in the product feed. |
totalAmount |
float | no | The total value of the cart |
totalQuantity |
float | no | The total quantity of items in the cart |
itemIds |
array | recommended | This is a parameter that stores item IDs from the cart. Thanks to this parameter, you don’t need to extract sku values from the products array to to create analytics based on item IDs; create recommendations; or exclude items from a recommendation if they’re already in the cart. |
Clearing a cart
When all the contents of a cart are removed, send a status event with an empty cart.
This must be done when a transaction is completed.
SR.event.trackCustomEvent('cart.status', {
products: [],
totalAmount: 0,
totalQuantity: 0
}, 'CartStatus');