summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2020-07-08 22:41:18 +0200
committerAki <please@ignore.pl>2020-07-08 22:41:18 +0200
commit81311c9a72058fedf0b9add696db170349478ebe (patch)
treeb7bdd49cd1ebc2bcfea6bb45eeb8ad50c908f35f
parent74a06dab4d6a4a05d7a4c0c384a826c0d2b1df92 (diff)
downloadrudone-81311c9a72058fedf0b9add696db170349478ebe.zip
rudone-81311c9a72058fedf0b9add696db170349478ebe.tar.gz
rudone-81311c9a72058fedf0b9add696db170349478ebe.tar.bz2
Changed to short circuit non-null just in case
-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
}))
})
})()