-
Notifications
You must be signed in to change notification settings - Fork 3
/
preezie-ga4-tracking.html
117 lines (88 loc) · 3.51 KB
/
preezie-ga4-tracking.html
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
<script data-cfasync="false">
/*
Web Site Advantage: Preezie GA Tracking [v1.0]
Tracking of user activity with Preezie
https://bigcommerce.websiteadvantage.com.au/
Copyright (C) 2023 Web Site Advantage
*/
!function() {
var ga4Id = ''; // optional if you want to send it to a specific destination
var exitintent = false;
var popup = false;
var cta = false;
var workflow = false;
var result = false;
var gtagEvent = function (name, options) {
if (ga4Id) {
options = options || {};
options.send_to = ga4Id;
}
gtag('event', name, options);
// console.log('event', name, options);
}
var journeyClickHandler = function(node) {
var text = node.innerText;
node.addEventListener('click', function(event) {
gtagEvent('journey_click', {
'journey_click': text, // so always get the text in the node
});
}, false);
}
var resultClickHandler = function(node) {
node.addEventListener('click', function(event) {
gtagEvent('preezie_result_click', {
'journey_result': event.target.href,
});
}, false);
}
new MutationObserver(function(mutationsList, observer) {
mutationsList.forEach(function(mutation){
for (let i = 0; i < mutation.addedNodes.length; i++) {
var node = mutation.addedNodes[i];
if(node.nodeType === Node.ELEMENT_NODE) {
if(node.classList.toString().match(/exitintent_/)) {
if (!exitintent) {
exitintent = true;
gtagEvent('preezie_exitintent');
}
}
if(node.classList.toString().match(/popup_/)) {
if (!popup) {
popup = true;
gtagEvent('preezie_popup');
}
}
if(node.classList.toString().match(/cta_/)) {
if (!cta) {
cta = true;
gtagEvent('preezie_cta');
}
}
if(node.classList.toString().match(/workflow_/)) {
if (!workflow) {
workflow = true;
gtagEvent('preezie_workflow');
}
}
node.querySelectorAll("#preezienav [id^='preez-'], #preezieans [id^='preezans-']").forEach(function(innerNode){
journeyClickHandler(innerNode);
});
if (node.id == 'preezieres') {
console.log('preezieres', node);
}
var results = node.querySelectorAll("#preezieres a");
results.forEach(function(innerNode){
resultClickHandler(innerNode);
});
if (!result && results.length > 0) {
result = true;
gtagEvent('preezie_result', {
'count': results.length,
});
}
}
}
});
}).observe(document.body, { childList: true, subtree: true });
}()
</script>