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.

trackAddToCart

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

import { trackAddToCart } from '@snowplow/browser-plugin-snowplow-ecommerce';

trackAddToCart({ products: Product[], total_value, currency, cart_id });
  • Where products is an array with the product/s added to cart.
  • Where total_value is the value of the cart after the addition.
  • Where currency is the currency of the cart.
  • Where cart_id is an identifier for the current cart instance.

Example usage:

import { trackAddToCart } from "@snowplow/browser-plugin-snowplow-ecommerce";

trackAddToCart({
  products: [
    {
      id: "P125",
      name: "Baseball T",
      brand: "Snowplow",
      category: "Mens/Apparel",
      price: 200,
      currency: "USD",
    },
  ],
  total_value: 200,
  currency: "USD",
});

trackAddToCart

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

/* {trackerName} is a placeholder for the initialized tracker on your page.  */

window.snowplow("trackAddToCart:{trackerName}", { products: Product[], total_value, currency, cart_id });
  • Where products is an array with the product/s added to cart.
  • Where total_value is the value of the cart after the addition.
  • Where currency is the currency of the cart.
  • Where cart_id is an identifier for the current cart instance.

Example usage:

window.snowplow("trackAddToCart:{trackerName}", {
  products: [
    {
      id: "P125",
      name: "Baseball T",
      brand: "Snowplow",
      category: "Mens/Apparel",
      price: 200,
      currency: "USD",
    },
  ],
  total_value: 200,
  currency: "USD",
});

Remove from cart event

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

trackRemoveFromCart

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

import { trackRemoveFromCart } from '@snowplow/browser-plugin-snowplow-ecommerce';

trackRemoveFromCart({ products: Product[], total_value, currency, cart_id });
  • Where products is an array with the product/s removed from cart.
  • Where total_value is the value of the cart after the removal.
  • Where currency is the currency of the cart.
  • Where cart_id is an identifier for the current cart instance.

Example usage:

import { trackRemoveFromCart } from "@snowplow/browser-plugin-snowplow-ecommerce";

trackRemoveFromCart({
  products: [
    {
      id: "P125",
      name: "Baseball T",
      brand: "Snowplow",
      category: "Mens/Apparel",
      price: 200,
      currency: "USD",
    },
  ],
  total_value: 0, /* Total cart value after removal of the product */
  currency: "USD",
});

trackRemoveFromCart

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

/* {trackerName} is a placeholder for the initialized tracker on your page.  */

window.snowplow("trackRemoveFromCart:{trackerName}", { products: Product[], total_value, currency, cart_id });
  • Where products is an array with the product/s removed from cart.
  • Where total_value is the value of the cart after the removal.
  • Where currency is the currency of the cart.
  • Where cart_id is an identifier for the current cart instance.

Example usage:

window.snowplow("trackRemoveFromCart:{trackerName}", {
  products: [
    {
      id: "P125",
      name: "Baseball T",
      brand: "Snowplow",
      category: "Mens/Apparel",
      price: 200,
      currency: "USD",
    },
  ],
  total_value: 0,
  currency: "USD",
});

Where product 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.
list_pricenumberRecommended 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.
inventory_statusstringInventory 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.
creative_idstringIdentifier/Name/Url for the creative presented on a list or product view.