Skip to main content

Tracking cart changes

Cart changes can be tracked either with the Voyado Engage tracking script or the tracking API. Engage can trigger abandoned cart communication to be sent to identified contacts. To enable this, Engage need to know:

  • Every update of every unique shopping cart

  • The contactId of the visitor

There are two methods to consider when tracking cart changes:

  • cart(): Used for registering visitor actions related to any cart modification

  • emptyCart(): Used for pruning the cart of all items, usually when indicating a purchase or logout by the e-com visitor

Data flow

This is how the flow looks:

  1. The site submits shopping cart changes, either via the tracking script implemented on the e-com site or through the tracking API.

  2. Carts containing products that haven't been accessed for at least 30 minutes are considered abandoned. If the cart is connected to a specific contact it will be sent to Engage. All other carts will be filtered out.

  3. Engage then triggers the relevant automation (based on language/locale).

Cart automation requirements

The following are required so that an abaondoned cart automation can be triggered:

  • The locale must match a product feed in Engage and the corresponding language is set in an automation.

  • The SKU/SKUs must match products in the product feed (commonly “g:id”). If a SKU doesn’t match the feed, that particular product will not be included in the email. If no SKUs match the products in the feed the automation won't be triggered at all.

  • No products in the cart have been purchased (meaning no transaction has been sent to Engage) since the cart was identified as abandoned (although this can be overruled when configuring the trigger).

Using the tracking script

Here is how to use the tracking script to track cart changes.

The cart() method

Invoke this method every time the cart is changed (items added/removed or the quantity updated) regardless of if the user has been identified by the website or not. The cart() method will then generate a HTTP POST request to the Collect endpoint.

Field

Type

Description

*cartRef

string

Cart identifier, must be unique for each cart

cartUrl

string

URL to the cart

contactId

string

Engage contact ID, cookie _vaI will be used as fallback

*locale

string

Locale for the site where the cart is (example sv-SE). Format as defined by IETF language tag. Only locales with a Product Feed assigned in Engage can trigger an abandoned cart automation

*items

Array<object>

The array of items added to the cart

*items[].itemId

string

Item ID (SKU in Engage)

*items[].quantity

int

The number of items

Fields marked with * are mandatory

This is what a cart update looks like in code:

va("cart",{
    "cartRef":"354354",
    "contactId":"afa7625d-2e97-4667-b4c1-ad3b01194bee",
    "cartUrl":"https://www.store.se/cart?id=354354",
    "locale":"sv-SE",
    "items":
    [{
        "itemId": "456436",
        "quantity": 2,
    },
    {
        "itemId": "456437",
        "quantity": 2,
    }]
}); <!-- Adds two products in the cart-->

The emptyCart() method

Invoke this method when the cart has been emptied, either manually by the user or when the checkout process has been completed. This method is equivalent to invoking cart() with no items. It’s important to invoke emptyCart() after each successful checkout to avoid faulty abandoned cart communications.

The emptyCart() method will generate a HTTP POST request to the Collect endpoint.

Field

Type

Description

*cartRef

string

Cart identifier

contactId

string

The contact's Engage ID

Fields marked with * are mandatory

This is how a call to emptyCart() looks in code:

va("emptyCart",{
    "cartRef":  "354354"}
);

Using the tracking API

It's possible to submit cart changes directly via the API instead of implementing the tracking script. If you choose this approach, it is important to identify all contacts that come to the e-com via links in emails (add “vtid” in “contactId”). The calls can be tested through your OpenAPI (Swagger) page.

[tenantname].voyado.com/api/v2/ui/index#/tracking

Read more about the Engage API and your OpenAPI page here.

Important points when tracking cart changes

All behavioral data can be used to build understanding and insights. A shopping cart belonging to an anonymous user can still be linked to a contact after they are identified.

Important

If the user is identified / logged in, both the “cart()” script method and the Carts API can be used to track their behavior. For anonymous users, however, only the “cart()” script can be used. This is because the tracking API always requires the contactId.

Cart updates: Call the “cart()” script method (for identified and anonymous users) or the Carts API (for identified users only) for all updates to the shopping cart, regardless of where on the site or at what stage the cart update takes place (product page, popup or checkout). Engage handles the shopping cart based on its latest change. It is therefore important that all changes generate a call to “cart()” or the Carts API and that the data corresponds to the shopping cart currently displayed on the website.

cartRef: The “cartRef” value must be unique and must not be shared between different baskets or users. A "cartRef" of a specific shopping cart must not be changed, and all updates regarding a shopping cart must use the same "cartRef" value.

Empty carts: Use “cartRef” for empty carts as well. Even empty carts need a cart reference.

Important

Make sure to call “cart()” script method or the Carts API only when the cart is updated. Doing it at other times risks polluting your data in Engage.

Locale: Call the “cart()” script method or Carts API with a “locale” value corresponding to the locale of your Product Feed in Engage. In order to enrich the products with article data, a Product Feed for that locale needs to be set up in Engage. An automation using that locale also needs to be active.

Abandoned carts: All carts not emptied before the website visitor leaves, or makes a purchase, risk being marked as abandoned. If you have an abandoned cart automation active that will be triggered by those unemptied carts.