@snowplow/javascript-tracker
Version:
Web analytics for Snowplow
73 lines (63 loc) • 2.28 kB
HTML
<html>
<head>
<title>Cookieless test page</title>
</head>
<body>
<p id="title">Page for testing anonymous tracking with Snowplow Micro</p>
<script>
var collector_endpoint = document.cookie.split('container=')[1].split(';')[0];
document.body.className += ' loaded';
</script>
<script>
function parseQuery() {
var query = {};
var pairs = window.location.search.substring(1).split('&');
for (var i = 0; i < pairs.length; i++) {
var pair = pairs[i].split('=');
query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || '');
}
return query;
}
</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');
document.write(collector_endpoint);
var ieTest = parseQuery().ieTest;
window.snowplow('newTracker', 'sp', collector_endpoint, {
appId: ieTest ? 'ie' : 'anon',
eventMethod: 'post',
contexts: {
webPage: true,
},
anonymousTracking: { withServerAnonymisation: true },
});
window.snowplow('setUserId', 'Malcolm');
window.snowplow('trackPageView', { title: 'Server Anon' });
window.snowplow('trackPageView', { title: 'Server Anon' }); // Should have different network_userid
if (!ieTest) {
setTimeout(function () {
window.snowplow('disableAnonymousTracking', { stateStorageStrategy: 'cookieAndLocalStorage' });
window.snowplow('setUserId', 'Malcolm');
window.snowplow('trackPageView', { title: 'No Anon' });
window.snowplow('enableAnonymousTracking');
window.snowplow('trackPageView', { title: 'Client Anon' });
}, 2000);
}
</script>
</body>
</html>