forked from snowplow/snowplow-javascript-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactivity-callback.html
More file actions
101 lines (88 loc) · 2.79 KB
/
Copy pathactivity-callback.html
File metadata and controls
101 lines (88 loc) · 2.79 KB
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
<!DOCTYPE html>
<html>
<head>
<title>Acitvity calllback test page</title>
</head>
<body style="width: 2000px; height: 2000px; position: relative">
<div id="init"></div>
<div id="currentPageViewId"></div>
<div id="numEvents"></div>
<div id="middle" style="position: absolute; top: 50%; left: 50%">Middle</div>
<div id="bottomRight" style="position: absolute; bottom: 0; right: 0">Bottom right</div>
<script>
var collector_endpoint = document.cookie.split('container=')[1].split(';')[0];
document.body.className += ' loaded';
</script>
<script>
(function (p, l, o, w, i, n, g) {
if (!p[i]) {
p.GlobalSnowplowNamespace = p.GlobalSnowplowNamespace || [];
p.GlobalSnowplowNamespace.push(i);
p[i] = function () {
(p[i].q = p[i].q || []).push(arguments);
};
p[i].q = p[i].q || [];
n = l.createElement(o);
g = l.getElementsByTagName(o)[0];
n.async = 1;
n.src = w;
g.parentNode.insertBefore(n, g);
}
})(window, document, 'script', './snowplow.js', 'spActivity');
document.write(collector_endpoint);
spActivity('newTracker', 'sp', collector_endpoint);
spActivity(function () {
document.getElementById('init').innerText = 'true';
});
var events = [];
spActivity('enableActivityTrackingCallback', {
minimumVisitLength: 2,
heartbeatDelay: 2,
callback: function (e) {
events.push(e);
document.getElementById('numEvents').innerText = events.length;
},
});
function createMaxFinder(key) {
return function () {
var i = 0;
var max = 0;
for (; i < events.length; i++) {
if (events[i][key] > max) {
max = events[i][key];
}
}
return max;
};
}
var findMaxY = createMaxFinder('maxYOffset');
var findMaxX = createMaxFinder('maxXOffset');
function findFirstEventForPageViewId(id) {
for (var i = 0; i < events.length; i++) {
if (events[i].pageViewId === id) {
return events[i];
}
}
return null;
}
function findLastEventForPageViewId(id) {
var found = null;
for (var i = 0; i < events.length; i++) {
if (events[i].pageViewId === id) {
found = events[i];
}
}
return found;
}
function trackPageView() {
spActivity('trackPageView');
}
function getCurrentPageViewId() {
spActivity(function () {
document.getElementById('currentPageViewId').innerText = this.sp.getPageViewId();
});
}
spActivity('trackPageView');
</script>
</body>
</html>