Created
March 16, 2023 17:01
-
-
Save elliotlings/70547ba59ca495ab6288b4776129bb4b to your computer and use it in GitHub Desktop.
Salesfire tracking code for Ecwid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(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