-
Notifications
You must be signed in to change notification settings - Fork 0
/
wi-events.js
75 lines (57 loc) · 1.83 KB
/
wi-events.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
function wie(userParams) {
var el = this,
params = {
debug: false,
ga: false,
gtm: false,
ym: null
}
if (userParams) {
for (key in userParams) {
params[key] = userParams[key];
}
}
// Send Event
el.send = function (eventName) {
if (eventName) {
// Google Analytics Event
if (params.ga) {
if (typeof (ga) != 'undefined') {
ga('send', 'event', '', eventName);
if (params.debug) {
console.log('Google Analytics: ' + eventName);
}
} else {
console.log('ga is undefined');
}
}
// Google Analytics Event through GTM
if (params.gtm) {
if (typeof (dataLayer) != 'undefined') {
dataLayer.push({
event: 'jsEvent',
eventAction: eventName,
});
if (params.debug) {
console.log('Google Analytics through GTM: ' + eventName);
}
} else {
console.log('dataLayer is undefined');
}
}
// Yandex Metrika Event
if (params.ym) {
if (typeof (ym) != 'undefined') {
ym(params.ym, 'reachGoal', eventName);
if (params.debug) {
console.log('Yandex Metrika (' + params.ym + '): ' + eventName);
}
} else {
console.log('ym is undefined');
}
}
} else {
console.log('Event name should not be empty')
}
}
}