(()=>{ 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 })) }) })()