-
-
Notifications
You must be signed in to change notification settings - Fork 317
/
Copy pathanalytics.js
53 lines (46 loc) · 1.36 KB
/
analytics.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { log } from './utils';
/* global ga */
// eslint-disable-next-line max-params
export function trackEvent(category, action, label, value) {
if (window.DEBUG) {
log('trackevent', category, action, label, value);
return;
}
if (window.ga) {
ga('send', 'event', category, action, label, value);
fetch('https://event-ajhkrtmkaq-uc.a.run.app', {
method: 'post',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ category, action, label, value })
});
}
}
// if online, load after sometime
if (navigator.onLine && !window.DEBUG) {
/* eslint-disable */
// prettier-ignore
setTimeout(function () {
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
if (location.href.indexOf('chrome-extension://') === -1) {
ga('create', 'UA-87786708-2');
} else {
ga('create', 'UA-87786708-2', {
'cookieDomain': 'none'
});
// required for chrome extension protocol
ga('set', 'checkProtocolTask', function () { /* nothing */ });
}
ga('send', 'pageview');
}, 100);
/* eslint-enable */
}