-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprocess_elements_website.js
104 lines (82 loc) · 4.01 KB
/
process_elements_website.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
export function processElementsWebsite(event) {
// extract properties from elements
if (event.properties['$elements']) {
// 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_track
if ('attr__data-track' in element) {
event.properties['el_data_track'] = element['attr__data-track']
// el_data_track_0
if (element['attr__data-track'].includes('::')) {
arr = element['attr__data-track'].split('::')
event.properties['el_data_track_0'] = arr[0]
event.properties['el_data_track_1'] = arr[1]
event.properties['el_data_track_2'] = arr[2]
event.properties['el_data_track_3'] = arr[3]
event.properties['el_data_track_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_class
if ('attr__class' in element && element['attr__class'] !== null) {
event.properties['el_class'] = element['attr__class']
}
})
}
return event
}