mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Script simplification: Final minor cleanups
This commit is contained in:
parent
5369144b64
commit
9b9cf32ee7
1 changed files with 6 additions and 10 deletions
|
|
@ -20,7 +20,7 @@
|
||||||
const attr = currentScript.getAttribute.bind(currentScript);
|
const attr = currentScript.getAttribute.bind(currentScript);
|
||||||
const website = attr(_data + 'website-id');
|
const website = attr(_data + 'website-id');
|
||||||
const hostUrl = attr(_data + 'host-url');
|
const hostUrl = attr(_data + 'host-url');
|
||||||
const tag = attr(_data + 'tag');
|
const tag = attr(_data + 'tag') || undefined;
|
||||||
const autoTrack = attr(_data + 'auto-track') !== _false;
|
const autoTrack = attr(_data + 'auto-track') !== _false;
|
||||||
const dnt = attr(_data + 'do-not-track') === _true;
|
const dnt = attr(_data + 'do-not-track') === _true;
|
||||||
const excludeSearch = attr(_data + 'exclude-search') === _true;
|
const excludeSearch = attr(_data + 'exclude-search') === _true;
|
||||||
|
|
@ -45,7 +45,7 @@
|
||||||
hostname,
|
hostname,
|
||||||
url: currentUrl,
|
url: currentUrl,
|
||||||
referrer: currentRef,
|
referrer: currentRef,
|
||||||
tag: tag ? tag : undefined,
|
tag,
|
||||||
});
|
});
|
||||||
|
|
||||||
const hasDoNotTrack = () => {
|
const hasDoNotTrack = () => {
|
||||||
|
|
@ -73,10 +73,8 @@
|
||||||
const handlePathChanges = () => {
|
const handlePathChanges = () => {
|
||||||
const hook = (_this, method, callback) => {
|
const hook = (_this, method, callback) => {
|
||||||
const orig = _this[method];
|
const orig = _this[method];
|
||||||
|
|
||||||
return (...args) => {
|
return (...args) => {
|
||||||
callback.apply(null, args);
|
callback.apply(null, args);
|
||||||
|
|
||||||
return orig.apply(_this, args);
|
return orig.apply(_this, args);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -87,14 +85,13 @@
|
||||||
|
|
||||||
const handleClicks = () => {
|
const handleClicks = () => {
|
||||||
const trackElement = async el => {
|
const trackElement = async el => {
|
||||||
const attr = el.getAttribute.bind(el);
|
const eventName = el.getAttribute(eventNameAttribute);
|
||||||
const eventName = attr(eventNameAttribute);
|
|
||||||
if (eventName) {
|
if (eventName) {
|
||||||
const eventData = {};
|
const eventData = {};
|
||||||
|
|
||||||
el.getAttributeNames().forEach(name => {
|
el.getAttributeNames().forEach(name => {
|
||||||
const match = name.match(eventRegex);
|
const match = name.match(eventRegex);
|
||||||
if (match) eventData[match[1]] = attr(name);
|
if (match) eventData[match[1]] = el.getAttribute(name);
|
||||||
});
|
});
|
||||||
|
|
||||||
return track(eventName, eventData);
|
return track(eventName, eventData);
|
||||||
|
|
@ -106,8 +103,7 @@
|
||||||
if (!parentElement) return trackElement(el);
|
if (!parentElement) return trackElement(el);
|
||||||
|
|
||||||
const { href, target } = parentElement;
|
const { href, target } = parentElement;
|
||||||
const eventName = parentElement.getAttribute(eventNameAttribute);
|
if (!parentElement.getAttribute(eventNameAttribute)) return;
|
||||||
if (!eventName) return;
|
|
||||||
|
|
||||||
if (parentElement.tagName === 'BUTTON') {
|
if (parentElement.tagName === 'BUTTON') {
|
||||||
return trackElement(parentElement);
|
return trackElement(parentElement);
|
||||||
|
|
@ -158,7 +154,7 @@
|
||||||
cache = data.cache;
|
cache = data.cache;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
/* empty */
|
/* no-op */
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue