The Goal
Your Shopify store is set up to offer customers additional products after their initial purchase is complete. You want to track these valuable upsells as a distinct conversion event in Everflow to properly reward the partners who drive them.
This guide walks you through the process of placing a script in your Shopify settings to track those post-purchase events.
Before You Begin
- You need an active Shopify account with a post-purchase upsell app or feature enabled.
- In Everflow, you must have an Offer ready with a specific Advertiser-Level Event created for the upsell (e.g., "Post-Purchase" or "Upsell").
Code Snippet:
<script type="text/javascript">
var script = document.createElement('script');
script.onload = function() {
(function() {
var aid = INSERT_ADVERTISER_ID;
var adv_event_id = INSERT_ADVERTISER_EVENT_ID;
Shopify.on('CheckoutAmended', function(newOrder, previousOrder) {
var previousOrderSubtotal = previousOrder.subtotalPrice
var oldItems = previousOrder.lineItems.map(function(line) {
return line.id;
});
var addedItems = newOrder.lineItems.filter(
function(line) {
return oldItems.indexOf(line.id) < 0;
}
);
// no new items were added, so we skip conversion tracking
if (addedItems.length === 0) {
return;
}
// track additional purchase
var order = window.Shopify.order;
var amount = order.subtotalPrice - previousOrderSubtotal;
var order1 = {
"oid": order.id,
"items": []
}
for (var i = 0; i < order.lineItems.length; i++) {
var a = {};
a.ps = order.lineItems[i].title;
a.p = order.lineItems[i].price;
a.qty = order.lineItems[i].quantity;
order1.items.push(a)
}
EF.conversion({
aid: aid,
adv_event_id: adv_event_id,
amount: amount,
order_id: order.id,
email: order.customer.email,
coupon_code: order.discounts ? order.discounts[0].code : "",
order: order1,
})
});
})();
}
script.src = 'https://INSERT_TRACKING_DOMAIN/scripts/sdk/everflow.js';
script.async = true;
document.head.appendChild(script);
</script>Example (Using our sample data):
<script type="text/javascript">
var script = document.createElement('script');
script.onload = function() {
(function() {
var aid = 139;
var adv_event_id = 26;
Shopify.on('CheckoutAmended', function(newOrder, previousOrder) {
var previousOrderSubtotal = previousOrder.subtotalPrice
var oldItems = previousOrder.lineItems.map(function(line) {
return line.id;
});
var addedItems = newOrder.lineItems.filter(
function(line) {
return oldItems.indexOf(line.id) < 0;
}
);
// no new items were added, so we skip conversion tracking
if (addedItems.length === 0) {
return;
}
// track additional purchase
var order = window.Shopify.order;
var amount = order.subtotalPrice - previousOrderSubtotal;
var order1 = {
"oid": order.id,
"items": []
}
for (var i = 0; i < order.lineItems.length; i++) {
var a = {};
a.ps = order.lineItems[i].title;
a.p = order.lineItems[i].price;
a.qty = order.lineItems[i].quantity;
order1.items.push(a)
}
EF.conversion({
aid: aid,
adv_event_id: adv_event_id,
amount: amount,
order_id: order.id,
email: order.customer.email,
coupon_code: order.discounts ? order.discounts[0].code : "",
order: order1,
})
});
})();
}
script.src = 'https://www.serve-eflow-test.com/scripts/sdk/everflow.js';
script.async = true;
document.head.appendChild(script);
</script>
The Result
You're all set! When a customer completes an upsell after their initial purchase, the script will fire and send the conversion data to Everflow.
You will see it recorded under your designated upsell event, allowing you to accurately track performance and manage payouts for these high-value actions.