-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
542 lines (452 loc) · 19.5 KB
/
Copy pathindex.html
File metadata and controls
542 lines (452 loc) · 19.5 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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
<!DOCTYPE html>
<html lang="en">
<head>
<script data-segment-write-key="BQ9dPm0Y9BYC2U5f6tHu4GekDZJU0XfI">
!(function () {
var i = "analytics",
analytics = (window[i] = window[i] || []);
if (!analytics.initialize)
if (analytics.invoked)
window.console &&
console.error &&
console.error("Segment snippet included twice.");
else {
analytics.invoked = !0;
analytics.methods = [
"trackSubmit",
"trackClick",
"trackLink",
"trackForm",
"pageview",
"identify",
"reset",
"group",
"track",
"ready",
"alias",
"debug",
"page",
"screen",
"once",
"off",
"on",
"addSourceMiddleware",
"addIntegrationMiddleware",
"setAnonymousId",
"addDestinationMiddleware",
"register",
];
analytics.factory = function (e) {
return function () {
if (window[i].initialized)
return window[i][e].apply(window[i], arguments);
var n = Array.prototype.slice.call(arguments);
if (
[
"track",
"screen",
"alias",
"group",
"page",
"identify",
].indexOf(e) > -1
) {
var c = document.querySelector("link[rel='canonical']");
n.push({
__t: "bpc",
c: (c && c.getAttribute("href")) || void 0,
p: location.pathname,
u: location.href,
s: location.search,
t: document.title,
r: document.referrer,
});
}
n.unshift(e);
analytics.push(n);
return analytics;
};
};
for (var n = 0; n < analytics.methods.length; n++) {
var key = analytics.methods[n];
analytics[key] = analytics.factory(key);
}
analytics._writeKey = document.currentScript.getAttribute("data-segment-write-key");
var r = document.getElementsByTagName("script")[0];
analytics.load = function (key, n) {
var t = document.createElement("script");
t.type = "text/javascript";
t.async = !0;
t.setAttribute("data-global-segment-analytics-key", i);
t.src =
"https://cdn.segment.com/analytics.js/v1/" +
key +
"/analytics.min.js";
r.parentNode.insertBefore(t, r);
analytics._loadOptions = n;
};
analytics.loadWithSignals = function (key, n) {
var signalsScript = document.createElement("script");
signalsScript.type = "text/javascript";
signalsScript.src =
"https://cdn.jsdelivr.net/npm/@segment/analytics-signals@latest/dist/umd/analytics-signals.umd.js";
signalsScript.async = !0;
r.parentNode.insertBefore(signalsScript, r);
signalsScript.onload = function () {
var signalsPlugin = new SignalsPlugin();
analytics.register(signalsPlugin);
analytics.load(key, n)
};
};
analytics.loadWithSignals(analytics._writeKey)
analytics.page()
}
})();
</script>
<script>
const get_ = (obj, path) => {
// Minimal safe getter: "a.b.c" => obj?.a?.b?.c
if (!obj || !path) return undefined;
return path.split('.').reduce((acc, key) => (acc && acc[key] !== undefined ? acc[key] : undefined), obj);
};
function lsKey(sessionId) {
var storagePrefix = 'ef'
return storagePrefix + ':products:' + sessionId
}
function saveSet(sessionId, set) {
if (!sessionId) return
try {
localStorage.setItem(lsKey(sessionId), JSON.stringify(Array.from(set)))
} catch (e) {
// quota or storage disabled; ignore
}
}
function loadSet(sessionId) {
if (!sessionId) return new Set()
try {
var raw = localStorage.getItem(lsKey(sessionId))
var arr = raw ? JSON.parse(raw) : []
if (!Array.isArray(arr)) arr = []
return new Set(arr.map(String))
} catch (e) {
return new Set()
}
}
class product_changes_tracker {
constructor() {
this.name = 'Product Change tracker';
this.type = 'enrichment';
this.version = '1';
}
isLoaded() {
return true;
}
async load(ctx, analytics) {
}
async identify(ctx) {
let session_id = localStorage.getItem("session_id") || null;
var ids = Array.from(loadSet(session_id))
var count = ids.length
ctx.updateEvent('traits.productChangesInLastSession', count);
}
async track(ctx) {
let session_id = localStorage.getItem("session_id") || null;
var evt = ctx.event || {}
if (session_id && evt.event === 'get_premiums') {
var props = evt.properties || {}
var productId = get(props, 'data.product_class')
if (productId !== undefined && productId !== null && productId !== '') {
var set = loadSet(session_id)
set.add(String(productId))
saveSet(session_id, set)
}
}
if (session_id) {
var ids = Array.from(loadSet(session_id))
var count = ids.length
// Safely set nested field:
ctx.updateEvent('context.productChangeHistory', {
ids: ids,
count: count,
session_id: session_id
})
}
ctx.event.properties.session_id = localStorage.getItem("session_id");
return ctx;
}
}
class session_tracker {
constructor() {
this.name = 'Session Tracker Plugin';
this.type = 'before';
this.version = '1';
}
isLoaded() {
return true;
}
async load(ctx, analytics) {
let session_id = localStorage.getItem("session_id") || null;
let session_timestamp = localStorage.getItem("session_timestamp") || null;
const now = new Date();
const diff = now - session_timestamp;
if (session_timestamp == null || diff < (30 * 60 * 1000)) { // Fixed the extra closing parenthesis here
console.log("Setting New Session");
let session_id = Array.from({ length: 32 }, () =>
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
[Math.floor(Math.random() * 62)]
).join('');
localStorage.setItem("session_id", session_id);
localStorage.setItem("session_timestamp", now);
}
return;
}
async track(ctx) {
ctx.event.properties.session_id = localStorage.getItem("session_id");
return ctx;
}
async page(ctx) {
ctx.event.properties.session_id = localStorage.getItem("session_id");
return ctx;
}
async identify(ctx) {
ctx.event.context.session_id = localStorage.getItem("session_id");
return ctx;
}
}
window.analytics.register(new session_tracker());
window.analytics.register(new product_changes_tracker());
const get = (obj, path) => {
// Minimal safe getter: "a.b.c" => obj?.a?.b?.c
if (!obj || !path) return undefined;
return path.split('.').reduce((acc, key) => (acc && acc[key] !== undefined ? acc[key] : undefined), obj);
};
function lsKey(sessionId) {
var storagePrefix = 'ef'
return storagePrefix + ':products:' + sessionId
}
function saveSet(sessionId, set) {
if (!sessionId) return
try {
localStorage.setItem(lsKey(sessionId), JSON.stringify(Array.from(set)))
} catch (e) {
// quota or storage disabled; ignore
}
}
function loadSet(sessionId) {
if (!sessionId) return new Set()
try {
var raw = localStorage.getItem(lsKey(sessionId))
var arr = raw ? JSON.parse(raw) : []
if (!Array.isArray(arr)) arr = []
return new Set(arr.map(String))
} catch (e) {
return new Set()
}
}
class product_changes_tracker {
constructor() {
this.name = 'Product Change tracker';
this.type = 'enrichment';
this.version = '1';
}
isLoaded() {
return true;
}
async load(ctx, analytics) {
}
async identify(ctx) {
let session_id = localStorage.getItem("session_id") || null;
var ids = Array.from(loadSet(session_id))
var count = ids.length
ctx.updateEvent('traits.productChangesInLastSession', count);
}
async track(ctx) {
let session_id = localStorage.getItem("session_id") || null;
var evt = ctx.event || {}
if (session_id && evt.event === 'get_premiums') {
var props = evt.properties || {}
var productId = get(props, 'data.product_class')
if (productId !== undefined && productId !== null && productId !== '') {
var set = loadSet(session_id)
set.add(String(productId))
saveSet(session_id, set)
}
}
if (session_id) {
var ids = Array.from(loadSet(session_id))
var count = ids.length
// Safely set nested field:
ctx.updateEvent('context.productChangeHistory', {
ids: ids,
count: count,
session_id: session_id
})
}
ctx.event.properties.session_id = localStorage.getItem("session_id");
return ctx;
}
}
class session_tracker {
constructor() {
this.name = 'Session Tracker Plugin';
this.type = 'before';
this.version = '1';
}
isLoaded() {
return true;
}
async load(ctx, analytics) {
let session_id = localStorage.getItem("session_id") || null;
let session_timestamp = localStorage.getItem("session_timestamp") || null;
const now = new Date();
const diff = now - session_timestamp;
if (session_timestamp == null || diff < (30 * 60 * 1000)) { // Fixed the extra closing parenthesis here
console.log("Setting New Session");
let session_id = Array.from({ length: 32 }, () =>
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
[Math.floor(Math.random() * 62)]
).join('');
localStorage.setItem("session_id", session_id);
localStorage.setItem("session_timestamp", now);
}
return;
}
async track(ctx) {
ctx.event.properties.session_id = localStorage.getItem("session_id");
return ctx;
}
async page(ctx) {
ctx.event.properties.session_id = localStorage.getItem("session_id");
return ctx;
}
async identify(ctx) {
ctx.event.context.session_id = localStorage.getItem("session_id");
return ctx;
}
}
window.analytics.register(new session_tracker());
window.analytics.register(new product_changes_tracker());
</script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test Web Tracking</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
.container {
max-width: 600px;
margin: 0 auto;
}
.field-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 5px;
}
input[type="text"],
input[type="email"],
select,
textarea {
width: 100%;
padding: 10px;
margin-bottom: 10px;
}
button {
padding: 10px 20px;
background-color: #007BFF;
color: white;
border: none;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
</style>
<script type="text/javascript">
window.heapReadyCb = window.heapReadyCb || [], window.heap = window.heap || [], heap.load = function (e, t) { window.heap.envId = e, window.heap.clientConfig = t = t || {}, window.heap.clientConfig.shouldFetchServerConfig = !1; var a = document.createElement("script"); a.type = "text/javascript", a.async = !0, a.src = "https://cdn.us.heap-api.com/config/" + e + "/heap_config.js"; var r = document.getElementsByTagName("script")[0]; r.parentNode.insertBefore(a, r); var n = ["init", "startTracking", "stopTracking", "track", "resetIdentity", "identify", "getSessionId", "getUserId", "getIdentity", "addUserProperties", "addEventProperties", "removeEventProperty", "clearEventProperties", "addAccountProperties", "addAdapter", "addTransformer", "addTransformerFn", "onReady", "addPageviewProperties", "removePageviewProperty", "clearPageviewProperties", "trackPageview"], i = function (e) { return function () { var t = Array.prototype.slice.call(arguments, 0); window.heapReadyCb.push({ name: e, fn: function () { heap[e] && heap[e].apply(heap, t) } }) } }; for (var p = 0; p < n.length; p++)heap[n[p]] = i(n[p]) };
heap.load("3745202683");
</script>
</head>
<body>
<div class="container">
<h1>Web Tracking Test Page</h1>
<!-- Random Input Fields -->
<div class="field-group">
<label for="name">Name</label>
<input type="text" id="name" placeholder="Enter your name">
</div>
<div class="field-group">
<label for="email">Email</label>
<input type="email" id="email" placeholder="Enter your email">
</div>
<div class="field-group">
<label for="age">Age</label>
<input type="number" id="age" placeholder="Enter your age">
</div>
<div class="field-group">
<label for="gender">Gender</label>
<select id="gender">
<option value="">Select</option>
<option value="male">Male</option>
<option value="female">Female</option>
<option value="other">Other</option>
</select>
</div>
<div class="field-group">
<label for="comments">Comments</label>
<textarea id="comments" rows="4" placeholder="Enter your comments"></textarea>
</div>
<!-- Random Buttons -->
<div class="field-group">
<button id="submitBtn">Submit</button>
<button id="resetBtn">Reset</button>
<button id="randomBtn">Random Action</button>
</div>
<div class="field-group">
<label for="product_class">Produt Class</label>
<select id="product_class">
<option value="prod1">Product1</option>
<option value="prod2">Product2</option>
<option value="prod3">Product3</option>
<option value="prod4">Product4</option>
<option value="prod5">Product5</option>
</select>
</div>
<div class="field-group">
<button id="trackBtn1">Track get_premiums</button>
</div>
<div class="field-group">
<button id="trackBtn2">Fire identify</button>
</div>
</div>
<script>
const userid = crypto.randomUUID();
// Sample click event handlers to simulate tracking interactions
document.getElementById('submitBtn').addEventListener('click', function () {
console.log('Submit button clicked');
alert('Submit button clicked');
});
document.getElementById('resetBtn').addEventListener('click', function () {
console.log('Reset button clicked');
alert('Reset button clicked');
});
document.getElementById('randomBtn').addEventListener('click', function () {
console.log('Random button clicked');
alert('Random button clicked');
});
document.getElementById('trackBtn1').addEventListener('click', function () {
analytics.track('get_premiums', { data: { product_class: document.getElementById('product_class').value } })
});
document.getElementById('trackBtn2').addEventListener('click', function () {
analytics.identify(userid, { firstName: 'Jon', lastName: 'Doe' })
});
document.getElementById('trackBtn3').addEventListener('click', function () {
console.log('Track Action 3 clicked');
alert('Track Action 3 clicked');
});
</script>
</body>
</html>