-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
__ns__.js
89 lines (81 loc) · 2.82 KB
/
__ns__.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* Defines <code>komito.trackers.dom</code> namespace.
* @namespace
*/
komito.trackers.dom = {
init: function() {
komito.trackers.dom.Forms && new komito.trackers.dom.Forms;
komito.trackers.dom.Links && new komito.trackers.dom.Links;
komito.trackers.dom.Print && new komito.trackers.dom.Print;
komito.trackers.dom.Scroll && new komito.trackers.dom.Scroll;
komito.trackers.dom.Orientation && new komito.trackers.dom.Orientation;
komito.trackers.dom.AdBlock && new komito.trackers.dom.AdBlock;
komito.trackers.dom.trackHeartBeat_(+komito.config['sendHeartbeat']);
komito.trackers.dom.trackErrorPages_();
komito.trackers.dom.trackColorScheme_();
komito.trackers.dom.trackRuntimeErrors_();
},
/**
* Tracks heartbeat event.
* @param {number} interval The heartbeat interval in seconds.
* @see https://www.w3.org/TR/page-visibility/
* @private
*/
trackHeartBeat_: function(interval) {
if (interval) {
/** @type {number} */ var timer;
interval = Math.max(interval, 30);
dom.events.addEventListener(dom.document, 'visibilitychange', function() {
if ('visible' === dom.document['visibilityState']) {
timer = setInterval(function() {
komito.track(komito.EVENT_ACTION_TYPE, 'heartbeat', interval + 's');
}, 1E3 * interval);
} else {
timer && clearInterval(timer);
}
});
}
},
/**
* Tracks error pages.
* @private
*/
trackErrorPages_: function() {
var page = komito.config['trackErrorPages'] && location.href;
if (page) {
komito.markAsNonInteractionEvent('errors');
(new net.HttpRequest).doHead(/** @type {string} */(page), function(req) {
if (399 < req.status) {
komito.track(komito.EVENT_ACTION_TYPE, 'errors', req.status, page);
}
});
}
},
/**
* Tracks javascript runtime errors.
* @see https://developer.mozilla.org/en-US/docs/Web/API/ErrorEvent
* @private
*/
trackRuntimeErrors_: function() {
if (komito.config['trackErrors']) {
komito.markAsNonInteractionEvent('errors');
dom.events.addEventListener(dom.context, 'error', function(e) {
komito.track(komito.EVENT_ACTION_TYPE, 'errors', e.message, e.filename);
});
}
},
/**
* Tracks user preferred color scheme.
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme
* @private
*/
trackColorScheme_: function() {
if (komito.config['trackColorScheme'] && dom.context.matchMedia) {
// https://github.com/Datamart/Komito/issues/38
komito.markAsNonInteractionEvent('color-scheme');
var query = '(prefers-color-scheme: dark)';
var scheme = dom.context.matchMedia(query).matches ? 'dark' : 'light';
komito.track(komito.EVENT_ACTION_TYPE, 'color-scheme', scheme);
}
}
};