blob: 0a281e6539234faafdf0b2fe99b8941727c4fb2e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
(()=>{
let startedAt = null
let scrolledTo = null
window.addEventListener("load", ()=>{
startedAt = new Date()
scrolledTo = window.scrollY
if (window.innerHeight >= document.scrollingElement.scrollHeight) {
scrolledTo = document.scrollingElement.scrollHeight
}
})
window.addEventListener("scroll", ()=>{
scrolledTo = Math.max(scrolledTo, window.scrollY + window.innerHeight)
}, false)
window.addEventListener("beforeunload", ()=>{
navigator.sendBeacon("http://stats.ignore.pl/entries", JSON.stringify({
"location": document.location.href,
"referrer": document.referrer,
"startedAt": startedAt,
"timeSpent": Math.floor((new Date() - startedAt) / 1000),
"scrolledTo": (scrolledTo || 0) / document.scrollingElement.scrollHeight
}))
})
})()
|