-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtracker-google.js
35 lines (32 loc) · 939 Bytes
/
tracker-google.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
/**
* Tracking service.
*/
export default class TrackerGoogle {
dataLayerPush(data) {
/* eslint-disable */
window.dataLayer = window.dataLayer || [];
window.dataLayer.push(data);
/* eslint-enable */
}
// Helpful article: https://www.optimizesmart.com/event-tracking-guide-google-analytics-simplified-version/.
sendEvent(
eventCategory = '',
eventAction = '',
eventName = '',
eventValue = '',
eventNonInteraction = ''
) {
const ga = window[window['GoogleAnalyticsObject'] || 'ga'];
if ('function' !== typeof ga) {
return;
}
ga('send', {
'hitType': 'event',
'eventCategory': eventCategory,
'eventAction': eventAction,
'eventLabel': eventName,
'eventValue': eventValue,
'nonInteraction': eventNonInteraction,
});
}
}