Purchase
The following describes how purchase tracking is done for Firework.
How to implement the "purchase" tracking event
<script>
function onPurchase() {
window._fwn.analytics.purchase({
order_id: '23423',
order_value: '35.54',
currency: 'CAD',
country: 'Canada',
subtotal: '31.89',
payment_method: 'AMEX',
product: [{
ext_parent_product_id:'6692',
ext_product_id: '4483',
parent_product_name:'V-Neck Tshirt',
product_name:'V Neck Tshirt - L Blue',
price: 31,
quantity: 1,
currency: 'CAD',
url: "https//www.xx.com/product/xxx"
}]
//ext_parent_product_id is the ID of the parent product and ext_product_id is the variant ID. Same goes for title as well
});
}
//Call the function when purchase happens or on the load of thank you or order confirmation page
document.addEventListener('DOMContentLoaded', function() {
onPurchase();
});
</script>
Note: The purchase function expects the following input shape:
export interface PurchaseData {
ext_customer_identifier?: string //customer_identifier from customer site
order_id: string //Order ID from customer site
order_value: number //Total value of order
currency: string //Currency, for example: USD
country: string //Country code, for example: US
subtotal: number //Subtotal, without shipping fee. usually order_value = subtotal + shipping fee.
payment_method?: string // payment method: for example: creditcard, bank, paypal, others
product: Array<{
ext_parent_product_id:string; //product_id
ext_product_id:string; //unit_id or variant_id
parent_product_name:string; //product name
product_name:string; //unit name or variant name
image?: string; //image
sku?: string: //sku
price: number; //price of variant
currency: string; //currency
quantity: number; //quantity
url: string // url link for variant or product
}>
}
Example:
{
"order_id": "61947935457",
"order_value": 57.98,
"currency": "USD",
"country": "US",
"subtotal": 49.99,
"product": [
{
"ext_parent_product_id": "xxxxxxxx",
"ext_product_id": "xxxxxx",
"parent_product_name": "xxxxxx",
"product_name": "XXXX",
"image": "https://cdn.xxxx.com/s/files/xxx.png",
"price": 49.99,
"currency": "USD",
"quantity": 1,
"url": "https://xxx.com/products/xxxx"
}
]
}
Debugging issues with purchase tracking
To ensure that the purchase tracking is implemented correctly you can follow the steps below
Open browser developer tools
Goto "Sources" tab
Choose the "/thank_you" page
Find the part of the DOM which contains our tracking code snippet
Ensure there are no errors appearing anywhere in that code

To ensure that the data you are sending is accurate you may try printing the transaction data to the console. You may find all the information related to the Shopify transaction data here - https://shopify.dev/docs/api/liquid/objects/transaction
You will not be able to print out the entire transaction object as Shopify prevents this. However you will be able to inspect the part that you are interested in. For example something like this
let debugTransaction = {
payment_details: { { transaction.payment_details | json } }
}
console.log("debugTransaction: ", debugTransaction)
Shopify <> Firework Purchase Tracking
With the latest Firework app in Shopify, you do not need explicitly do any steps for implementing purchase tracking. The purchase tracking code is integrated automatically when the Firework app is installed in Shopify.
Verifying purchase tracking in Shopify
You could perform a test purchase and on the order confirmation page, check for the user:purchase
event in your network tab

Last updated
Was this helpful?