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
77 lines (66 loc) · 2.26 KB
/
Copy pathactivity-callback.html
File metadata and controls
77 lines (66 loc) · 2.26 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
<!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="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>
;(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","snowplow"));
snowplow('newTracker', 'cf', 'snowplow-js-tracker.local:9090');
snowplow(function() {
document.getElementById('init').innerText = 'true';
});
var events = [];
snowplow('enableActivityTrackingCallback', 2, 2, 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() {
snowplow('trackPageView');
}
function getCurrentPageViewId(cb) {
snowplow(function() {
cb(this.cf.getPageViewId())
});
}
snowplow('trackPageView')
</script>
</html>