mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
fix(hash): improve URL normalization and handling in tracking functions
This commit is contained in:
parent
1b6da0aaa0
commit
c5298d5d45
1 changed files with 16 additions and 7 deletions
|
|
@ -38,6 +38,18 @@
|
||||||
|
|
||||||
/* Helper functions */
|
/* Helper functions */
|
||||||
|
|
||||||
|
const normalize = raw => {
|
||||||
|
if (!raw) return raw;
|
||||||
|
try {
|
||||||
|
const u = new URL(raw, location.href);
|
||||||
|
if (excludeSearch) u.search = '';
|
||||||
|
if (excludeHash) u.hash = '';
|
||||||
|
return u.toString();
|
||||||
|
} catch (e) {
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const getPayload = () => ({
|
const getPayload = () => ({
|
||||||
website,
|
website,
|
||||||
screen,
|
screen,
|
||||||
|
|
@ -61,11 +73,7 @@
|
||||||
if (!url) return;
|
if (!url) return;
|
||||||
|
|
||||||
currentRef = currentUrl;
|
currentRef = currentUrl;
|
||||||
currentUrl = new URL(url, location.href);
|
currentUrl = normalize(new URL(url, location.href).toString());
|
||||||
|
|
||||||
if (excludeSearch) currentUrl.search = '';
|
|
||||||
if (excludeHash) currentUrl.hash = '';
|
|
||||||
currentUrl = currentUrl.toString();
|
|
||||||
|
|
||||||
if (currentUrl !== currentRef) {
|
if (currentUrl !== currentRef) {
|
||||||
setTimeout(track, delayDuration);
|
setTimeout(track, delayDuration);
|
||||||
|
|
@ -210,8 +218,9 @@
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let currentUrl = href;
|
let currentUrl = normalize(href);
|
||||||
let currentRef = referrer.startsWith(origin) ? '' : referrer;
|
let currentRef = normalize(referrer.startsWith(origin) ? '' : referrer);
|
||||||
|
|
||||||
let initialized = false;
|
let initialized = false;
|
||||||
let disabled = false;
|
let disabled = false;
|
||||||
let cache;
|
let cache;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue