Snowplow ecommerce tracking
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.
It provides several trackX methods, which each create a Snowplow ecommerce action event with the appropriate entities attached. The event itself has only one property, an enum describing the ecommerce action taken e.g. "add_to_cart". View the schema here. All the provided data is sent in context entities.
There are also two context entities that can be globally configured: ecommerce page and ecommerce user.
The plugin is available since version 3.8 of the tracker.
Snowplow ecommerce events and entities must be manually tracked.
Install plugin
- JavaScript (tag)
- Browser (npm)
| Tracker Distribution | Included |
|---|---|
sp.js | ❌ |
sp.lite.js | ❌ |
Download:
| Download from GitHub Releases (Recommended) | Github Releases (plugins.umd.zip) |
| Available on jsDelivr | jsDelivr (latest) |
| Available on unpkg | unpkg (latest) |
window.snowplow(
'addPlugin',
'https://cdn.jsdelivr.net/npm/@snowplow/browser-plugin-snowplow-ecommerce@3/dist/index.umd.min.js',
['snowplowEcommerceAccelerator', 'SnowplowEcommercePlugin']
);
npm install @snowplow/browser-plugin-snowplow-ecommerce@3yarn add @snowplow/browser-plugin-snowplow-ecommerce@3pnpm add @snowplow/browser-plugin-snowplow-ecommerce@3
import { newTracker } from '@snowplow/browser-tracker';
import { SnowplowEcommercePlugin } from '@snowplow/browser-plugin-snowplow-ecommerce';
newTracker('sp1', '{{collector_url}}', {
appId: 'my-app-id',
plugins: [ SnowplowEcommercePlugin() ],
});
Events
| API | Used for: |
|---|---|
trackProductView | Tracking a visit to a product page. Known also as product detail view. |
trackAddToCart | Track an addition to cart. |
trackRemoveFromCart | Track a removal from cart. |
trackProductListView | Track an impression of a product list. The list could be a search results page, recommended products, upsells etc. |
trackProductListClick | Track the click/selection of a product from a product list. |
trackPromotionView | Track an impression for an internal promotion banner or slider or any other type of content that showcases internal products/categories. |
trackPromotionClick | Track the click/selection of an internal promotion. |
trackCheckoutStep | Track a checkout step completion in the checkout process together with common step attributes for user choices throughout the checkout funnel. |
trackTransaction | Track a transaction/purchase completion. |
trackRefund | Track a transaction partial or complete refund. |
trackTransactionError | Track an error happening during a transaction process. |
Product view
To track a product view you can use the trackProductView method with the following attributes:
- JavaScript (tag)
- Browser (npm)
window.snowplow("trackProductView:{trackerName}", {
id: "12345",
name: "Baseball T",
brand: "Snowplow",
category: "apparel",
price: 200,
currency: "USD",
});
import { trackProductView } from '@snowplow/browser-plugin-snowplow-ecommerce';
trackProductView({
id: "12345",
name: "Baseball T",
brand: "Snowplow",
category: "apparel",
price: 200,
currency: "USD",
});
Add to cart
To track a product/s addition to the cart you can use the trackAddToCart method with the following attributes:
- JavaScript (tag)
- Browser (npm)
window.snowplow("trackAddToCart:{trackerName}", {
products: [
{
id: "P125",
name: "Baseball T",
brand: "Snowplow",
category: "Mens/Apparel",
price: 200,
currency: "USD",
},
],
total_value: 200,
currency: "USD",
});
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",
});
- Where
productsis an array with the product/s added to cart. - Where
total_valueis the value of the cart after the addition. - Where
currencyis the currency of the cart.
Remove from cart
To track a product/s removal from the cart you can use the trackRemoveFromCart method with the following attributes:
- JavaScript (tag)
- Browser (npm)
window.snowplow("trackRemoveFromCart:{trackerName}", {
products: [
{
id: "P125",
name: "Baseball T",
brand: "Snowplow",
category: "Mens/Apparel",
price: 200,
currency: "USD",
},
],
total_value: 0,
currency: "USD",
});
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,
currency: "USD",
});
- Where
productsis an array with the product/s removed from the cart. - Where
total_valueis the value of the cart after the removal of the product/s. - Where
currencyis the currency of the cart.
Product list view
To track a product list view you can use the trackProductListView method with the following attributes:
- JavaScript (tag)
- Browser (npm)
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",
});
import { trackProductListView } from '@snowplow/browser-plugin-snowplow-ecommerce';
trackProductListView({
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
productsis an array of products being viewed from the list. - Where
nameis 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'
Product list click
- JavaScript (tag)
- Browser (npm)
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",
});
import { trackProductListClick } from '@snowplow/browser-plugin-snowplow-ecommerce';
trackProductListClick({
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
productis the product being clicked/selected from the list. - Where
nameis 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'
Promotion view
- JavaScript (tag)
- Browser (npm)
/* Carousel slide 1 viewed */
window.snowplow("trackPromotionView:{trackerName}", {
id: 'IP1234',
name: 'promo_winter',
type: 'carousel',
position: 1,
product_ids: ['P1234'],
});
/* On carousel slide 2 view */
window.snowplow("trackPromotionView:{trackerName}", {
id: 'IP1234',
name: 'promo_winter',
type: 'carousel',
position: 2,
product_ids: ['P1235'],
});
import { trackPromotionView } from '@snowplow/browser-plugin-snowplow-ecommerce';
/* Carousel slide 1 viewed */
trackPromotionView({
id: 'IP1234',
name: 'promo_winter',
type: 'carousel',
position: 1,
product_ids: ['P1234'],
});
/* On carousel slide 2 view */
trackPromotionView({
id: 'IP1234',
name: 'promo_winter',
type: 'carousel',
position: 2,
product_ids: ['P1235'],
});
Promotion click
- JavaScript (tag)
- Browser (npm)
window.snowplow("trackPromotionClick:{trackerName}", {
id: 'IP1234',
name: 'promo_winter',
type: 'carousel',
position: 1,
product_ids: ['P1234'],
});
import { trackPromotionClick } from "@snowplow/browser-plugin-snowplow-ecommerce";
trackPromotionClick({
id: 'IP1234',
name: 'promo_winter',
type: 'carousel',
position: 1,
product_ids: ['P1234'],
});
Checkout step
To track a checkout step you can use the trackCheckoutStep method with the following attributes:
- JavaScript (tag)
- Browser (npm)
/* 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",
});
import { trackCheckoutStep } from '@snowplow/browser-plugin-snowplow-ecommerce';
/* Step 1 - Account type selection */
trackCheckoutStep({
step: 1,
account_type: "guest checkout",
});
/* Step 2 - Billing options selection */
trackCheckoutStep({
step: 2,
payment_method: "credit card",
proof_of_payment: "invoice",
});