trackEcommerceAddToCart

The trackEcommerceAddToCart() method tracks when a product is added to the cart.

Syntax

const options: CommonEventOptions = { visitCustomVariables: { index: { name: 'name', value: 'value' }, customDimensions: { dimensionID: 'value', dimensionID: 'value', }, }; const ecommerceProduct: EcommerceProduct[] = [ { sku: 'sku', name: 'name', category: ['category'], price: 'price', quantity: quantity, brand: 'brand', variant: 'variant', customDimensions: { dimensionID: 'value', dimensionID: 'value', }, }, ]; await PiwikProSdk.trackEcommerceAddToCart(products, options);

Parameters

products (array, required)

Product list. Each product should have the following attributes:

sku (string, required)

Product stock-keeping unit.

name (string, optional)

Product name (default: “”).

category (string|Array, optional)

Product category or an array of up to 5 categories. Default: “”.

price (number|string, optional)

Product price has to be a float number or a string containing float number representation. Default: 0.

quantity (number|string, optional)

Product quantity has to be an integer number or a string containing integer representation. Default: 1.

brand (string, optional)

Product brand. Default: “”.

variant (string, optional)

Product variant. Default: “”.

customDimensions (object, optional)

Product custom dimensions. Default: {}.

options

Event options: an object containing two properties.

customDimensions

An object that specifies custom dimensions.

visitCustomVariables

An object that specifies visit custom variables.

Examples

const options: CommonEventOptions = { visitCustomVariables: { index: { name: 'name', value: 'value' }, customDimensions: { dimensionID: 'value', dimensionID: 'value', }, }; const ecommerceProduct: EcommerceProduct[] = [ { sku: 'craft-311', name: 'Unicorn Iron on Patch', category: ['Crafts & Sewing', 'Toys', 'Cosmetics'], price: '49,9089', quantity: 3, brand: 'DMZ', variant: 'blue', customDimensions: { 1: 'coupon-2020', 2: '20%', }, }, ]; await PiwikProSdk.trackEcommerceAddToCart(ecommerceProduct, options);

Related methods


Did this page help you?