@alexsab-ru/scripts 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/analytics.js +31 -19
- package/package.json +1 -1
package/lib/analytics.js
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
window.dataLayer = window.dataLayer || [];
|
|
2
2
|
|
|
3
|
-
export function
|
|
4
|
-
|
|
3
|
+
export function reachGoal(eventAction, t = {}) {
|
|
4
|
+
t.eventAction = eventAction;
|
|
5
|
+
dl("reachGoal-"+eventAction, {
|
|
6
|
+
...t
|
|
7
|
+
})
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function pageView(eventAction, t = {}) {
|
|
11
|
+
t.eventAction = eventAction;
|
|
12
|
+
dl("pageView-"+eventAction, {
|
|
13
|
+
...t
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function dl(event, t = {}) {
|
|
18
|
+
console.log(event, t);
|
|
5
19
|
void 0 !== window.dataLayer && window.dataLayer.push({
|
|
6
20
|
event: event,
|
|
7
21
|
...t
|
|
@@ -9,10 +23,10 @@ export function dataLayer(event, t = {}) {
|
|
|
9
23
|
}
|
|
10
24
|
|
|
11
25
|
export function getFormDataObject(formData, form_id) {
|
|
12
|
-
let obj = {"
|
|
13
|
-
formData.forEach((value, key) => (obj["
|
|
14
|
-
obj['
|
|
15
|
-
obj["
|
|
26
|
+
let obj = {"eventProperties":{}};
|
|
27
|
+
formData.forEach((value, key) => (obj["eventProperties"][key] = value));
|
|
28
|
+
obj['eventCategory'] = 'Lead';
|
|
29
|
+
obj["eventProperties"]['formID'] = form_id;
|
|
16
30
|
obj['sourceName'] = 'page';
|
|
17
31
|
return obj;
|
|
18
32
|
}
|
|
@@ -39,25 +53,25 @@ export function ymPage(pageName,goalParams) {
|
|
|
39
53
|
|
|
40
54
|
export function addPhoneGoals(item) {
|
|
41
55
|
item.addEventListener('click', function(evt) {
|
|
42
|
-
|
|
56
|
+
reachGoal('phone_click');
|
|
43
57
|
});
|
|
44
58
|
item.addEventListener('copy', function(evt) {
|
|
45
|
-
|
|
59
|
+
reachGoal('phone_copy');
|
|
46
60
|
});
|
|
47
61
|
item.addEventListener('contextmenu', function(evt) {
|
|
48
|
-
|
|
62
|
+
reachGoal('phone_contextmenu');
|
|
49
63
|
});
|
|
50
64
|
}
|
|
51
65
|
|
|
52
66
|
export function addEmailGoals(item) {
|
|
53
67
|
item.addEventListener('click', function(evt) {
|
|
54
|
-
|
|
68
|
+
reachGoal('email_click');
|
|
55
69
|
});
|
|
56
70
|
item.addEventListener('copy', function(evt) {
|
|
57
|
-
|
|
71
|
+
reachGoal('email_copy');
|
|
58
72
|
});
|
|
59
73
|
item.addEventListener('contextmenu', function(evt) {
|
|
60
|
-
|
|
74
|
+
reachGoal('email_contextmenu');
|
|
61
75
|
});
|
|
62
76
|
}
|
|
63
77
|
|
|
@@ -87,25 +101,23 @@ export function addEmailGoals(item) {
|
|
|
87
101
|
goals.forEach(function(value, index, array){
|
|
88
102
|
if(value.goal != null) {
|
|
89
103
|
document.querySelectorAll(value.selector).forEach(function(element) {
|
|
90
|
-
console.log(
|
|
104
|
+
console.log("Set \"" + value.goal + "\" goal", element);
|
|
91
105
|
element.addEventListener(value.action, function(){
|
|
92
|
-
|
|
93
|
-
eventAction: value.goal,
|
|
106
|
+
reachGoal(value.goal, {
|
|
94
107
|
title: value.title,
|
|
95
108
|
});
|
|
96
109
|
});
|
|
97
110
|
});
|
|
98
111
|
} else if(value.hit != null) {
|
|
99
112
|
document.querySelectorAll(value.selector).forEach(function(element) {
|
|
100
|
-
console.log(
|
|
113
|
+
console.log("Set \"" + value.goal + "\" hit", element);
|
|
101
114
|
element.addEventListener(value.action, function(){
|
|
102
|
-
|
|
103
|
-
eventAction: value.hit,
|
|
115
|
+
pageView(value.hit, {
|
|
104
116
|
title: value.title,
|
|
105
117
|
});
|
|
106
118
|
});
|
|
107
119
|
});
|
|
108
120
|
} else {
|
|
109
|
-
console.warn(
|
|
121
|
+
console.warn("Ошибка в списке целей", value);
|
|
110
122
|
}
|
|
111
123
|
});
|