Added css-events tracker parameter. Closes #1018.
parent
5ca6f76daa
commit
cdd7273194
|
@ -22,6 +22,7 @@ import { removeTrailingSlash } from '../lib/url';
|
||||||
const autoTrack = attr('data-auto-track') !== 'false';
|
const autoTrack = attr('data-auto-track') !== 'false';
|
||||||
const dnt = attr('data-do-not-track');
|
const dnt = attr('data-do-not-track');
|
||||||
const useCache = attr('data-cache');
|
const useCache = attr('data-cache');
|
||||||
|
const cssEvents = attr('data-css-events') !== 'false';
|
||||||
const domain = attr('data-domains') || '';
|
const domain = attr('data-domains') || '';
|
||||||
const domains = domain.split(',').map(n => n.trim());
|
const domains = domain.split(',').map(n => n.trim());
|
||||||
|
|
||||||
|
@ -29,7 +30,7 @@ import { removeTrailingSlash } from '../lib/url';
|
||||||
const eventSelect = "[class*='umami--']";
|
const eventSelect = "[class*='umami--']";
|
||||||
const cacheKey = 'umami.cache';
|
const cacheKey = 'umami.cache';
|
||||||
|
|
||||||
const disableTracking = () =>
|
const trackingDisabled = () =>
|
||||||
(localStorage && localStorage.getItem('umami.disabled')) ||
|
(localStorage && localStorage.getItem('umami.disabled')) ||
|
||||||
(dnt && doNotTrack()) ||
|
(dnt && doNotTrack()) ||
|
||||||
(domain && !domains.includes(hostname));
|
(domain && !domains.includes(hostname));
|
||||||
|
@ -75,7 +76,7 @@ import { removeTrailingSlash } from '../lib/url';
|
||||||
};
|
};
|
||||||
|
|
||||||
const collect = (type, payload) => {
|
const collect = (type, payload) => {
|
||||||
if (disableTracking()) return;
|
if (trackingDisabled()) return;
|
||||||
|
|
||||||
post(
|
post(
|
||||||
`${root}/api/collect`,
|
`${root}/api/collect`,
|
||||||
|
@ -150,14 +151,6 @@ import { removeTrailingSlash } from '../lib/url';
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const monitorMutate = mutations => {
|
|
||||||
mutations.forEach(mutation => {
|
|
||||||
const element = mutation.target;
|
|
||||||
addEvent(element);
|
|
||||||
addEvents(element);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Handle history changes */
|
/* Handle history changes */
|
||||||
|
|
||||||
const handlePush = (state, title, url) => {
|
const handlePush = (state, title, url) => {
|
||||||
|
@ -177,6 +170,19 @@ import { removeTrailingSlash } from '../lib/url';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const observeDocument = () => {
|
||||||
|
const monitorMutate = mutations => {
|
||||||
|
mutations.forEach(mutation => {
|
||||||
|
const element = mutation.target;
|
||||||
|
addEvent(element);
|
||||||
|
addEvents(element);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const observer = new MutationObserver(monitorMutate);
|
||||||
|
observer.observe(document, { childList: true, subtree: true });
|
||||||
|
};
|
||||||
|
|
||||||
/* Global */
|
/* Global */
|
||||||
|
|
||||||
if (!window.umami) {
|
if (!window.umami) {
|
||||||
|
@ -189,17 +195,18 @@ import { removeTrailingSlash } from '../lib/url';
|
||||||
|
|
||||||
/* Start */
|
/* Start */
|
||||||
|
|
||||||
if (autoTrack && !disableTracking()) {
|
if (autoTrack && !trackingDisabled()) {
|
||||||
history.pushState = hook(history, 'pushState', handlePush);
|
history.pushState = hook(history, 'pushState', handlePush);
|
||||||
history.replaceState = hook(history, 'replaceState', handlePush);
|
history.replaceState = hook(history, 'replaceState', handlePush);
|
||||||
|
|
||||||
const update = () => {
|
const update = () => {
|
||||||
if (document.readyState === 'complete') {
|
if (document.readyState === 'complete') {
|
||||||
addEvents(document);
|
|
||||||
trackView();
|
trackView();
|
||||||
|
|
||||||
const observer = new MutationObserver(monitorMutate);
|
if (cssEvents) {
|
||||||
observer.observe(document, { childList: true, subtree: true });
|
addEvents(document);
|
||||||
|
observeDocument();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue