-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathstats.js
More file actions
47 lines (40 loc) · 1.11 KB
/
stats.js
File metadata and controls
47 lines (40 loc) · 1.11 KB
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
37
38
39
40
41
42
43
44
45
46
47
(function() {
var PLAUSIBLE_API = 'https://stats.turbowarp.org/api/event';
var PLAUSIBLE_DOMAIN = 'forkphorus.github.io';
if (location.protocol !== 'http:' && location.protocol !== 'https:') {
return;
}
if (location.origin.indexOf(PLAUSIBLE_DOMAIN) === -1) {
return;
}
if (navigator.doNotTrack === '1') {
return;
}
var referrer = null;
if (document.referrer) {
try {
var url = new URL(document.referrer);
url.pathname = '';
referrer = url.href;
} catch (e) { /* ignore */ }
}
var sendEvent = function(eventName) {
(window.requestIdleCallback || window.setTimeout)(function() {
var req = new XMLHttpRequest();
req.open('POST', PLAUSIBLE_API, true);
req.setRequestHeader('Content-Type', 'text/plain');
req.send(JSON.stringify({
n: eventName,
u: location.href,
d: PLAUSIBLE_DOMAIN,
r: referrer,
w: window.innerWidth,
}));
});
};
var trackPageview = function() {
sendEvent('pageview');
};
window.addEventListener('hashchange', trackPageview);
trackPageview();
}());