## Overview

The Enhanced Analytics plugin for the `Affirm.js` library is a simple, easy-to-use tool allowing deeper integration with Affirm to measure customer interactions across your site. With Enhanced Analytics enabled, Affirm is better able to help you understand your customers’ financial preferences and tailor their shopping experiences accordingly.

## How it works

As a user navigates between web pages, Affirm.js records information about their session. This includes discrete events for tracking product impressions, viewing product details, adding to or removing from the shopping cart, initiating the checkout process, and completing a purchase.

The most important signal that Affirm can use to help you increase the value of your integration comes from order confirmation data; as a result, sending this event type is the only requirement in integrating Enhanced Analytics.

## Sending confirmation events

#### <span style="color:green">Function</span>: trackOrderConfirmed ([Order](🔗), Optional\[[Strict](🔗)])

The `trackOrderConfirmed` function accepts basic data about each confirmed customer order from your confirmation page and sends the details to Affirm’s improved data pipeline for use in our analytics tools.

## Implementation

Track Order Confirmed implementation
Open Recipe

1\. Add the `Affirm.js` SDK to the confirmation page (Affirm.js may already be loaded on all site pages for some merchants) 2\. Upon load of the confirmation page, prepare the following data to be passed to the `trackOrderConfirmed` function.

  • [`Order`](🔗) object - JSON object containing the following details:

    • [`currency`](🔗)

    • [`orderID`](🔗)

    • [`paymentMethod`](🔗)

    • [`total`](🔗)

3\. Call the `trackOrderConfirmed` function and provide the previously gathered data as the parameters. We included an example call below.

Passing the _null_ value

You can pass `null` in second required parameter. This was formerly the `product` array in our [Legacy Enhanced Analytics](🔗). If you keep the existing parameters to include the `product` array, we'll simply ignore the value and treat it as `null`.

Passing the _true_ value

The true value in the third parameter is also required

## Objects

### Order

ParameterData typeDescription
<a name="order"></a> `order` <span style="color:red">required</span>ObjectContains details about the customer’s order

The order object should contain the following details:

ParameterData typeDescription
<a name="currency"></a> `currency` <span style="color:red">required</span>_string_Three-letter ISO currency code, in uppercase. Possible values: - USD - CAD
<a name="orderid"></a> `orderID` <span style="color:red">required</span>_string_Unique identifier representing the order/transaction in your system
<a name="paymentmethod"></a> `paymentMethod` <span style="color:red">required</span>_string_Description of payment method used (ex. “Visa”, “Mastercard”, “Gift Card”,"Affirm")
<a name="total"></a> `total` <span style="color:red">required</span>_integer_The total value of the transaction, including tax and shipping. The value must be non-negative and represented as cents instead of dollars.