Track purchase dynamic value in FB Ads (code only)
- Alex Denshik
- Mar 29, 2021
- 1 min read
Note: For Shopify sites, we have a separate post
What you need:
FB Pixel code must be installed on your site (see "How to create an FB Pixel" or “How to add FB Pixel code using GTM”)
You need to add code to the Checkout page, which will create a "Purchase" event for your FB Pixel and transfer dynamic data about the transaction from variables on the site.
Purchase variables (which store transaction data) vary from website to website, so you'll have to work with your developer to understand your website's variables (except Shopify).
Here are some common examples, it must be placed on the Checkout or Thank You page:
FB Transactions value tracking code for WooCommerce:
<script>
fbq('track', 'Purchase', {
value: <?php echo $order->get_order_total(); ?>
});
</script>
FB Transactions value tracking code for Squarespace:
<script>
fbq('track', 'Purchase', {
value: {orderGrandTotal}
});
</script>
FB Transactions value tracking code for BigCommerce:
<script>
fbq('track', 'Purchase', {
value: %%ORDER_SUBTOTAL%%;
});
</script>
FB Transactions value tracking code for Magento:
<script>
fbq('track', 'Purchase', {
value: <?php echo $amount; ?>
});
</script>
FB Transactions value tracking code for Shopify:
<script>
fbq('track', 'Purchase', {
value: {{ total_price | money_without_currency }},
currency: 'USD',
});
</script>