Skip to main content

Snowplow Ecommerce

This plugin is the recommended way to track ecommerce events on your store. Functions, usage and a complete setup journey is showcased on the E-commerce Web Accelerator.

Tracker DistributionIncluded
sp.js
sp.lite.js
note

The plugin is available since version 3.8 of the tracker.

Download

Download from GitHub Releases (Recommended)Github Releases (plugins.umd.zip)
Available on jsDelivrjsDelivr (latest)
Available on unpkgunpkg (latest)

Initialization

window.snowplow(
'addPlugin',
'https://cdn.jsdelivr.net/npm/@snowplow/browser-plugin-snowplow-ecommerce@latest/dist/index.umd.min.js',
['snowplowEcommerceAccelerator', 'SnowplowEcommercePlugin']
);

Functions

APIUsed for:
trackProductViewTracking a visit to a product page. Known also as product detail view.
trackAddToCartTrack an addition to cart.
trackRemoveFromCartTrack a removal from cart.
trackProductListViewTrack an impression of a product list. The list could be a search results page, recommended products, upsells etc.
trackProductListClickTrack the click/selection of a product from a product list.
trackCheckoutStepTrack a checkout step completion in the checkout process together with common step attributes for user choices throughout the checkout funnel.
trackTransactionTrack a transaction/purchase completion.
setPageTypeSet a Page type context which would allow the analyst to discern between types of pages with ecommerce value. E.g. Category Page, Product Page, Cart Page, etc.
setEcommerceUserSet a User type context with a few standard user attributes.

Usage

trackProductView

To track a product view you can use the trackProductView method with the following attributes:

window.snowplow("trackProductView:{trackerName}", {
id: "12345",
name: "Baseball T",
brand: "Snowplow",
category: "apparel",
price: 200,
currency: "USD",
});

trackAddToCart

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

window.snowplow("trackAddToCart:{trackerName}", {
products: [
{
id: "P125",
name: "Baseball T",
brand: "Snowplow",
category: "Mens/Apparel",
price: 200,
currency: "USD",
},
],
total_value: 200,
currency: "USD",
});
  • 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.

trackRemoveFromCart

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

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 products is an array with the product/s removed from the cart.
  • Where total_value is the value of the cart after the removal of the product/s.
  • Where currency is the currency of the cart.

trackProductListView

To track a product list view you can use the trackProductListView method with the following attributes:

window.snowplow("trackProductListView:{trackerName}", {
products: [
{
id: "P123",
name: "Fashion red",
brand: "Snowplow",
category: "Mens/Apparel",
price: 100,
inventory_status: "in stock",
currency: "USD",
position: 1,
},
{
id: "P124",
name: "Fashion green",
brand: "Snowplow",
category: "Mens/Apparel",
price: 119,
inventory_status: "in stock",
currency: "USD",
position: 2,
},
{
id: "P125",
name: "Baseball T",
brand: "Snowplow",
category: "Mens/Apparel",
price: 200,
inventory_status: "in stock",
currency: "USD",
position: 3,
},
],
name: "Recommended Products",
});
  • Where products is an array of products being viewed from the list.
  • Where name is the name of the list being viewed. For the list names, you can use any kind of friendly name or a codified language to express the labeling of the list. E.g. 'Shoes - Men - Sneakers','Search results: "unisex shoes"', 'Product page upsells'

trackProductListClick

window.snowplow("trackProductListClick:{trackerName}", {
product: {
id: "P124",
name: "Fashion green",
brand: "Snowplow",
category: "Mens/Apparel",
price: 119,
inventory_status: "in stock",
currency: "USD",
position: 2,
},
name: "Recommended Products",
});
  • Where product is the product being clicked/selected from the list.
  • Where name is the name of the list the product is currently in. For the list names, you can use any kind of friendly name or a codified language to express the labeling of the list. E.g. 'Shoes - Men - Sneakers','Search results: "unisex shoes"', 'Product page upsells'

trackCheckoutStep

To track a checkout step you can use the trackCheckoutStep method with the following attributes:

/* Step 1 - Account type selection */
window.snowplow("trackCheckoutStep:{trackerName}", {
step: 1,
account_type: "guest checkout",
});

/* Step 2 - Billing options selection */
window.snowplow("trackCheckoutStep:{trackerName}", {
step: 2,
payment_method: "credit card",
proof_of_payment: "invoice",
});

trackTransaction

To track a completed transaction you can use the trackTransaction method with the following attributes:

window.snowplow("trackTransaction:{trackerName}", {
transaction_id: "T12345",
revenue: 230,
currency: "USD",
payment_method: "credit_card",
total_quantity: 1,
tax: 20,
shipping: 10,
products: [
{
id: "P125",
name: "Baseball T",
brand: "Snowplow",
category: "Mens/Apparel",
price: 200,
inventory_status: "in stock",
currency: "USD",
},
],
});
  • Where products is an array with the product/s taking part in the transaction.

setPageType

To set a Page type context you can use the setPageType method with the following attributes:

window.snowplow("setPageType:{trackerName}", { type, language, locale });

After setting the Page context, it will getting attached to every consecutive Snowplow event.

setEcommerceUser

To set an Ecommerce User context you can use the setEcommerceUser method with the following attributes:

window.snowplow("setEcommerceUser:{trackerName}", { id, is_guest, email });

After setting the Page context, it will getting attached to every consecutive Snowplow event.

Entities

Below is the set of entities and attributes that can be used in the Snowplow Ecommerce implementation.

Ecommerce page entity

An ecommerce page entity can have the following attributes:

attributetypedescriptionrequired
typestringThe type of the page that was visited E.g. homepage, product page, checkout page.
languagestringThe language that the web page is based in.
localestringThe locale version of the site that is running.
Relevant Iglu schema

Ecommerce user entity

An ecommerce user entity can have the following attributes:

attributetypedescriptionrequired
idstringThe user ID.
is_guestbooleanWhether or not the user is a guest.
emailstringThe user's email address.
Relevant Iglu schema

Product entity

Whenever there is a product entity involved in the ecommerce interaction event, the product or array of products 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.
Relevant Iglu schema

Cart entity

On cart interaction ecommerce events, a cart can have the following attributes:

attributetypedescriptionrequired
total_valuenumberThe total value of the cart after this interaction.
currencystringThe currency used for this cart (ISO 4217).
cart_idstringThe unique ID representing this cart.
Cart

Checkout step entity

Whenever there is a checkout entity involved in the ecommerce interaction event, it can have the following attributes:

attributetypedescriptionrequired
stepnumberCheckout step index.
shipping_postcodestringShipping address postcode.
billing_postcodestringBilling address postcode.
shipping_full_addressstringFull shipping address.
billing_full_addressstringFull billing address.
delivery_providerstringCan be used to discern delivery providers DHL, PostNL etc.
delivery_methodstringCan be used to discern delivery methods selected E.g. store pickup, standard delivery, express delivery, international.
coupon_codestringCoupon applied at checkout.
account_typestringType of account used on checkout. E.g. existing user, guest.
payment_methodstringAny kind of payment method the user selected to proceed E.g. card, PayPal, Alipay etc.
proof_of_paymentstringInvoice or receipt.
marketing_opt_inbooleanIf opted in to marketing campaigns.
Relevant Iglu schema

Transaction entity

Whenever there is a transaction entity involved in the ecommerce interaction event, it can have the following attributes:

attributetypedescriptionrequired
transaction_idstringThe ID of the transaction
currencystringThe currency used for the transaction (ISO 4217).
revenuenumberThe revenue of the transaction.
payment_methodstringThe payment method used for the transaction.
total_quantitynumberTotal quantity of items in the transaction.
taxnumberTotal amount of tax on the transaction.
shippingnumberTotal cost of shipping on the transaction.
discount_codestringDiscount code used.
discount_amountnumberDiscount amount taken off.
credit_orderbooleanWhether the transaction is a credit order or not.
Relevant Iglu schema
Was this page helpful?