Skip to main content

 

Affirm Merchant Help

Confirmation Page function

Overview

Our Affirm.js library now includes Enhanced Analytics. Enhanced Analytics offers insight into how customers interact with your site across their shopping experience. When a customer completes their purchase, you can send their order and product information to Affirm for tracking, A/B testing, which will help you optimize your site, allowing the ecommerce lifecycle to be measured comprehensively. You can send this information by adding the Confirmation Page function to your order confirmation page. 

1. Add Affirm.js 

Before adding Enhanced Analytics function, you need to add the Affirm.js embed code to your global page template or in the global header if you haven't already done so:

<!-- Affirm -->
<script>
 _affirm_config = {
   public_api_key:  "YOUR_PUBLIC_KEY",
   script:          "https://cdn1-sandbox.affirm.com/js/v2/affirm.js",
 };
 (function(l,g,m,e,a,f,b){var d,c=l[m]||{},h=document.createElement(f),n=document.getElementsByTagName(f)[0],k=function(a,b,c){return function(){a[b]._.push([c,arguments])}};c[e]=k(c,e,"set");d=c[e];c[a]={};c[a]._=[];d._=[];c[a][b]=k(c,a,b);a=0;for(b="set add save post open empty reset on off trigger ready setProduct".split(" ");a<b.length;a++)d[b[a]]=k(c,e,b[a]);a=0;for(b=["get","token","url","items"];a<b.length;a++)d[b[a]]=function(){};h.async=!0;h.src=g[f];n.parentNode.insertBefore(h,n);delete g[f];d(g);l[m]=c})(window,_affirm_config,"affirm","checkout","ui","script","ready");
// Use your live public API Key and https://cdn1.affirm.com/js/v2/affirm.js script to point to Affirm production environment.
</script>
<!-- End Affirm -->

2. Add Confirmation Page Function

The trackOrderConfirmed event triggers when a customer completes their purchase. It measures the sale of one or more products. This function should be populated with order and products argument before adding it to the order confirmation page. All the values in the order and product arguments must be based on the order that was placed. We only require orderId, total, productId, and quantity for A/B testing.

Parameters:

  • order (object) - The order
  • products (array) - Products sold to the customer

Returns:

  • null

Example

affirm.ui.ready(function(){
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"
}]);
});

Data types

Order object

The Order object defines the customer's order when they begin the checkout process. It also includes transaction information when the customer completes checkout.

Parameter Type Description
storeName string Your store name. Maximum 500 characters. Required
checkoutId string Your internal unique identifier representing the checkout if it’s distinct from the order ID. If they are the same, only orderID is needed. Maximum 500 characters. Optional
coupon string The coupon code applied to the order (e.g., SUMMER2018). Maximum 500 characters. Optional
currency string USD Optional
discount integer The total discount applied to the order, stated in USD cents (e.g., $100 = 10000). Optional
orderId string Your internal unique identifier representing the order. Maximum 500 characters. Required
paymentMethod string The payment method chosen by the customer (e.g., Visa). Maximum 150 characters. Optional
revenue integer The net revenue amount of the order excluding shipping, total tax and discounts, stated in USD cents (e.g., $100 = 10000). Optional
shipping integer The shipping cost associated with the order. Optional
shippingMethod string The shipping method chosen by the customer (e.g., Fedex). Maximum 150 characters. Optional
tax integer The total tax amount associated with the order, stated in USD cents (e.g., $100 = 10000). Optional
total integer The total amount of the transaction including tax and shipping, stated in USD cents (e.g., $100 = 10000). If not sent, the total amount will be calculated using the product quantity and price fields of each product object passed. Optional

Product object

The Product object defines the product offered by the merchant.

Parameter Type Description
brand string The brand of the product (e.g., Affirm). Maximum 500 characters. Optional
category string The product category (e.g., apparel). Maximum 500 characters. Optional
coupon string Any coupon code applied to this particular product. Maximum 500 characters. Optional
name string The full name of the product (e.g., Affirm T-Shirt). Maximum 500 characters. Optional
price integer The price of the purchased product, stated in USD cents (e.g., $100 = 10000). Optional
productId string Your unique internal identifier representing the product, such as the SKU or an internal database identifier. Maximum 500 characters. Required
quantity integer The quantity of the purchased product. Optional
variant string The variant of the product (e.g. black). Maximum 500 characters. Optional
currency string A currency code associated with this product (USD) Optional

 

  • Was this article helpful?