mirror of
https://github.com/umami-software/umami.git
synced 2026-02-19 20:15:41 +01:00
edit tracker script to work under SSR sites
This commit is contained in:
parent
3c906d066b
commit
bf4de2fbf5
2 changed files with 42 additions and 31 deletions
|
|
@ -84,12 +84,19 @@
|
|||
});
|
||||
|
||||
const getClientIPAddress = () => {
|
||||
if (ip) return ip;
|
||||
fetch('https://api64.ipify.org/?format=json')
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
ip = data.ip;
|
||||
});
|
||||
return new Promise(res => {
|
||||
if (ip) {
|
||||
res(ip);
|
||||
return;
|
||||
}
|
||||
fetch('https://api64.ipify.org/?format=json')
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
ip = data.ip;
|
||||
res(ip);
|
||||
return;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const collect = (type, payload) => {
|
||||
|
|
@ -211,36 +218,36 @@
|
|||
};
|
||||
|
||||
/* Global */
|
||||
getClientIPAddress();
|
||||
getClientIPAddress().then(() => {
|
||||
if (!window.umami) {
|
||||
const umami = eventValue => trackEvent(eventValue);
|
||||
umami.trackView = trackView;
|
||||
umami.trackEvent = trackEvent;
|
||||
|
||||
if (!window.umami) {
|
||||
const umami = eventValue => trackEvent(eventValue);
|
||||
umami.trackView = trackView;
|
||||
umami.trackEvent = trackEvent;
|
||||
window.umami = umami;
|
||||
window.lemonsquare = umami;
|
||||
}
|
||||
|
||||
window.umami = umami;
|
||||
window.lemonsquare = umami;
|
||||
}
|
||||
/* Start */
|
||||
|
||||
/* Start */
|
||||
if (autoTrack && !trackingDisabled()) {
|
||||
history.pushState = hook(history, 'pushState', handlePush);
|
||||
history.replaceState = hook(history, 'replaceState', handlePush);
|
||||
|
||||
if (autoTrack && !trackingDisabled()) {
|
||||
history.pushState = hook(history, 'pushState', handlePush);
|
||||
history.replaceState = hook(history, 'replaceState', handlePush);
|
||||
const update = () => {
|
||||
if (document.readyState === 'complete') {
|
||||
trackView();
|
||||
|
||||
const update = () => {
|
||||
if (document.readyState === 'complete') {
|
||||
trackView();
|
||||
|
||||
if (cssEvents) {
|
||||
addEvents(document);
|
||||
observeDocument();
|
||||
if (cssEvents) {
|
||||
addEvents(document);
|
||||
observeDocument();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
document.addEventListener('readystatechange', update, true);
|
||||
document.addEventListener('readystatechange', update, true);
|
||||
|
||||
update();
|
||||
}
|
||||
update();
|
||||
}
|
||||
});
|
||||
})(window);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue