Fix #3603: Add guard to prevent tracker from running multiple times

This commit is contained in:
Ayush3603 2025-11-10 18:22:58 +05:30
parent 372d1d86f4
commit d590c6b078

View file

@ -1,4 +1,9 @@
(window => {
// Prevent multiple executions
if (window.umami && window.umami.version) {
return;
}
const {
screen: { width, height },
navigator: { language, doNotTrack: ndnt, msDoNotTrack: msdnt },
@ -35,6 +40,8 @@
const eventRegex = /data-umami-event-([\w-_]+)/;
const eventNameAttribute = _data + 'umami-event';
const delayDuration = 300;
// Add credentials option
const credentials = attr(_data + 'credentials') || 'omit'; // Default to 'omit' for security
/* Helper functions */
@ -165,7 +172,7 @@
'Content-Type': 'application/json',
...(typeof cache !== 'undefined' && { 'x-umami-cache': cache }),
},
credentials: 'omit',
credentials, // Use configurable credentials instead of hardcoded 'omit'
});
const data = await res.json();
@ -216,11 +223,17 @@
window.umami = {
track,
identify,
version: '1.0.0' // Add version to indicate initialization
};
} else {
// If umami exists but without version, add the functions
window.umami.track = window.umami.track || track;
window.umami.identify = window.umami.identify || identify;
window.umami.version = '1.0.0';
}
let currentUrl = normalize(href);
let currentRef = normalize(referrer.startsWith(origin) ? '' : referrer);
let currentRef = referrer && referrer.startsWith(origin) ? '' : normalize(referrer);
let initialized = false;
let disabled = false;
@ -234,4 +247,4 @@
document.addEventListener('readystatechange', init, true);
}
}
})(window);
})(window);