Manually set up a post purchase event
ImportantOnly use this method if you are unable to use the Taboola Pixel app.
This page describes how to manually set up a post purchase event for your post-purchase upsell appin Shopify.
Create a conversion rule in Realize
-
Open Realize, and select the account (top, left) that you will use to track conversions.
-
In the sidebar (left), select
Tracking
. -
Click on
+ New conversion
(far right). Then selectInstall events using code
and clickContinue
. -
Type in a
Conversion Name
of your choice - e.g.Upsell Purchase
.This is a descriptive name for your convenience.
-
For
Conversion Type
, selectEVENT
: -
Leave
Fixed Value
blank (since this value is dynamic).For additional guidelines, see the Help Center.
-
Under
Category
, selectMake Purchase
. -
Edit the
Event Name
to readupsell_purchase
(or similar). -
Make sure that the
Include in total value
andInclude in total conversions
checkboxes are checked. -
(Optional) If desired, tweak the values of the remaining fields.
For additional guidelines, see the Help Center.
-
Scroll down to the
Event Code
section, and select the relevantdynamic parameters
.Note how the code snippet updates accordingly. For detailed guidelines, see: Track dynamic conversion values
-
Review your chosen settings, and click on
Create
(bottom, right):

Add a code snippet to Shopify
-
In your Shopify dashboard, select
Settings
>Checkout
. -
Scroll down to
Post-purchase page
section. -
Copy the code snippet provided below and paste it under
Additional scripts
.Mouse over the code snippet and click on
copy
(top, right).
-
Edit the script and replace
DYNAMIC_ACCOUNT_ID
with your own Taboola Account ID on the first line. -
Once you are done with your editing, click on
Save
.Make sure to fill in your own Taboola Account ID.
<script>
// Replace with your Taboola account ID
var TABOOLA_ACCOUNT_ID = 'DYNAMIC_ACCOUNT_ID';
window._tfa = window._tfa || [];
!function (t, f, a, x ) {
if (!document.getElementById(x)) {
t.async = 1;t.src = a;t.id=x;f.parentNode.insertBefore(t, f);
}
}(document.createElement('script'),
document.getElementsByTagName('script')[0],
'//cdn.taboola.com/libtrc/unip/' + TABOOLA_ACCOUNT_ID + '/tfa.js',
'tb_tfa_script');
window.Shopify = window.Shopify || {};
if (Shopify.on) {
Shopify.on('CheckoutAmended', function (newOrder, previousOrder) {
try {
console.log('[TaboolaPixel] CheckoutAmended event fired', newOrder, previousOrder);
var oldItems = (previousOrder && previousOrder.lineItems) || [];
var oldItemsIds = oldItems.map(function (item) {
return item && item.id;
});
var newItems = (newOrder && newOrder.lineItems) || [];
var addedItems = newItems.filter(function (item) {
var itemId = item && item.id;
return itemId && oldItemsIds.indexOf(itemId) < 0;
});
console.log('[TaboolaPixel] Previous item IDs:', oldItems);
console.log('[TaboolaPixel] Newly added items:', addedItems);
if (addedItems.length === 0) {
console.log('[TaboolaPixel] No new items detected — event will not be fired');
return;
}
var totalQuantity = 0;
var totalRevenue = addedItems.reduce(function (sum, item) {
var finalPrice = (item && item.finalPrice) || 0;
var quantity = (item && item.quantity) || 0;
totalQuantity = totalQuantity + quantity;
return sum + (finalPrice * quantity);
}, 0);
var currency = (newOrder && newOrder.currency) || 'USD';
var newOrderId = (newOrder && newOrder.id) || '';
var taboolaEvent = {
notify: 'event',
name: 'upsell_purchase',
id: TABOOLA_ACCOUNT_ID,
revenue: totalRevenue,
currency: currency,
orderid: newOrderId,
quantity: totalQuantity
};
console.log('[TaboolaPixel] Final event object:', taboolaEvent);
_tfa.push(taboolaEvent);
console.log('[TaboolaPixel] Event pushed to _tfa');
} catch (error) {
console.error('[TaboolaPixel] Error in CheckoutAmended handler:', error);
}
});
}
</script>
Updated 13 days ago