Merge branch 'umami-software:master' into fix/tracker-single-init
This commit is contained in:
1148 files changed
+55615
-29474
No files matched your search
+22
-9
@@ -21,6 +21,7 @@
|
||||
const _false = 'false';
|
||||
const _true = 'true';
|
||||
const attr = currentScript.getAttribute.bind(currentScript);
|
||||
|
||||
const website = attr(_data + 'website-id');
|
||||
const hostUrl = attr(_data + 'host-url');
|
||||
const beforeSend = attr(_data + 'before-send');
|
||||
@@ -30,6 +31,8 @@
|
||||
const excludeSearch = attr(_data + 'exclude-search') === _true;
|
||||
const excludeHash = attr(_data + 'exclude-hash') === _true;
|
||||
const domain = attr(_data + 'domains') || '';
|
||||
const credentials = attr(_data + 'fetch-credentials') || 'omit';
|
||||
|
||||
const domains = domain.split(',').map(n => n.trim());
|
||||
const host =
|
||||
hostUrl || '__COLLECT_API_HOST__' || currentScript.src.split('/').slice(0, -1).join('/');
|
||||
@@ -41,6 +44,18 @@
|
||||
|
||||
/* 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 {
|
||||
return raw;
|
||||
}
|
||||
};
|
||||
|
||||
const getPayload = () => ({
|
||||
website,
|
||||
screen,
|
||||
@@ -64,11 +79,7 @@
|
||||
if (!url) return;
|
||||
|
||||
currentRef = currentUrl;
|
||||
currentUrl = new URL(url, location.href);
|
||||
|
||||
if (excludeSearch) currentUrl.search = '';
|
||||
if (excludeHash) currentUrl.hash = '';
|
||||
currentUrl = currentUrl.toString();
|
||||
currentUrl = normalize(new URL(url, location.href).toString());
|
||||
|
||||
if (currentUrl !== currentRef) {
|
||||
setTimeout(track, delayDuration);
|
||||
@@ -146,7 +157,7 @@
|
||||
const callback = window[beforeSend];
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
payload = callback(type, payload);
|
||||
payload = await Promise.resolve(callback(type, payload));
|
||||
}
|
||||
|
||||
if (!payload) return;
|
||||
@@ -160,7 +171,7 @@
|
||||
'Content-Type': 'application/json',
|
||||
...(typeof cache !== 'undefined' && { 'x-umami-cache': cache }),
|
||||
},
|
||||
credentials: 'omit',
|
||||
credentials,
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
@@ -168,6 +179,7 @@
|
||||
disabled = !!data.disabled;
|
||||
cache = data.cache;
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
} catch (e) {
|
||||
/* no-op */
|
||||
}
|
||||
@@ -213,8 +225,9 @@
|
||||
};
|
||||
}
|
||||
|
||||
let currentUrl = href;
|
||||
let currentRef = referrer.startsWith(origin) ? '' : referrer;
|
||||
let currentUrl = normalize(href);
|
||||
let currentRef = normalize(referrer.startsWith(origin) ? '' : referrer);
|
||||
|
||||
let initialized = false;
|
||||
let disabled = false;
|
||||
let cache;
|
||||
|
||||
Reference in new issue
Block a user