Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

Updated initialization process.

Mike Cao291c64f7b0b5
diff --git a/src/tracker/index.js b/src/tracker/index.js
index 90a73c432..707594cf4 100644
--- a/src/tracker/index.js
+++ b/src/tracker/index.js
@@ -222,6 +222,16 @@
}
};
+ const init = () => {
+ if (!initialized) {
+ track();
+ handlePathChanges();
+ handleTitleChanges();
+ handleClicks();
+ initialized = true;
+ }
+ };
+
const track = (obj, data) => {
if (typeof obj === 'string') {
return send({
@@ -255,19 +265,10 @@
let initialized;
if (autoTrack && !trackingDisabled()) {
- handlePathChanges();
- handleTitleChanges();
- handleClicks();
-
- const init = () => {
- if (document.readyState === 'complete' && !initialized) {
- track();
- initialized = true;
- }
- };
-
- document.addEventListener('readystatechange', init, true);
-
- init();
+ if (document.readyState === 'complete') {
+ init();
+ } else {
+ document.addEventListener('readystatechange', init, true);
+ }
}
})(window);