-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalytics.js
More file actions
22 lines (22 loc) · 873 Bytes
/
analytics.js
File metadata and controls
22 lines (22 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
(function () {
try {
var url = 'https://hc-refactored.fly.dev/api/analytics/pageview';
var qs = new URLSearchParams(location.search);
var payload = JSON.stringify({
site: 'boardgaminghub.com',
path: location.pathname,
referrer: document.referrer,
screen: screen.width + 'x' + screen.height,
utm_source: qs.get('utm_source') || '',
utm_medium: qs.get('utm_medium') || '',
utm_campaign: qs.get('utm_campaign') || '',
utm_term: qs.get('utm_term') || '',
utm_content: qs.get('utm_content') || ''
});
if (navigator.sendBeacon) {
navigator.sendBeacon(url, new Blob([payload], { type: 'application/json' }));
} else {
fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: payload, keepalive: true });
}
} catch (e) { /* never break the page */ }
})();