/
script.js
36 lines (35 loc) · 1.12 KB
/
script.js
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
28
29
30
31
32
33
34
35
36
(function () {
if (sessionStorage.getItem('doNotTrack') || localStorage.getItem('doNotTrack')){
return
}
var id = document.currentScript.getAttribute("data-id");
var utcoffset = document.currentScript.getAttribute("data-utcoffset");
var server =
document.currentScript.getAttribute("data-server") ||
"https://t.counter.dev";
if (
!sessionStorage.getItem("_swa") &&
!document.referrer.startsWith(location.protocol + "//" + location.host)
) {
setTimeout(function () {
sessionStorage.setItem("_swa", "1");
fetch(
server +
"/track?" +
new URLSearchParams({
referrer: document.referrer,
screen: screen.width + "x" + screen.height,
id: id,
utcoffset: utcoffset,
})
);
}, 4500);
}
navigator.sendBeacon(
server + "/trackpage",
new URLSearchParams({
id: id,
page: window.location.pathname,
})
);
})();