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 creating an automation that sends abandoned cart reminders to a customer.

WARNING: The events described here do not modify the cart. Their purpose is only to track the cart’s current content for use in marketing scenarios, automations, and analytics.

Authentication

Requests to the SDK may require customer authentication. For more details, see this article.

Updating cart status

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');
Important: This custom event contains complete information about a cart - if you want to add an item, you must also include the items that were in the cart before.

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');
😕

We are sorry to hear that

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.

😉

Awesome!

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.

Close modal icon Placeholder alt for modal to satisfy link checker