Purchase
The following describes how purchase tracking is done for Firework.
How to implement the "purchase" tracking event
<script>
function onPurchase() {
let purchasePayload = {
"order_id": "123456789",
"currency": "USD",
"subtotal": "40.00",
"total_discounts": "5.00",
"order_value": "50.00",
"line_items": [{
"sku": "TSHIRT-RED-M",
"quantity": 2,
"price": "15.00",
"name": "Red T-shirt (M)"
},
{
"sku": "BANANA",
"quantity": 10,
"price": "1.00",
"name": "Organic Banana"
}
]
};
window._fwn.analytics.purchase(purchasePayload);
}
//Call the function when purchase happens or on the load of thank you or order confirmation page
document.addEventListener('DOMContentLoaded', function() {
onPurchase();
});
</script>Payload for purchase tags:
order_id
string
required
The order ID. e.g. ‘12334’
currency
string
required
The currency used in this order. Has to be in ISO 4217 format.
subtotal
number
required
The cost of the items purchased before discounts, taxes and shipping costs are added
total_discounts
number
optional
The total amount of all discounts applied to the order in the currency's subunit
order_value
number
required
The total purchase order value is the final amount a customer pays, including all taxes, shipping, and any discounts applied
line_items
array
required
See line_items parameters table below. The tag needs to pass in either line_items or product
product
array
for backward compatibility
See product parameters table below
Payload for line_item:
sku
string
required
The ID that we can link back to the product or product unit. It can be the SKU, barcode, GTIN, MPN, product_unit.external_id, product.external_id
quantity
number
required
The quantity bought
price
number
required
The unit price of the line item. This includes any line-level discounts
product_name
string
optional
Name of the product variant or product unit
Payload for product:
ext_parent_product_id
string
required
Product ID from the client system, this maps to product.external_id
ext_product_id
string
required
Product Unit ID from the client system, this maps to product_unit.external_id
parent_product_name
string
required
Name of the product
product_name
string
required
Name of the product variant or product unit
image
string
optional
sku
string
optional
price
number
required
The unit price of the line item. This includes any line-level discounts
currency
string
required
Currency in ISO 4217 format
quantity
number
required
The quantity bought
url
string
required
URL for the variant or product
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?