summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--track.js3
1 files changed, 2 insertions, 1 deletions
diff --git a/track.js b/track.js
index cb8ab72..9447b78 100644
--- a/track.js
+++ b/track.js
@@ -13,6 +13,7 @@
}, false)
window.addEventListener("beforeunload", ()=>{
let xhr = new XMLHttpRequest()
+ startedAt = startedAt || new Date()
xhr.open("POST", "https://stats.ignore.pl/entry")
xhr.setRequestHeader("Content-Type", "application/json")
xhr.send(JSON.stringify({
@@ -20,7 +21,7 @@
"referrer": document.referrer,
"startedAt": startedAt,
"timeSpent": Math.floor((new Date() - startedAt) / 1000),
- "scrolledTo": scrolledTo / document.scrollingElement.scrollHeight
+ "scrolledTo": (scrolledTo || 0) / document.scrollingElement.scrollHeight
}))
})
})()