mirror of
https://github.com/umami-software/umami.git
synced 2026-02-15 10:05:36 +01:00
Fix #3603: Add guard to prevent tracker from running multiple times
This commit is contained in:
parent
372d1d86f4
commit
d590c6b078
1 changed files with 16 additions and 3 deletions
|
|
@ -1,4 +1,9 @@
|
||||||
(window => {
|
(window => {
|
||||||
|
// Prevent multiple executions
|
||||||
|
if (window.umami && window.umami.version) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
screen: { width, height },
|
screen: { width, height },
|
||||||
navigator: { language, doNotTrack: ndnt, msDoNotTrack: msdnt },
|
navigator: { language, doNotTrack: ndnt, msDoNotTrack: msdnt },
|
||||||
|
|
@ -35,6 +40,8 @@
|
||||||
const eventRegex = /data-umami-event-([\w-_]+)/;
|
const eventRegex = /data-umami-event-([\w-_]+)/;
|
||||||
const eventNameAttribute = _data + 'umami-event';
|
const eventNameAttribute = _data + 'umami-event';
|
||||||
const delayDuration = 300;
|
const delayDuration = 300;
|
||||||
|
// Add credentials option
|
||||||
|
const credentials = attr(_data + 'credentials') || 'omit'; // Default to 'omit' for security
|
||||||
|
|
||||||
/* Helper functions */
|
/* Helper functions */
|
||||||
|
|
||||||
|
|
@ -165,7 +172,7 @@
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
...(typeof cache !== 'undefined' && { 'x-umami-cache': cache }),
|
...(typeof cache !== 'undefined' && { 'x-umami-cache': cache }),
|
||||||
},
|
},
|
||||||
credentials: 'omit',
|
credentials, // Use configurable credentials instead of hardcoded 'omit'
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|
@ -216,11 +223,17 @@
|
||||||
window.umami = {
|
window.umami = {
|
||||||
track,
|
track,
|
||||||
identify,
|
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 currentUrl = normalize(href);
|
||||||
let currentRef = normalize(referrer.startsWith(origin) ? '' : referrer);
|
let currentRef = referrer && referrer.startsWith(origin) ? '' : normalize(referrer);
|
||||||
|
|
||||||
let initialized = false;
|
let initialized = false;
|
||||||
let disabled = false;
|
let disabled = false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue