eCommerce

The following sections provide an overview for how you can measure commerce-related activity in your apps. mParticle Integrations have varying levels of support for commerce data, some providing no commerce-specific support, while others support very granular measurement of user-product, promotion, and impression interactions. The mParticle platform is designed to be flexible - use the APIs described below to measure the datapoints that you need and mParticle will make sure your data is represented faithfully across all of the integrations that you enable.

Basic

It’s sufficient for many apps to only track a purchase, rather than all of the granular steps before and after. Use a product-based Commerce Event or the Commerce helper-apis to track a simple purchase transaction.

Measuring Transactions

Create the Product(s)

The Product class should be used to represent a physical or virtual good or service. At minimum all products are required to have a name, an ID (or SKU), and a price.

The quantity will default to 1 if not provided as the 4th argument.

var product = mParticle.eCommerce.createProduct('Foo name', 'Foo sku', 100.00, 4);

Summarize the Transaction

var transactionAttributes = mParticle.eCommerce.createTransactionAttributes('foo-transaction-id');

Log the Transaction

mParticle.eCommerce.logPurchase(transactionAttributes, product);

Advanced

The mParticle platform lets you measure every granular step and interaction users can have with eCommerce products and services.

Class Overview

Commerce Event

The CommerceEvent class is central to mParticle’s eCommerce measurement. Commerce Events can contain many data points but it’s important to understand that there are 3 core variations:

  • Product-based: Used to measure measured datapoints associated with one or more products
  • Promotion-base: Used to measure datapoints associated with internal promotions or campaigns
  • Impression-based: Used to measure interactions with impressions of products and product-listings

Shopping Cart

Several of mParticle integration partners support the notion of a shopping cart and require that a shopping cart state be maintained. To make your life easier, the mParticle SDKs automatically maintain a shopping cart for you against the current user. The shopping cart will maintain its state across application launches, products can be manually added and removed from it, and you can even use it to log CommerceEvents.

There is a default maximum of 20 products that can be added to a cart. This can be changed by setting mParticle.config.maxProducts to a new number.

Commerce Helper APIs

The mParticle SDK provides a Commerce API class that interacts with the cart and also provides methods dedicated to certain product actions. This class is aware of how to generate and log simple Commerce Events so you can reduce the boilerplate code in your apps. The methods supported by this class, such as checkout() and purchase() will automatically include the products objects currently contained in the Cart.

Product Events

Product-based Commerce Events can be used to measure all of the steps and actions that a user might perform on their way to making a purchase within an eCommerce-enabled app, such as:

  • tapping and viewing products
  • adding and removing products from a cart or wishlist
  • multistep checkout
  • purchases and refunds

Create the Product(s)

var product = mParticle.eCommerce.createProduct('Foo name', 'Foo sku', 100.00, 4);

Add to Cart Events

Tracking when a user adds a product to their virtual cart can be very valuable - for example to target and message users if they abandon their cart without purchasing. You can use the Cart API to log these events, or manually create a CommerceEvent with the add-to-cart action.

var user = mParticle.Identity.getCurrentUser();
user.Cart.add(product, true);

Checkout Events

The mParticle SDK provides several APIs to measure the steps of the checkout process. Some integration partners such as Google Analytics allow you to configure the steps of your checkout process for in-depth analysis.

mParticle.eCommerce.logCheckout(1, 'Mastercard');

Promotion Events

The Promotion class should be used to represent internal offers - such as sales that might be displayed in a banner advertisement. Promotion events are created by specifying a promotion action string, and one or more promotions. When constructing a promotion it’s recommended to specify at least an ID or a name.

var promotion = mParticle.eCommerce.createPromotion('my_promo_1', 'sale_banner_1', 'App-wide 50% off sale', 1);
mParticle.eCommerce.logPromotion(mParticle.PromotionType.PromotionClick, promotion);

Impression Events

Use impressions to represent any time one or more products are displayed on the screen, and optionally specify a name for the location or list in which the products appeared.

var impression = mParticle.eCommerce.createImpression('suggested products list', product);
mParticle.eCommerce.logImpression(impression);

Note that the impression argument can either be a single impression, or an array of impressions.