-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprocess_elements_cloud.js
221 lines (177 loc) · 9.26 KB
/
process_elements_cloud.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
export function processElementsCloud(event) {
// extract properties from elements
if (event.properties['$elements']) {
// process each element, last (outermost) first.
event.properties['$elements'].slice().forEach((element) => {
// el_data_testid_outer
if ('attr__data-testid' in element) {
event.properties['el_data_testid_outer'] = element['attr__data-testid']
// el_data_testid_outer_0
if (element['attr__data-testid'].includes('::')) {
arr = element['attr__data-testid'].split('::')
event.properties['el_data_testid_outer_0'] = arr[0]
event.properties['el_data_testid_outer_1'] = arr[1]
event.properties['el_data_testid_outer_2'] = arr[2]
event.properties['el_data_testid_outer_3'] = arr[3]
event.properties['el_data_testid_outer_4'] = arr[4]
}
}
// el_data_ga_outer
if ('attr__data-ga' in element) {
event.properties['el_data_ga_outer'] = element['attr__data-ga']
// el_data_ga_outer_0
if (element['attr__data-ga'].includes('::')) {
arr = element['attr__data-ga'].split('::')
event.properties['el_data_ga_outer_0'] = arr[0]
event.properties['el_data_ga_outer_1'] = arr[1]
event.properties['el_data_ga_outer_2'] = arr[2]
event.properties['el_data_ga_outer_3'] = arr[3]
event.properties['el_data_ga_outer_4'] = arr[4]
}
}
// el_data_track_outer
if ('attr__data-track' in element) {
event.properties['el_data_track_outer'] = element['attr__data-track']
// el_data_track_outer_0
if (element['attr__data-track'].includes('::')) {
arr = element['attr__data-track'].split('::')
event.properties['el_data_track_outer_0'] = arr[0]
event.properties['el_data_track_outer_1'] = arr[1]
event.properties['el_data_track_outer_2'] = arr[2]
event.properties['el_data_track_outer_3'] = arr[3]
event.properties['el_data_track_outer_4'] = arr[4]
}
}
})
// process each element, reverse to use posthog order as preference
event.properties['$elements'].slice().reverse().forEach((element) => {
// el_data_testid
if ('attr__data-testid' in element) {
event.properties['el_data_testid'] = element['attr__data-testid']
// el_data_testid_0
if (element['attr__data-testid'].includes('::')) {
arr = element['attr__data-testid'].split('::')
event.properties['el_data_testid_0'] = arr[0]
event.properties['el_data_testid_1'] = arr[1]
event.properties['el_data_testid_2'] = arr[2]
event.properties['el_data_testid_3'] = arr[3]
event.properties['el_data_testid_4'] = arr[4]
}
}
// el_data_ga
if ('attr__data-ga' in element) {
event.properties['el_data_ga'] = element['attr__data-ga']
// el_data_ga_0
if (element['attr__data-ga'].includes('::')) {
arr = element['attr__data-ga'].split('::')
event.properties['el_data_ga_0'] = arr[0]
event.properties['el_data_ga_1'] = arr[1]
event.properties['el_data_ga_2'] = arr[2]
event.properties['el_data_ga_3'] = arr[3]
event.properties['el_data_ga_4'] = arr[4]
// give nice names in posthog
event.properties['event_category'] = arr[0]
event.properties['event_action'] = arr[1]
event.properties['event_label'] = arr[2]
event.properties['event_value'] = arr[3]
}
}
// el_data_testid_inner
if ('attr__data-testid' in element) {
event.properties['el_data_testid_inner'] = element['attr__data-testid']
// el_data_testid_inner_0
if (element['attr__data-testid'].includes('::')) {
arr = element['attr__data-testid'].split('::')
event.properties['el_data_testid_inner_0'] = arr[0]
event.properties['el_data_testid_inner_1'] = arr[1]
event.properties['el_data_testid_inner_2'] = arr[2]
event.properties['el_data_testid_inner_3'] = arr[3]
event.properties['el_data_testid_inner_4'] = arr[4]
}
}
// el_data_ga_inner
if ('attr__data-ga' in element) {
event.properties['el_data_ga_inner'] = element['attr__data-ga']
// el_data_ga_inner_0
if (element['attr__data-ga'].includes('::')) {
arr = element['attr__data-ga'].split('::')
event.properties['el_data_ga_inner_0'] = arr[0]
event.properties['el_data_ga_inner_1'] = arr[1]
event.properties['el_data_ga_inner_2'] = arr[2]
event.properties['el_data_ga_inner_3'] = arr[3]
event.properties['el_data_ga_inner_4'] = arr[4]
}
}
// el_data_track_inner
if ('attr__data-track' in element) {
event.properties['el_data_track_inner'] = element['attr__data-track']
// el_data_track_inner_0
if (element['attr__data-track'].includes('::')) {
arr = element['attr__data-track'].split('::')
event.properties['el_data_track_inner_0'] = arr[0]
event.properties['el_data_track_inner_1'] = arr[1]
event.properties['el_data_track_inner_2'] = arr[2]
event.properties['el_data_track_inner_3'] = arr[3]
event.properties['el_data_track_inner_4'] = arr[4]
}
}
// el_href
if ('attr__href' in element && element['attr__href'] !== null) {
event.properties['el_href'] = element['attr__href']
} else if ('href' in element && element['href'] !== null) {
event.properties['el_href'] = element['href']
} else if ('$href' in element && element['$href'] !== null) {
event.properties['el_href'] = element['$href']
}
// el_onclick
if ('attr__onclick' in element && element['attr__onclick'] !== null) {
event.properties['el_onclick'] = element['attr__onclick']
}
// el_id
if ('attr__id' in element && element['attr__id'] !== null) {
event.properties['el_id'] = element['attr__id']
}
// el_name
if ('attr__name' in element && element['attr__name'] !== null) {
event.properties['el_name'] = element['attr__name']
}
// el_title
if ('attr__title' in element && element['attr__title'] !== null) {
event.properties['el_title'] = element['attr__title']
}
// el_text
if ('$el_text' in element && element['$el_text'] !== null && element['$el_text'] !== '') {
event.properties['el_text'] = element['$el_text']
} else if ('text' in element && element['text'] !== null && element['text'] !== '') {
event.properties['el_text'] = element['text']
}
// el_data_menuid
if ('attr__data-menuid' in element && element['attr__data-menuid'] !== null) {
event.properties['el_data_menuid'] = element['attr__data-menuid']
}
// el_data_submenuid
if ('attr__data-submenuid' in element && element['attr__data-submenuid'] !== null) {
event.properties['el_data_submenuid'] = element['attr__data-submenuid']
}
// el_data_chartid
if ('attr__data-chartid' in element && element['attr__data-chartid'] !== null) {
event.properties['el_data_chartid'] = element['attr__data-chartid']
}
// el_id_menu
if ('attr__id' in element && element['attr__id'] !== null && element['attr__id'].substring(0,5) === 'menu_') {
event.properties['el_id_menu'] = element['attr__id']
event.properties['el_menu'] = element['attr__id'].split('_submenu')[0].replace('menu_', '')
if (element['attr__id'].includes('_submenu_')) {
event.properties['el_submenu'] = element['attr__id'].split('_submenu_')[1]
} else {
event.properties['el_submenu'] = ''
}
}
// el_class
if ('attr__class' in element && element['attr__class'] !== null) {
event.properties['el_class'] = element['attr__class']
}
})
}
return event
}