-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathanalytics.js
More file actions
47 lines (45 loc) · 1.31 KB
/
analytics.js
File metadata and controls
47 lines (45 loc) · 1.31 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
// This setting doesn't do anything, nor does the detection work.
settings.register({
name: 'Send anonymous statistics',
key: 'underscript.analytics',
default: window.GoogleAnalyticsObject !== undefined,
enabled: window.GoogleAnalyticsObject !== undefined,
hidden: true,
note: () => {
if (window.GoogleAnalyticsObject === undefined) {
return 'Analytics has been disabled by your adblocker.';
}
},
});
const analytics = wrap(() => {
const config = {
'app_name': 'underscript',
'app_version': scriptVersion,
'version': scriptVersion,
'handler': GM_info.scriptHandler,
'anonymize_ip': true, // I don't care about IP addresses, don't track this
'custom_map': {
'dimension1': 'version',
},
};
if (sessionStorage.getItem('UserID')) {
// This gives me a truer user count, by joining all hits from the same user together
config['user_id'] = sessionStorage.getItem('UserID');
}
window.dataLayer = window.dataLayer || [];
gtag('js', new Date());
gtag('config', 'UA-38424623-4', config);
function gtag() {
dataLayer.push(arguments);
}
function send(...args) {
if (!args.length) return;
gtag('event', ...args);
}
function error(description, fatal = false) {
send('exception', {description, fatal})
}
return {
send, error,
};
});