-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathcustom-analytics.js
30 lines (28 loc) · 987 Bytes
/
custom-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
var CustomAnalytics = CustomAnalytics || {};
CustomAnalytics.collector = {
collect: (context) => {
if(!context || !context.eventAction || !context.eventName || !context.message) return;
try {
ga('send', 'event', context.eventName, context.eventAction, context.message);
} catch(e) {
//ignore silently
}
},
collectError: (context, err) => {
context.errorContext = (Page || { request: {}}).request || {};
context.errorContext.url = window.location.href;
context.errorContext.userAgent = navigator.userAgent;
try {
context.eventName = `${err}`;
} catch(e) {
context.eventName = `Unknown Error`;
}
CustomAnalytics.collector.collect(
{
eventName: context.eventName,
eventAction: context.eventAction,
message: `${JSON.stringify(context.errorContext)}`
}
);
}
};