Skip to main content

 

Affirm Merchant Help

Enhanced Analytics

Learn about our analytics solution to gain deeper insight into how customers interact with your e-commerce site.

Overview

The Enhanced Analytics plugin for the Affirm.js library is a simple, easy-to-use tool allowing you to measure and track customer interactions across your site. With Enhanced Analytics enabled, we’ll help you gain deeper insights into your business to continually optimize your financing programs to better fit your customer base. 

How it works

As a user navigates between web pages, Affirm.js records information about the page providing a complete evaluation of the e-commerce lifecycle. This includes discrete events for tracking product impressions, viewing product details, adding or removing a product to a shopping cart, initiating the checkout process, and completing a purchase and processing refunds.

Setup

Affirm.js is a JavaScript library for integrating Affirm with your site. To use the Enhanced Analytics plugin, you must first embed Affirm.js. This allows Affirm to collect and measure e-commerce activity on your website.

Measuring the e-commerce lifecycle

After embedding Affirm.js, you’ll have access to new enhanced analytics commands to begin tracking the following e-commerce lifecycle events:

Event category Event page Event action Event description
Browsing Search Result Page (SRP)

Products searched

Product list viewed

The user searched for one or more products.

The user viewed a product list or category.

Promotion Home page, Site-wide

Promotion viewed

Promotion clicked

The user viewed a promotion.

The user clicked on a promotion

Product Product detail page, Cart page

Product clicked

P0 - Product viewed

P0 - Product added

Product removed

P0 - Cart viewed

The user clicked on a product link.

The user viewed the details of a product.

The user added one or more products to their shopping cart.

The user removed one or more products from their shopping cart.

The user viewed their shopping cart. 

Checkout Checkout page

P0 - Checkout started

Checkout step viewed

Checkout step completed

Payment entered

The user initiated the order process.

The user viewed a checkout step.

The user completed a checkout step.

The user added payment information.

Order Purchase confirmation page

Order completed

Order updated

Order refunded

Order canceled

The user completed the order.

The user updated the order.

The user initiated an order refund.

The user canceled the order.

 

Enhanced Analytics events & functions

Use Enhanced Analytics functions on specific events you want to track and analyze during a customer’s shopping experience.

Note: All the operations in the following events are stateless and retain no information about previous events meaning that there is no order to the click events.

Browsing events

Browsing events represent customer interactions while browsing your e-commerce site.

trackProductsSearched(Product)

Triggered when a customer searches for products. 

Parameters:

  • query (string) - The query string used to search for products.

Returns: null

Example
affirm.analytics.trackProductsSearched("shirts");

trackProductListViewed: (list,[Product]) → None

An event triggered when a customer views a list of products, such as after completing a search, or on a category page that features multiple products.

Parameters:

  • list (object) - The list viewed by customers.

  • Products (array) - An array of products present in the list.

Returns: null

 Example

affirm.analytics.trackProductListViewed({
    "listId": "L12345",
    "category": "Apparel"
}, [{
    "brand": "Affirm",
    "category": "Apparel",
    "coupon": "SUMMER2018",
    "name": "Affirm T-Shirt",
    "price": 730,
    "productId": "SKU-1234",
    "quantity": 1,
    "variant": "Black"
}, {
    "brand": "Affirm",
    "category": "Apparel",
    "coupon": "SUMMER2018",
    "name": "Affirm Turtleneck Sweater",
    "price": 2190,
    "productId": "SKU-5678",
    "quantity": 1,
    "variant": "Black"
}]);

 Promotion events

Promotion events help you gather analytics on offers within your e-commerce website. Our enhanced analytics automatically tracks promotional information displayed by Affirm without any additional integrations.

trackPromotionViewed:(Promotion) → None

An event triggered when a customer views a promotion.

Parameters:

  • promotion (object) - The promotion the customer viewed.

Returns: null

Example

affirm.analytics.trackPromotionViewed({
    "creativeId": "promo_summer_sale_2100_variant1",
    "Message": "T-Shirt Sale 75% Off",
    "Position": "home_hero",
    "promotionId": "promo_summer_sale_2100"
});

trackPromotionClicked:(Promotion) → None

An event triggered when a customer clicks on a promotion.

Parameters:

  • promotion (object) - The promotion the customer clicked.

Returns: null

Example
affirm.analytics.trackPromotionClicked({
    "creativeId": "promo_summer_sale_2100_variant1",
    "Message": "T-Shirt Sale 75% Off",
    "Position": "home_hero",
    "promotionId": "promo_summer_sale_2100"
});

 Product events

Product events represent the customer’s journey as they choose and decide the product to order.

trackProductClicked:(Product) → None

An event triggered when a customer clicks on a product link to view more details.

Parameters:

  • product (object) - The product that the customer clicks on.

Returns: null

Example
affirm.analytics.trackProductClicked({
    "brand": "Affirm",
    "category": "Apparel",
    "coupon": "SUMMER2018",
    "name": "Affirm T-Shirt",
    "price": 730,
    "productId": "SKU-1234",
    "quantity": 1,
    "variant": "Black"
});

trackProductViewed: (Product) → None

An event triggered when a page dedicated to the product loads.

Parameters:

  • product (object) - The product the customer viewed.

Returns: null

Example
 affirm.analytics.trackProductViewed({
    "brand": "Affirm",
    "category": "Apparel",
    "coupon": "SUMMER2018",
    "name": "Affirm T-Shirt",
    "price": 730,
    "productId": "SKU-1234",
    "quantity": 1,
    "variant": "Black"
});

trackProductAdded: (Product, Optional[Cart]) → None

An event triggered when a customer adds a product to their cart.

Parameters:

  • product (object) - The the product that the customer adds to their cart.

  • cart (object, optional) - The cart the customer adds the product to. An undefined argument implies that customers may only have one cart at all times.

Returns: null

Example

 affirm.analytics.trackProductAdded({
    "brand": "Affirm",
    "category": "Apparel",
    "coupon": "SUMMER2018",
    "name": "Affirm T-Shirt",
    "price": 730,
    "productId": "SKU-1234",
    "quantity": 1,
    "variant": "Black"
}, {
    "cartId": "CART-1234",
    "name": "Main Cart"
});

 trackProductRemoved: (Product, Optional[Cart]) → None

An event triggered when a customer removes a product from their cart.

Parameters:

  • product (object) - The product that the customer adds to their cart.

  • cart (object, optional) - The cart the customer removes the product from. An undefined argument implies that customers may only have one cart at all times.

Returns: null

Example

affirm.analytics.trackProductRemoved({
    "brand": "Affirm",
    "category": "Apparel",
    "coupon": "SUMMER2018",
    "name": "Affirm T-Shirt",
    "price": 730,
    "productId": "SKU-1234",
    "quantity": 1,
    "variant": "Black"
}, {
    "cartId": "CART-1234",
    "name": "Main Cart"
});

trackCartViewed: (Product, Optional[Cart]) → None

An event triggered when a customer views their cart.

Parameters:

  • product (array) - The products in the cart when the customer viewed it.

  • cart (object, optional) - The cart the customer viewed. An undefined argument implies that customers may only have one cart at all times.

Returns: null

Example
 affirm.analytics.trackCartViewed([{
    "brand": "Affirm",
    "category": "Apparel",
    "coupon": "SUMMER2018",
    "name": "Affirm T-Shirt",
    "price": 730,
    "productId": "SKU-1234",
    "quantity": 1,
    "variant": "Black"
}, {
    "brand": "Affirm",
    "category": "Apparel",
    "coupon": "SUMMER2018",
    "name": "Affirm Turtleneck Sweater",
    "price": 2190,
    "productId": "SKU-5678",
    "quantity": 1,
    "variant": "Black"
}], {
    "cartId": "CART-1234",
    "name": "Main Cart"
});

Checkout events

The Checkout event represents the customer journey as they navigate through the checkout process.

trackCheckoutStarted: (Order, Optional[Product]) → None

An event triggered once the checkout process begins for the customer, typically on the page, the customer navigates to after pressing the checkout button.

Parameters:

  • order (object) - The order associated with this checkout.

  • products (array) - Products that are a part of the order.

Returns: null

Example
affirm.analytics.trackCheckoutStarted({
    "storeName": "Affirm Store",
    "coupon": "SUMMER2018",
    "currency": "USD",
    "discount": 0,
    "revenue": 2920,
    "shipping": 534,
    "tax": 285,
    "orderId": "T12345",
    "total": 3739
}, [{
    "brand": "Affirm",
    "category": "Apparel",
    "coupon": "SUMMER2018",
    "name": "Affirm T-Shirt",
    "price": 730,
    "productId": "SKU-1234",
    "quantity": 1,
    "variant": "Black"
}, {
    "brand": "Affirm",
    "category": "Apparel",
    "coupon": "SUMMER2018",
    "name": "Affirm Turtleneck Sweater",
    "price": 2190,
    "productId": "SKU-5678",
    "quantity": 1,
    "variant": "Black"
}]);

trackCheckoutStepViewed: (Integer, Order) → None

An event triggered when the customer views a distinct checkout step that is part of the checkout process.

Parameters:

  • step (integer) - An incrementing number representing the current step in the checkout process.

  • order (object) - The order associated with this checkout.

Returns: null

Example
affirm.analytics.trackCheckoutStepViewed(1, {
    "storeName": "Affirm Store",
    "coupon": "SUMMER2018",
    "currency": "USD",
    "discount": 0,
    "revenue": 2920,
    "shipping": 534,
    "tax": 285,
    "orderId": "T12345",
    "total": 3739
});

trackCheckoutStepCompleted: (Integer, Order) → None

An event triggered when the customer completes a distinct checkout step that is part of the checkout process.

Parameters:

  • step (integer) - An incrementing number representing the current step in the checkout process.

  • order (object) - The order associated with this checkout.

Returns: null

Example
affirm.analytics.trackCheckoutStepCompleted(1, {
    "storeName": "Affirm Store",
    "coupon": "SUMMER2018",
    "currency": "USD",
    "discount": 0,
    "revenue": 2920,
    "shipping": 534,
    "shippingMethod": "Fedex",
    "tax": 285,
    "orderId": "T12345",
    "total": 3739
});

Order events

Order events represent the key events once the customer finishes the checkout process, completes the purchase, and the order confirmation page loads.

trackOrderConfirmed:  (Order, Optional[Product]) → None

An event triggered when a customer completes the purchase. You can measure the sale of one or more products by this event.

Parameters:

  • order (object) - The order.

  • products (array) - Products that were sold to the customer.

Returns: null

Example
affirm.analytics.trackOrderConfirmed({
    "storeName": "Affirm Store",
    "coupon": "SUMMER2018",
    "currency": "USD",
    "discount": 0,
    "paymentMethod": "Visa",
    "revenue": 2920,
    "shipping": 534,
    "shippingMethod": "Fedex",
    "tax": 285,
    "orderId": "T12345",
    "total": 3739
}, [{
    "brand": "Affirm",
    "category": "Apparel",
    "coupon": "SUMMER2018",
    "name": "Affirm T-Shirt",
    "price": 730,
    "productId": "SKU-1234",
    "quantity": 1,
    "variant": "Black"
}, {
    "brand": "Affirm",
    "category": "Apparel",
    "coupon": "SUMMER2018",
    "name": "Affirm Turtleneck Sweater",
    "price": 2190,
    "productId": "SKU-5678",
    "quantity": 1,
    "variant": "Black"
}]);

trackOrderCancelled:  (Order, Optional[Product]) → None

An event triggered when a user cancels an order. 

Parameters:

  • order (object) - The canceled order.

  • products (array) - Products that were canceled by this order.

Returns: null

Example
affirm.analytics.trackOrderConfirmed({
    "storeName": "Affirm Store",
    "coupon": "SUMMER2018",
    "currency": "USD",
    "discount": 0,
    "paymentMethod": "Visa",
    "revenue": 2920,
    "shipping": 534,
    "shippingMethod": "Fedex",
    "tax": 285,
    "orderId": "T12345",
    "total": 3739
}, [{
    "brand": "Affirm",
    "category": "Apparel",
    "coupon": "SUMMER2018",
    "name": "Affirm T-Shirt",
    "price": 730,
    "productId": "SKU-1234",
    "quantity": 1,
    "variant": "Black"
}, {
    "brand": "Affirm",
    "category": "Apparel",
    "coupon": "SUMMER2018",
    "name": "Affirm Turtleneck Sweater",
    "price": 2190,
    "productId": "SKU-5678",
    "quantity": 1,
    "variant": "Black"
}]); 

trackOrderRefunded (String, String, Integer, Optional[Product]) → None

An event triggered when an order is partially or fully refunded.

Parameters:

  • orderId (string) - A unique identifier representing the transaction to fully or partially refund.

  • amount (integer) - The amount to refund, either partially or fully.

  • currency (string) - XXX

  • products (array) - An array of objects representing the products within the order correlated to the refund amount.

Returns: null

Example
affirm.analytics.trackOrderRefunded(
    "O12345", 3739, "USD",
    [{
        "brand": "Affirm",
        "category": "Apparel",
        "coupon": "SUMMER2018",
        "name": "Affirm T-Shirt",
        "price": 730,
        "productId": "SKU-1234",
        "quantity": 1,
        "variant": "Black"
    }, {
        "brand": "Affirm",
        "category": "Apparel",
        "coupon": "SUMMER2018",
        "name": "Affirm Turtleneck Sweater",
        "price": 2190,
        "productId": "SKU-5678",
        "quantity": 1,
        "variant": "Black"
    }]
);

trackOrderUpdated: (Order, Optional[Product]) → None

An event triggered when a user updates an order.

Parameters:

  • order (object) - The order that the customer updates.

  • products (array) - Products that are part of this order.

Returns: null

Example
affirm.analytics.trackOrderUpdated({
    "storeName": "Affirm Store",
    "coupon": "SUMMER2018",
    "currency": "USD",
    "discount": 0,
    "paymentMethod": "Visa",
    "revenue": 2920,
    "shipping": 534,
    "shippingMethod": "Fedex",
    "tax": 285,
    "orderId": "T12345",
    "total": 3739
}, [{
    "brand": "Affirm",
    "category": "Apparel",
    "coupon": "SUMMER2018",
    "name": "Affirm T-Shirt",
    "price": 730,
    "productId": "SKU-1234",
    "quantity": 1,
    "variant": "Black"
}, {
    "brand": "Affirm",
    "category": "Apparel",
    "coupon": "SUMMER2018",
    "name": "Affirm Turtleneck Sweater",
    "price": 2190,
    "productId": "SKU-5678",
    "quantity": 1,
    "variant": "Black"
}]);

Enhanced Analytics objects 

The Enhanced Analytics API uses a set of standard objects to represent the data you wish to track. 

Cart

Represents a user’s cart. This is an optional argument for most of the functions in the Enhanced Analytics API. It is intended to support analytics for e-commerce websites that allow customers to have multiple carts.

Parameter

Description

Protocol Parameter

cartId 

string

required

Maximum length: 500

A unique identifier representing the user’s cart.  A maximum of 500 characters.

ctid

name

string

optional

Maximum length: 500 

 

The name of the cart. 

ctnm

 

List

Represents a list of products appearing on any given page. This is frequently used to track products returned as a search result or included on a category page.

 

Parameter

Description

Protocol Parameter

listId 

string

required

Maximum length: 500

A unique identifier representing the list of products. 

ltid

category

string

optional

Maximum length: 500

A description of the category the list belongs to, if any. 

ltc

name

string

optional

Maximum length: 500

The display name of the list. 

ltnm

 

Order 

Represents a single customer’s checkout transaction. This includes parameters related to the transaction once the customer completes their checkout.

 

Parameter

Description

Protocol Parameter

checkoutId

string

optional

Maximum length: 500

A unique identifier representing the checkout, if it is conceptually distinct from an order. Otherwise only the orderId is necessary.

oci

couponCode

string

optional

Maximum length: 500

The coupon code associated with a transaction (e.g. SUMMER2018). 

occ

currency

string

optional

Maximum length: 500

The local currency for all transaction currency values. Value should be a valid subset of ISO 4217 currency code.

ocu

discount

integer

optional

The total discount associated with the transaction. The value must be non-negative and represented in minor units, such as cents instead of dollars.

od

orderId

string

optional

Maximum length: 500

A unique identifier representing the order/transaction.

ooi

paymentMethod

string

optional

Maximum length: 150

The payment method chosen by the customer for the transaction (e.g. Visa). A maximum of 150 characters.

opm

revenue

integer

optional

Revenue associated with transaction, excluding shipping, total tax and discounts. The value must be non-negative and represented as cents instead of dollars.

or

shipping

integer

optional

The shipping cost associated with the transaction.

os

shippingMethod

string

optional

Maximum length: 150

The shipping method chosen by the customer for the transaction (e.g. Fedex).

osm

storeName 

string

optional

Maximum length: 500

The name of the store responsible for this transaction. (e.g. Affirm Store). 

osn

tax

integer

optional

The total tax associated with the transaction. The value must be non-negative and represented in as cents instead of dollars.

otx

total

integer

optional

The total value of the transaction, including tax and shipping. If not sent, this value will be automatically calculated using the product quantity and price fields of all products in the same hit. The value must be non-negative and represented as cents instead of dollars.

ot

 

Product 

Represents any offered product or service.

 

Parameter

Description

Protocol Parameter

brand 

String

optional

Maximum length: 500

The brand associated with the product (e.g. Affirm).

prbr

category

String

optional

Maximum length: 500

The category the product belongs to (e.g. Apparel).

prca

coupon

String

optional

Maximum length: 500

Any coupon code associated with the particular instance of this product.

prcc

currency

String

optional

A currency code associated with this product 

prcu

name

String

optional

Maximum length: 500

The canonical name of the product (e.g. Affirm T-Shirt). 

prnm

price

integer

optional

The price of the product. The value must be non-negative and represented as cents instead of dollars.

prpr

productId

String

optional

Maximum length: 500

A unique identifier representing the product, such as the SKU or an internal database identifier used by the merchant. 

prid

quantity

integer

optional

The quantity of the product. The value must be non-negative.

prqt

variant

String

optional

Maximum length: 500

The variant of the product (e.g. black). 

prva

Promotion

Represents a promotion present on the e-commerce website, with or without creatives. Functions using a promotion to support multiple products to be associated with the promotion.

Parameter

Description

Protocol Parameter

creativeId 

String

optional

Maximum length: 500

An identifier for the creative used by the promotion.

pmmc

message

String

optional

Maximum length: 500

The messaging used in the promotion.

pmms

position

String

optional

Maximum length: 500

An identifier indicating where within the website the customer viewed the promotion (e.g. top_home).

pmpo

promotionId

String

optional

Maximum length: 500

A unique identifier of the promotion the customer viewed.

pmpi

  • Was this article helpful?