blob: 5b0e5443e071857a4d0a6010e74fcd927824141b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
(()=>{
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", ()=>{
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({
"location": document.location.href,
"referrer": document.referrer,
"startedAt": startedAt,
"timeSpent": Math.floor((new Date() - startedAt) / 1000),
"scrolledTo": (scrolledTo || 0) / document.scrollingElement.scrollHeight
}))
})
})()
|