forked from DataDog/snowplow-javascript-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration.html
More file actions
159 lines (130 loc) · 4.4 KB
/
Copy pathintegration.html
File metadata and controls
159 lines (130 loc) · 4.4 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE html>
<html>
<head>
<title>Integration test page</title>
</head>
<body>
<p id="title">Page for sending requests to request_recorder</p>
<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","snowplow"));
document.write(collector_endpoint)
window.snowplow('newTracker', 'cf', collector_endpoint, {
encodeBase64: true,
appId: 'CFe23a',
platform: 'mob',
eventMethod: 'get',
contexts: {
webPage: true
}
});
// Add a global context
var geolocationContext = {
schema: 'iglu:com.snowplowanalytics.snowplow/geolocation_context/jsonschema/1-1-0',
data: {
'latitude': 40.0,
'longitude' : 55.1
}
};
function eventTypeContextGenerator(args) {
var context = {};
context['schema'] = 'iglu:com.snowplowanalytics.snowplow/mobile_context/jsonschema/1-0-1';
context['data'] = {};
context['data']['osType'] = 'ubuntu';
context['data']['osVersion'] = '2018.04';
context['data']['deviceManufacturer'] = 'ASUS';
context['data']['deviceModel'] = String(args['eventType']);
return context;
}
// A filter that will only attach contexts to structured events
function structuredEventFilter(args) {
return args['eventType'] === 'se';
}
function erroneousContextGenerator(args) {
return {};
}
window.snowplow('enableGdprContext', 'consent', 'someId', '0.1.0', 'this document is a test');
window.snowplow('addGlobalContexts', [erroneousContextGenerator]);
window.snowplow('addGlobalContexts', [[structuredEventFilter, [eventTypeContextGenerator, geolocationContext]]]);
window.snowplow('setUserId', 'Malcolm');
window.snowplow('trackPageView', 'My Title', [ // Auto-set page title; add page context
{
schema: "iglu:org.schema/WebPage/jsonschema/1-0-0",
data: {
keywords: ['tester']
}
}
]);
// This should have different pageViewId in web_page context
window.snowplow('trackPageView');
window.snowplow('trackStructEvent', 'Mixes', 'Play', 'MRC/fabric-0503-mix', '', '0.0');
window.snowplow('trackUnstructEvent', {
schema: 'iglu:com.snowplowanalytics.snowplow/ad_impression/jsonschema/1-0-0',
data: {
bannerId: 'ASO01043'
}
}, [], {type: 'ttm', value: 1477401868});
var orderId = 'order-123';
window.snowplow('addTrans',
orderId,
'acme',
'8000',
'100',
'50',
'phoenix',
'arizona',
'USA',
'JPY'
);
// addItem might be called for each item in the shopping cart,
// or not at all.
window.snowplow('addItem',
orderId,
'1001',
'Blue t-shirt',
'clothing',
'2000',
'2',
'JPY'
);
// trackTrans sends the transaction to Snowplow tracking servers.
// Must be called last to commit the transaction.
window.snowplow('trackTrans');
var testAcceptRuleSet = {
accept: ['iglu:com.snowplowanalytics.snowplow/*/jsonschema/*-*-*']
};
var testRejectRuleSet = {
reject: ['iglu:com.snowplowanalytics.snowplow/*/jsonschema/*-*-*']
};
// test context rulesets
window.snowplow('addGlobalContexts', [[testAcceptRuleSet, [eventTypeContextGenerator, geolocationContext]]]);
window.snowplow('trackUnstructEvent', {
schema: 'iglu:com.snowplowanalytics.snowplow/ad_impression/jsonschema/1-0-0',
data: {
bannerId: 'ASO01042'
}
}, [], {type: 'ttm', value: 1477401869});
window.snowplow('removeGlobalContexts', [[testAcceptRuleSet, [eventTypeContextGenerator, geolocationContext]]]);
window.snowplow('addGlobalContexts', [[testRejectRuleSet, [eventTypeContextGenerator, geolocationContext]]]);
window.snowplow('trackUnstructEvent', {
schema: 'iglu:com.snowplowanalytics.snowplow/ad_impression/jsonschema/1-0-0',
data: {
bannerId: 'ASO01041'
}
}, [], {type: 'ttm', value: 1477401868});
// track unhandled exception
window.snowplow("enableErrorTracking");
// Test for exception handling
function raiseException() {
notExistentObject.notExistentProperty();
}
setTimeout(raiseException, 2500);
</script>
</body>
</html>