Clear History

Track Cart Events

Cart events are used for tracking additions and removals from a shopping cart.


Add to cart event

In this section, we will showcase how to track product additions to the cart.

AddToCartEvent

To track a product/s addition to the cart you can use the AddToCartEvent with the following attributes:

AddToCartEvent(products: [ProductEntity], cart: CartEntity)
  • Where products is an array with the product/s added to cart.
  • Where cart is a cart object.

Example usage:

let product = ProductEntity(id: "productId", category: "clothes/shirts", currency: "EUR", price: 100.50)
let cart = CartEntity(totalValue: 200, currency: "EUR")
let event = AddToCartEvent(products: [product], cart: cart)

tracker.track(event)

AddToCartEvent

To track a product/s addition to the cart you can use the AddToCartEvent with the following attributes:

AddToCartEvent(products: List<ProductEntity>, cart: CartEntity)
  • Where products is an array with the product/s added to cart.
  • Where cart is a cart object.

Example usage:

val product = ProductEntity(
  id = "productId", 
  category = "clothes/shirts", 
  currency = "EUR", 
  price = 100.50
)
val cart = CartEntity(totalValue = 200, currency = "EUR")
val event = AddToCartEvent(listOf(product), cart)

tracker.track(event)

AddToCartEvent

To track a product/s addition to the cart you can use the AddToCartEvent with the following attributes:

AddToCartEvent(products: List<ProductEntity>, cart: CartEntity)
  • Where products is an array with the product/s added to cart.
  • Where cart is a cart object.

Example usage:

ProductEntity product = new ProductEntity(
  "productId", // id
  "clothes/shirts", // category
  "EUR", // currency
  100.50 // price
);
List<Product> products = new ArrayList<>();
products.add(product);

CartEntity cart = new CartEntity(
  200, // totalValue
  "EUR" // currency
);
AddToCartEvent event = new AddToCartEvent(products, cart);

tracker.track(event);

Remove from cart event

In this section, we will showcase how to track product removals from the cart.

RemoveFromCartEvent

To track a product/s removal from the cart you can use the RemoveFromCartEvent with the following attributes:

RemoveFromCartEvent(products: [ProductEntity], cart: CartEntity)
  • Where products is an array with the product/s added to cart.
  • Where cart is a cart object.

Example usage:

let product = ProductEntity(id: "productId", category: "clothes/shirts", currency: "EUR", price: 100.50)
let cart = CartEntity(totalValue: 200, currency: "EUR")
let event = RemoveFromCartEvent(products: [product], cart: cart)

tracker.track(event)

RemoveFromCartEvent

To track a product/s removal from the cart you can use the RemoveFromCartEvent with the following attributes:

RemoveFromCartEvent(products: List<ProductEntity>, cart: CartEntity)
  • Where products is an array with the product/s added to cart.
  • Where cart is a cart object.

Example usage:

val product = ProductEntity(
  id = "productId", 
  category = "clothes/shirts", 
  currency = "EUR", 
  price = 100.50
)
val cart = CartEntity(totalValue = 200, currency = "EUR")
val event = RemoveFromCartEvent(listOf(product), cart)

tracker.track(event)

RemoveFromCartEvent

To track a product/s removal from the cart you can use the RemoveFromCartEvent with the following attributes:

RemoveFromCartEvent(products: List<ProductEntity>, cart: CartEntity)
  • Where products is an array with the product/s added to cart.
  • Where cart is a cart object.

Example usage:

ProductEntity product = new ProductEntity(
  "productId", // id
  "clothes/shirts", // category
  "EUR", // currency
  100.50 // price
);
List<Product> products = new ArrayList<>();
products.add(product);

CartEntity cart = new CartEntity(
  200, // totalValue
  "EUR" // currency
);
RemoveFromCartEvent event = new RemoveFromCartEvent(products, cart);

tracker.track(event);

Where ProductEntity can have the following attributes:

attributetypedescriptionrequired
idstringSKU or product ID.
currencystringCurrency in which the product is being priced (ISO 4217).
pricenumberPrice of the product at the current time.
namestringName or title of the product.
categorystringCategory the product belongs to. Use a consistent separator to express multiple levels. E.g. Woman/Shoes/Sneakers. The number of levels is defined by the user.
listPricenumberRecommended or list price of a product.
quantitynumberQuantity of the product taking part in the action. Used for Cart events.
sizestringSize of the product. E.g. XL, XS, M.
variantstringVariant of the product. E.g. Red, Heavy, Leather.
brandstringBrand of the product.
inventoryStatusstringInventory status of the product. E.g. in stock, out of stock, preorder, backorder.
positionnumberPosition the product was presented in a list of products. Used in Product List events.
creativeIdstringIdentifier/Name/Url for the creative presented on a list or product view.

Where CartEntity can have the following attributes:

attributetypedescriptionrequired
totalValuenumberThe total value of the cart after this interaction.
currencystringCurrency used for this cart (ISO 4217).
cartIdstringThe unique ID representing this cart.