This repository was archived by the owner on Apr 8, 2021. It is now read-only.
forked from snowplow/snowplow-javascript-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration.html
More file actions
313 lines (263 loc) · 9.64 KB
/
Copy pathintegration.html
File metadata and controls
313 lines (263 loc) · 9.64 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<!DOCTYPE html>
<html>
<head>
<title>Integration 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>
<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 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 eventMethod = parseQuery().eventMethod;
window.snowplow('newTracker', 'cf', collector_endpoint, {
appId: 'sp-' + eventMethod,
platform: 'mob',
eventMethod: eventMethod,
contexts: {
webPage: true
},
});
window.snowplow('newTracker', 'b64off', collector_endpoint, {
appId: 'no-b64-' + eventMethod,
platform: 'web',
eventMethod: eventMethod,
encodeBase64: false,
});
window.snowplow(function() {
document.getElementById('init').innerText = '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:cf', 'consent', 'someId', '0.1.0', 'this document is a test');
window.snowplow('addGlobalContexts:cf', [erroneousContextGenerator]);
window.snowplow('addGlobalContexts:cf', [[structuredEventFilter, [eventTypeContextGenerator, geolocationContext]]]);
window.snowplow('setUserId:cf', 'Malcolm');
window.snowplow('enableActivityTracking:cf', 1, 2);
// Also tracks to non-base64 encoding tracker
window.snowplow('trackPageView:cf;b64off', 'My Title', [ // 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:cf');
window.snowplow('trackStructEvent:cf', 'Mixes', 'Play', 'MRC/fabric-0503-mix', '', '0.0');
window.snowplow('trackUnstructEvent:cf', {
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:cf',
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:cf',
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:cf');
var testAcceptRuleSet = {
accept: ['iglu:com.snowplowanalytics.snowplow/*/jsonschema/*-*-*']
};
var testRejectRuleSet = {
reject: ['iglu:com.snowplowanalytics.snowplow/*/jsonschema/*-*-*']
};
// test context rulesets
window.snowplow('addGlobalContexts:cf', [[testAcceptRuleSet, [eventTypeContextGenerator, geolocationContext]]]);
window.snowplow('trackUnstructEvent:cf', {
schema: 'iglu:com.snowplowanalytics.snowplow/ad_impression/jsonschema/1-0-0',
data: {
bannerId: 'ASO01042'
}
}, [], {type: 'ttm', value: 1477401869});
window.snowplow('removeGlobalContexts:cf', [[testAcceptRuleSet, [eventTypeContextGenerator, geolocationContext]]]);
window.snowplow('addGlobalContexts:cf', [[testRejectRuleSet, [eventTypeContextGenerator, geolocationContext]]]);
window.snowplow('trackUnstructEvent:cf', {
schema: 'iglu:com.snowplowanalytics.snowplow/ad_impression/jsonschema/1-0-0',
data: {
bannerId: 'ASO01041'
}
}, [], {type: 'ttm', value: 1477401868});
window.snowplow('trackSocialInteraction:cf', 'retweet', 'twitter', '1234');
window.snowplow('trackAdImpression:cf',
'67965967893',
'cpm',
5.5,
'http://www.example.com',
'23',
'7',
'201',
'12'
);
window.snowplow('trackAdClick:cf',
'http://www.example.com', // targetUrl
'12243253', // clickId
'cpm', // costModel
2.5, // cost
'23', // bannerId
'7', // zoneId
'67965967893', // impressionId - the same as in trackAdImpression
'201', // advertiserId
'12' // campaignId
);
window.snowplow('trackAdConversion:cf',
'743560297', // conversionId
'cpa', // costModel
10, // cost
'ecommerce', // category
'purchase', // action
'', // property
99, // initialValue
'201', // advertiserId
'12' // campaignId
);
window.snowplow('trackAddToCart:cf', '000345', 'blue tie', 'clothing', 3.49, 2, 'GBP');
window.snowplow('trackRemoveFromCart:cf', '000345', 'blue tie', 'clothing', 3.49, 1, 'GBP');
window.snowplow('trackSiteSearch:cf',
['unified', 'log'], // search terms
{'category': 'books', 'sub-category': 'non-fiction'}, // filters
14, // results found
8 // results displayed on first page
);
window.snowplow('trackTiming:cf',
'load', // Category of the timing variable
'map_loaded', // Variable being recorded
50, // Milliseconds taken
'Map loading time' // Optional label
);
window.snowplow('trackConsentGranted:cf',
'1234', // Id
'5', // Version
'consent_document', // Name
'a document granting consent', // Description
'2020-11-21T08:00:00.000Z' // Expiry
);
window.snowplow('trackConsentWithdrawn:cf',
false, // All
'1234', // Id
'5', // Version
'consent_document', // Name
'a document withdrawing consent' // Description
);
try {
notExistentObject.notExistentProperty();
} catch(e) {
snowplow('trackError:cf', 'Cannot access notExistentProperty()', 'trackError.js', 237, 5, e);
}
window.snowplow('addEnhancedEcommerceActionContext:cf',
'T12345', // The Transaction ID
'Google Store - Online', // The affiliate
'37.39', // The revenue
'2.85', // The tax
'5.34', // The shipping
'WINTER2016' // The coupon
);
window.snowplow('addEnhancedEcommerceImpressionContext:cf',
'P12345', // The ID
'Android Warhol T-Shirt', // The name
'Search Results', // The list
'Google', // The brand
'Apparel/T-Shirts', // The category
'Black', // The variant
'1' // The position
);
window.snowplow('addEnhancedEcommerceProductContext:cf',
'P12345', // The ID
'Android Warhol T-Shirt', // The name
'Search Results', // The list
'Google', // The brand
'Apparel/T-Shirts', // The category
'Black', // The variant
1 // The quantity
);
window.snowplow('addEnhancedEcommercePromoContext:cf',
'PROMO_1234', // The Promotion ID
'Summer Sale', // The name
'summer_banner2', // The name of the creative
'banner_slot1' // The position
);
window.snowplow('trackEnhancedEcommerceAction:cf',
'purchase'
);
// track unhandled exception
window.snowplow('enableErrorTracking:cf', function (error) { return true; }, function (error) {
return [
{
schema: "iglu:org.schema/WebPage/jsonschema/1-0-0",
data: {
keywords: ['tester']
}
}
];
});
// Test for exception handling
function raiseException() {
notExistentObject.notExistentProperty();
}
setTimeout(raiseException, 3000);
</script>
</body>
</html>