Closed SeanRizarre closed 1 month ago
Added this code:
<script> const xhrResponseSource = (callback) => { const origOpen = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function () { this.addEventListener("load", () => callback(this)); origOpen.apply(this, arguments); }; }; const isTrackerLoaded = (callback) => { if (window.tracker) { callback(); } else { let trackerLoaded = false; const intervalId = setInterval(() => { if (window.tracker && !trackerLoaded) { trackerLoaded = true; clearInterval(intervalId); callback(); } }, 100); } }; const trackTransaction = (transaction) => { window.tracker( "addTrans", transaction.orderId.toString(), "N/A", parseFloat(transaction.orderAmount), parseFloat(transaction.taxTotal) || 0, parseFloat(transaction.shippingCostTotal) || 0, (transaction.billingAddress.city || "N/A").toString(), (transaction.billingAddress.stateOrProvinceCode || "N/A").toString(), (transaction.billingAddress.countryCode || "N/A").toString(), "USD" ); transaction.lineItems.physicalItems.forEach((item) => { const { productId, sku, name, listPrice, quantity } = item; window.tracker( "addItem", transaction.orderId.toString(), item.sku.toString(), (item.name || "N/A").toString(), "N/A", parseFloat(item.listPrice || 0), parseInt(item.quantity || 1), "USD" ); }); window.tracker("trackTrans"); }; xhrResponseSource((xhr) => { const transaction = JSON.parse(JSON.stringify(JSON.parse(xhr.responseText))); if (transaction.status && transaction.orderAmount > 0) { try{ isTrackerLoaded(() => { trackTransaction(transaction); }); } catch (error) { console.log("Error: ", error); } } }); </script>
Added this code: