Purchase

The following describes how purchase tracking is done for Firework.

How to implement the "purchase" tracking event

Please ensure you send all the purchase events happening in your website to us. Please do not filter out any events on your side. This information is required to identify your Firework attributed vs Non Firework purchases. This also helps us calculate the lift in GMV and AOV with Firework.

<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 }]
            //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
  order_id: string
  order_value: number
  currency: string
  country: string
  subtotal?: number
  payment_method?: string
  product?: Array<{ 
    ext_parent_product_id:string; 
    parent_product_name:string;  
    ext_product_id:string; 
    product_name:string; 
    image?: string;
    price: number; 
    currency?: string;
    sku?: string;
    quantity: number 
  }>
}

Debugging issues with purchase tracking

To ensure that the purchase tracking is implemented correctly you can follow the steps below

  1. Open browser developer tools

  2. Goto "Sources" tab

  3. Choose the "/thank_you" page

  4. Find the part of the DOM which contains our tracking code snippet

  5. 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.

If you already have added the Firework purchase tracking snippet under your Order Status Page, we recommend removing that as updating to the latest Shopify app version will add the tracking code automatically.

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