Ability to unregister umami
parent
8727dbf282
commit
2ea91aaabf
|
@ -39,12 +39,14 @@ export const put = (url, params) => apiRequest('put', url, JSON.stringify(params
|
||||||
|
|
||||||
export const hook = (_this, method, callback) => {
|
export const hook = (_this, method, callback) => {
|
||||||
const orig = _this[method];
|
const orig = _this[method];
|
||||||
|
_this[method] = (...args) => {
|
||||||
return (...args) => {
|
|
||||||
callback.apply(null, args);
|
callback.apply(null, args);
|
||||||
|
|
||||||
return orig.apply(_this, args);
|
return orig.apply(_this, args);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
_this[method] = orig;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const doNotTrack = () => {
|
export const doNotTrack = () => {
|
||||||
|
|
|
@ -73,8 +73,8 @@ import { removeTrailingSlash } from '../lib/url';
|
||||||
pageView();
|
pageView();
|
||||||
};
|
};
|
||||||
|
|
||||||
history.pushState = hook(history, 'pushState', handlePush);
|
const pushStateUnhook = hook(history, 'pushState', handlePush);
|
||||||
history.replaceState = hook(history, 'replaceState', handlePush);
|
const replaceStateUnhook = hook(history, 'replaceState', handlePush);
|
||||||
|
|
||||||
/* Handle events */
|
/* Handle events */
|
||||||
|
|
||||||
|
@ -106,4 +106,12 @@ import { removeTrailingSlash } from '../lib/url';
|
||||||
if (!window.umami) {
|
if (!window.umami) {
|
||||||
window.umami = event_value => collect('event', { event_type: 'custom', event_value });
|
window.umami = event_value => collect('event', { event_type: 'custom', event_value });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!window.umamiUnregister) {
|
||||||
|
window.umamiUnregister = () => {
|
||||||
|
pushStateUnhook();
|
||||||
|
replaceStateUnhook();
|
||||||
|
removeEvents();
|
||||||
|
};
|
||||||
|
}
|
||||||
})(window);
|
})(window);
|
||||||
|
|
Loading…
Reference in New Issue