Confirmation Page Analytics
Overview
Our Affirm.js
library now includes Confirmation Page Analytics. Confirmation Page Analytics offers insight into how customers interact with your site on the confirmation page. 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 and comprehensively measure the eCommerce lifecycle. You can send this information by adding the Confirmation Page function to your order confirmation page. Additionally, you can enable our Enhanced analytics functions to measure customer interactions with your site across their entire shopping experience.
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 orderproducts
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 | Description | |
---|---|---|
storeName required | string Maximum 500 characters. | Your store name. |
checkoutId optional | string Maximum 500 characters. | Your internal unique identifier representing the checkout if it’s distinct from the order ID. If they are the same, only orderID is needed. |
coupon optional | string Maximum 500 characters. | The coupon code applied to the order (e.g., SUMMER2018). |
currency optional | string | USD |
discount optional | integer | The total discount applied to the order, stated in USD cents (e.g., $100 = 10000). |
orderID required | string Maximum 500 characters. | Your internal unique identifier representing the order. |
paymentMethod required | string Maximum 150 characters. | The payment method chosen by the customer (e.g., Visa) |
revenue optional | integer | The shipping cost associated with the order. |
shipping optional | integer | The shipping cost associated with the order. |
shippingMethod optional | string Maximum 150 characters. | The shipping method chosen by the customer (e.g., Fedex). |
tax optional | integer | The total tax amount associated with the order, stated in USD cents (e.g., $100 = 10000). |
total optional | 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. |
Product object
The product
object defines the product offered by the merchant.
Parameter | Description | |
---|---|---|
brand optional | string Maximum 500 characters. | The brand of the product (e.g., Affirm). |
category optional | string Maximum 500 characters. | The product category. |
coupon optional | string Maximum 500 characters. | Any coupon code applied to this particular product. |
name optional | string Maximum 500 characters. | The full name of the product (e.g., Affirm T-Shirt). |
price optional | integer | The price of the purchased product, stated in USD cents (e.g., $100 = 10000). |
productID required | string Maximum 500 characters. | Your unique internal identifier representing the product, such as the SKU or an internal database identifier. |
quantity optional | integer | The quantity of the purchased product. |
variant optional | string Maximum 500 characters. | The variant of the product (e.g. black). |
currency optional | string | A currency code associated with this product (USD) |
Updated about 1 month ago