-
Notifications
You must be signed in to change notification settings - Fork 1
/
process_elements_agent.js
416 lines (333 loc) · 18.8 KB
/
process_elements_agent.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
import {isStringDDMMYYYYHHMM} from "./utils";
export function processElementsAgent(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]
}
}
// 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_id_menu
if ('attr__href' in element && element['attr__href'] !== null && element['attr__href'].substring(0,5) === '#menu') {
event.properties['el_href_menu'] = element['attr__href']
event.properties['el_menu'] = element['attr__href'].split('_submenu')[0].replace('#menu_', '')
if (element['attr__href'].includes('_submenu_')) {
event.properties['el_submenu'] = element['attr__href'].split('_submenu_')[1]
} else {
event.properties['el_submenu'] = ''
}
}
// 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']
// el_text_datetime
if (element['$el_text'].includes('/20') && isStringDDMMYYYYHHMM(element['$el_text'])) {
dtStr = element['$el_text']
dtStrClean = dtStr.substring(6,10).concat(
'-',dtStr.substring(3,5),'-',dtStr.substring(0,2),' ',dtStr.substring(11,16)
)
event.properties['el_text_datetime'] = dtStrClean
}
} else if ('text' in element && element['text'] !== null && element['text'] !== '') {
event.properties['el_text'] = element['text']
}
// el_data_netdata
if ('attr__data-netdata' in element && element['attr__data-netdata'] !== null) {
event.properties['el_data_netdata'] = element['attr__data-netdata']
}
// el_data_target
if ('attr__data-target' in element && element['attr__data-target'] !== null && element['attr__data-target'] !== '#sidebar') {
event.properties['el_data_target'] = element['attr__data-target']
// el_data_target_updatemodal
if ('attr__data-target' in element && element['attr__data-target'] !== null && element['attr__data-target'] === '#updateModal') {
event.properties['el_data_target_updatemodal'] = true
}
}
// el_data_id
if ('attr__data-id' in element && element['attr__data-id'] !== null) {
event.properties['el_data_id'] = element['attr__data-id']
}
// el_data_original_title
if ('attr__data-original-title' in element && element['attr__data-original-title'] !== null) {
event.properties['el_data_original_title'] = element['attr__data-original-title']
}
// el_data_toggle
if ('attr__data-toggle' in element && element['attr__data-toggle'] !== null) {
event.properties['el_data_toggle'] = element['attr__data-toggle']
}
// el_data-legend-position
if ('attr__data-legend-position' in element && element['attr__data-legend-position'] !== null) {
event.properties['el_data_legend_position'] = element['attr__data-legend-position']
}
// el_aria_controls
if ('attr__aria-controls' in element && element['attr__aria-controls'] !== null) {
event.properties['el_aria_controls'] = element['attr__aria-controls']
}
// el_aria_labelledby
if ('attr__aria-labelledby' in element && element['attr__aria-labelledby'] !== null) {
event.properties['el_aria_labelledby'] = element['attr__aria-labelledby']
}
// el_class_netdata_legend_toolbox
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'] === 'netdata-legend-toolbox') {
event.properties['el_class_netdata_legend_toolbox'] = true
}
// el_class_fa_play
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('fa-play')) {
event.properties['el_class_fa_play'] = true
}
// el_class_fa_backward
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('fa-backward')) {
event.properties['el_class_fa_backward'] = true
}
// el_class_fa_forward
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('fa-forward')) {
event.properties['el_class_fa_forward'] = true
}
// el_class_fa_plus
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('fa-plus')) {
event.properties['el_class_fa_plus'] = true
}
// el_class_fa_minus
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('fa-minus')) {
event.properties['el_class_fa_minus'] = true
}
// el_class_fa_sort
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('fa-sort')) {
event.properties['el_class_fa_sort'] = true
}
// el_class_navbar_highlight_content
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('navbar-highlight-content')) {
event.properties['el_class_navbar_highlight_content'] = true
}
// el_class_datepickercontainer
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('DatePickerContainer')) {
event.properties['el_class_datepickercontainer'] = true
}
// el_class_startendcontainer
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('StartEndContainer')) {
event.properties['el_class_startendcontainer'] = true
}
// el_class_pickerbtnarea
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('PickerBtnArea')) {
event.properties['el_class_pickerbtnarea'] = true
}
// el_class_pickerbox
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('PickerBox')) {
event.properties['el_class_pickerbox'] = true
}
// el_class_collapsablesection
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('CollapsableSection')) {
event.properties['el_class_collapsablesection'] = true
}
// el_class_signinbutton
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('SignInButton')) {
event.properties['el_class_signinbutton'] = true
}
// el_class_documentation_container
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('documentation__Container')) {
event.properties['el_class_documentation_container'] = true
}
// el_class_utilitysection
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('UtilitySection')) {
event.properties['el_class_utilitysection'] = true
}
// el_class_success
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('success')) {
event.properties['el_class_success'] = true
}
// el_class_warning
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('warning')) {
event.properties['el_class_warning'] = true
}
// el_class_danger
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('danger')) {
event.properties['el_class_danger'] = true
}
// el_class_info
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'] === 'info') {
event.properties['el_class_info'] = true
}
// el_class_pagination
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('pagination')) {
event.properties['el_class_pagination'] = true
}
// el_class_page_number
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('page-number')) {
event.properties['el_class_page_number'] = true
}
// el_class_export
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('export')) {
event.properties['el_class_export'] = true
}
// el_class_netdata_chartblock_container
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('netdata-chartblock-container')) {
event.properties['el_class_netdata_chartblock_container'] = true
}
// el_class_netdata_reset_button
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('netdata-reset-button')) {
event.properties['el_class_netdata_reset_button'] = true
}
// el_class_netdata_legend_toolbox_button
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('netdata-legend-toolbox-button')) {
event.properties['el_class_netdata_legend_toolbox_button'] = true
}
// el_class_netdata_legend_resize_handler
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('netdata-legend-resize-handler')) {
event.properties['el_class_netdata_legend_resize_handler'] = true
}
// el_class_calendarday
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('CalendarDay')) {
event.properties['el_class_calendarday'] = true
}
// el_class_daypicker
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('DayPicker')) {
event.properties['el_class_daypicker'] = true
}
// el_class_daterangepicker
if ('attr__class' in element && element['attr__class'] !== null && element['attr__class'].includes('DateRangePicker')) {
event.properties['el_class_daterangepicker'] = true
}
// el_id_date_picker_root
if ('attr__id' in element && element['attr__id'] !== null && element['attr__id'].includes('date-picker-root')) {
event.properties['el_id_date_picker_root'] = true
}
// el_id_updatemodal
if ('attr__id' in element && element['attr__id'] !== null && element['attr__id'].includes('updateModal')) {
event.properties['el_id_updatemodal'] = true
}
// el_class
if ('attr__class' in element && element['attr__class'] !== null) {
event.properties['el_class'] = element['attr__class']
}
})
}
return event
}