forked from snowplow/snowplow-javascript-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrack_performance.html
More file actions
98 lines (89 loc) · 2.88 KB
/
Copy pathtrack_performance.html
File metadata and controls
98 lines (89 loc) · 2.88 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
<!DOCTYPE html>
<html>
<head>
<title>Track performance test page</title>
</head>
<body style="width: 2000px; height: 2000px; position: relative">
<p id="title">Page for sending requests to Snowplow Micro</p>
<div id="init"></div>
<script>
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', 'snowplow');
function testWithStorageStrategy(storageStrategy, synchronousCookieWrite) {
return new Promise((resolve) => {
window.snowplow('newTracker', `sp-${storageStrategy}`, 'http://localhost:9090', {
appId: 'sp-perf',
cookieName: `sp-perf-${storageStrategy}`,
stateStorageStrategy: storageStrategy,
synchronousCookieWrite: synchronousCookieWrite,
customFetch: function (request) {
return new Response(null, {
status: 200,
statusText: 'OK',
});
},
});
let eventsTracked = 0;
const countPlugin = {
CountPlugin: function () {
return {
afterTrack: () => {
eventsTracked++;
if (eventsTracked === 100) {
performance.mark('end');
resolve();
}
}
};
}
};
window.snowplow('addPlugin', countPlugin, 'CountPlugin');
window.snowplow(function () {
setTimeout(() => {
performance.mark('start');
for (var i = 0; i < 100; i++) {
window.snowplow(
'trackPageView',
{
title: `My Title ${i}`,
context: [
{
schema: 'iglu:org.schema/WebPage/jsonschema/1-0-0',
data: {
keywords: ['tester'],
},
},
],
}
);
}
}, 100);
});
});
}
const url = new URL(window.location.href);
const stateStorageStrategy = url.searchParams.get('stateStorageStrategy');
const synchronousCookieWrite = url.searchParams.get('synchronousCookieWrite') === 'true';
testWithStorageStrategy(stateStorageStrategy, synchronousCookieWrite).then(() => {
console.log('done ' + stateStorageStrategy);
document.getElementById('init').innerText = 'true';
});
</script>
</body>
</html>