Skip to content

Instantly share code, notes, and snippets.

@elliotlings
Created March 16, 2023 17:01
Show Gist options
  • Save elliotlings/70547ba59ca495ab6288b4776129bb4b to your computer and use it in GitHub Desktop.
Save elliotlings/70547ba59ca495ab6288b4776129bb4b to your computer and use it in GitHub Desktop.
Salesfire tracking code for Ecwid
;(function() {
var found = false;
var giveUp = false;
function find() {
if (found || giveUp) {
return;
}
if (window._swOTP) {
track(window._swOTP);
found = true;
return;
}
setTimeout(find, 100);
}
find();
setTimeout(function() {
giveUp = true;
}, 5000);
function track(data) {
window.sfDataLayer = window.sfDataLayer || [];
window.sfDataLayer.push({
"ecommerce" : {
"purchase": {
"id": data.orderNumber,
"revenue": data.subtotal,
"shipping": data.shipping,
"tax": data.tax,
"currency": "GBP",
"products": (data.items || []).map(function(item) {
return {
"sku": item.product.sku,
"parent_sku": item.product.sku,
"name": item.product.name,
"variant": item.product.name,
"price": item.product.price,
"quantity": item.quantity,
"currency": "GBP"
};
}),
}
}
});
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment