// Run on page load
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', trackPurchase);
} else {
trackPurchase();
}
// Also check for URL changes (single-page app behaviour)
var lastUrl = window.location.href;
setInterval(function() {
if (window.location.href !== lastUrl) {
lastUrl = window.location.href;
purchaseEventFiredOnThisPage = false; // reset per "page"
trackPurchase();
}
}, 1000);