@usermaven/sdk-js 1.0.0 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/README.md +12 -1
- package/dist/npm/usermaven.cjs.js +1534 -4
- package/dist/npm/usermaven.d.ts +41 -6
- package/dist/npm/usermaven.es.js +1534 -4
- package/package.json +1 -1
package/dist/npm/usermaven.es.js
CHANGED
|
@@ -217,10 +217,1506 @@ function createLogger(logLevel) {
|
|
|
217
217
|
return logger;
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
+
var Config$1 = {
|
|
221
|
+
DEBUG: false,
|
|
222
|
+
LIB_VERSION: '1.0.0',
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
/* eslint camelcase: "off", eqeqeq: "off" */
|
|
226
|
+
|
|
227
|
+
/*
|
|
228
|
+
* Saved references to long variable names, so that closure compiler can
|
|
229
|
+
* minimize file size.
|
|
230
|
+
*/
|
|
231
|
+
|
|
232
|
+
const ArrayProto = Array.prototype,
|
|
233
|
+
FuncProto = Function.prototype,
|
|
234
|
+
ObjProto = Object.prototype,
|
|
235
|
+
slice = ArrayProto.slice,
|
|
236
|
+
toString = ObjProto.toString,
|
|
237
|
+
hasOwnProperty = ObjProto.hasOwnProperty,
|
|
238
|
+
win = typeof window !== 'undefined' ? window : {},
|
|
239
|
+
navigator$1 = win.navigator || { userAgent: '' },
|
|
240
|
+
document$1 = win.document || {},
|
|
241
|
+
userAgent = navigator$1.userAgent;
|
|
242
|
+
|
|
243
|
+
const nativeBind = FuncProto.bind,
|
|
244
|
+
nativeForEach = ArrayProto.forEach,
|
|
245
|
+
nativeIndexOf = ArrayProto.indexOf,
|
|
246
|
+
nativeIsArray = Array.isArray,
|
|
247
|
+
breaker = {};
|
|
248
|
+
|
|
249
|
+
var _ = {
|
|
250
|
+
trim: function (str) {
|
|
251
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim#Polyfill
|
|
252
|
+
return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '')
|
|
253
|
+
},
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
// Console override
|
|
257
|
+
var console$1 = {
|
|
258
|
+
/** @type {function(...*)} */
|
|
259
|
+
log: function () {
|
|
260
|
+
},
|
|
261
|
+
/** @type {function(...*)} */
|
|
262
|
+
error: function () {
|
|
263
|
+
},
|
|
264
|
+
/** @type {function(...*)} */
|
|
265
|
+
critical: function () {
|
|
266
|
+
if (!_.isUndefined(window.console) && window.console) {
|
|
267
|
+
var args = ['UserMaven error:', ...arguments];
|
|
268
|
+
try {
|
|
269
|
+
window.console.error.apply(window.console, args);
|
|
270
|
+
} catch (err) {
|
|
271
|
+
_.each(args, function (arg) {
|
|
272
|
+
window.console.error(arg);
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
// UNDERSCORE
|
|
280
|
+
// Embed part of the Underscore Library
|
|
281
|
+
_.bind = function (func, context) {
|
|
282
|
+
var args, bound;
|
|
283
|
+
if (nativeBind && func.bind === nativeBind) {
|
|
284
|
+
return nativeBind.apply(func, slice.call(arguments, 1))
|
|
285
|
+
}
|
|
286
|
+
if (!_.isFunction(func)) {
|
|
287
|
+
throw new TypeError()
|
|
288
|
+
}
|
|
289
|
+
args = slice.call(arguments, 2);
|
|
290
|
+
bound = function () {
|
|
291
|
+
if (!(this instanceof bound)) {
|
|
292
|
+
return func.apply(context, args.concat(slice.call(arguments)))
|
|
293
|
+
}
|
|
294
|
+
var ctor = {};
|
|
295
|
+
ctor.prototype = func.prototype;
|
|
296
|
+
var self = new ctor();
|
|
297
|
+
ctor.prototype = null;
|
|
298
|
+
var result = func.apply(self, args.concat(slice.call(arguments)));
|
|
299
|
+
if (Object(result) === result) {
|
|
300
|
+
return result
|
|
301
|
+
}
|
|
302
|
+
return self
|
|
303
|
+
};
|
|
304
|
+
return bound
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
_.bind_instance_methods = function (obj) {
|
|
308
|
+
for (var func in obj) {
|
|
309
|
+
if (typeof obj[func] === 'function') {
|
|
310
|
+
obj[func] = _.bind(obj[func], obj);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* @param {*=} obj
|
|
317
|
+
* @param {function(...*)=} iterator
|
|
318
|
+
* @param {Object=} context
|
|
319
|
+
*/
|
|
320
|
+
_.each = function (obj, iterator, context) {
|
|
321
|
+
if (obj === null || obj === undefined) {
|
|
322
|
+
return
|
|
323
|
+
}
|
|
324
|
+
if (nativeForEach && obj.forEach === nativeForEach) {
|
|
325
|
+
obj.forEach(iterator, context);
|
|
326
|
+
} else if (obj.length === +obj.length) {
|
|
327
|
+
for (var i = 0, l = obj.length; i < l; i++) {
|
|
328
|
+
if (i in obj && iterator.call(context, obj[i], i, obj) === breaker) {
|
|
329
|
+
return
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
} else {
|
|
333
|
+
for (var key in obj) {
|
|
334
|
+
if (hasOwnProperty.call(obj, key)) {
|
|
335
|
+
if (iterator.call(context, obj[key], key, obj) === breaker) {
|
|
336
|
+
return
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
_.extend = function (obj) {
|
|
344
|
+
_.each(slice.call(arguments, 1), function (source) {
|
|
345
|
+
for (var prop in source) {
|
|
346
|
+
if (source[prop] !== void 0) {
|
|
347
|
+
obj[prop] = source[prop];
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
return obj
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
_.isArray =
|
|
355
|
+
nativeIsArray ||
|
|
356
|
+
function (obj) {
|
|
357
|
+
return toString.call(obj) === '[object Array]'
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
// from a comment on http://dbj.org/dbj/?p=286
|
|
361
|
+
// fails on only one very rare and deliberate custom object:
|
|
362
|
+
// var bomb = { toString : undefined, valueOf: function(o) { return "function BOMBA!"; }};
|
|
363
|
+
_.isFunction = function (f) {
|
|
364
|
+
try {
|
|
365
|
+
return /^\s*\bfunction\b/.test(f)
|
|
366
|
+
} catch (x) {
|
|
367
|
+
return false
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
_.include = function (obj, target) {
|
|
372
|
+
var found = false;
|
|
373
|
+
if (obj === null) {
|
|
374
|
+
return found
|
|
375
|
+
}
|
|
376
|
+
if (nativeIndexOf && obj.indexOf === nativeIndexOf) {
|
|
377
|
+
return obj.indexOf(target) != -1
|
|
378
|
+
}
|
|
379
|
+
_.each(obj, function (value) {
|
|
380
|
+
if (found || (found = value === target)) {
|
|
381
|
+
return breaker
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
return found
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
_.includes = function (str, needle) {
|
|
388
|
+
return str.indexOf(needle) !== -1
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
// Underscore Addons
|
|
392
|
+
_.isObject = function (obj) {
|
|
393
|
+
return obj === Object(obj) && !_.isArray(obj)
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
_.isEmptyObject = function (obj) {
|
|
397
|
+
if (_.isObject(obj)) {
|
|
398
|
+
for (var key in obj) {
|
|
399
|
+
if (hasOwnProperty.call(obj, key)) {
|
|
400
|
+
return false
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return true
|
|
404
|
+
}
|
|
405
|
+
return false
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
_.isUndefined = function (obj) {
|
|
409
|
+
return obj === void 0
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
_.isString = function (obj) {
|
|
413
|
+
return toString.call(obj) == '[object String]'
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
_.isDate = function (obj) {
|
|
417
|
+
return toString.call(obj) == '[object Date]'
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
_.isNumber = function (obj) {
|
|
421
|
+
return toString.call(obj) == '[object Number]'
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
_.encodeDates = function (obj) {
|
|
425
|
+
_.each(obj, function (v, k) {
|
|
426
|
+
if (_.isDate(v)) {
|
|
427
|
+
obj[k] = _.formatDate(v);
|
|
428
|
+
} else if (_.isObject(v)) {
|
|
429
|
+
obj[k] = _.encodeDates(v); // recurse
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
return obj
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
_.timestamp = function () {
|
|
436
|
+
Date.now =
|
|
437
|
+
Date.now ||
|
|
438
|
+
function () {
|
|
439
|
+
return +new Date()
|
|
440
|
+
};
|
|
441
|
+
return Date.now()
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
_.formatDate = function (d) {
|
|
445
|
+
// YYYY-MM-DDTHH:MM:SS in UTC
|
|
446
|
+
function pad(n) {
|
|
447
|
+
return n < 10 ? '0' + n : n
|
|
448
|
+
}
|
|
449
|
+
return (
|
|
450
|
+
d.getUTCFullYear() +
|
|
451
|
+
'-' +
|
|
452
|
+
pad(d.getUTCMonth() + 1) +
|
|
453
|
+
'-' +
|
|
454
|
+
pad(d.getUTCDate()) +
|
|
455
|
+
'T' +
|
|
456
|
+
pad(d.getUTCHours()) +
|
|
457
|
+
':' +
|
|
458
|
+
pad(d.getUTCMinutes()) +
|
|
459
|
+
':' +
|
|
460
|
+
pad(d.getUTCSeconds())
|
|
461
|
+
)
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
_.safewrap = function (f) {
|
|
465
|
+
return function () {
|
|
466
|
+
try {
|
|
467
|
+
return f.apply(this, arguments)
|
|
468
|
+
} catch (e) {
|
|
469
|
+
console$1.critical('Implementation error. Please turn on debug and contact support@usermaven.com.');
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
_.safewrap_class = function (klass, functions) {
|
|
475
|
+
for (var i = 0; i < functions.length; i++) {
|
|
476
|
+
klass.prototype[functions[i]] = _.safewrap(klass.prototype[functions[i]]);
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
_.safewrap_instance_methods = function (obj) {
|
|
481
|
+
for (var func in obj) {
|
|
482
|
+
if (typeof obj[func] === 'function') {
|
|
483
|
+
obj[func] = _.safewrap(obj[func]);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
_.strip_empty_properties = function (p) {
|
|
489
|
+
var ret = {};
|
|
490
|
+
_.each(p, function (v, k) {
|
|
491
|
+
if (_.isString(v) && v.length > 0) {
|
|
492
|
+
ret[k] = v;
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
return ret
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
// Deep copies an object.
|
|
499
|
+
// It handles cycles by replacing all references to them with `undefined`
|
|
500
|
+
// Also supports customizing native values
|
|
501
|
+
const COPY_IN_PROGRESS_ATTRIBUTE =
|
|
502
|
+
typeof Symbol !== 'undefined' ? Symbol('__deepCircularCopyInProgress__') : '__deepCircularCopyInProgress__';
|
|
503
|
+
|
|
504
|
+
function deepCircularCopy(value, customizer) {
|
|
505
|
+
if (value !== Object(value)) return customizer ? customizer(value) : value // primitive value
|
|
506
|
+
|
|
507
|
+
if (value[COPY_IN_PROGRESS_ATTRIBUTE]) return undefined
|
|
508
|
+
|
|
509
|
+
value[COPY_IN_PROGRESS_ATTRIBUTE] = true;
|
|
510
|
+
let result;
|
|
511
|
+
|
|
512
|
+
if (_.isArray(value)) {
|
|
513
|
+
result = [];
|
|
514
|
+
_.each(value, (it) => {
|
|
515
|
+
result.push(deepCircularCopy(it, customizer));
|
|
516
|
+
});
|
|
517
|
+
} else {
|
|
518
|
+
result = {};
|
|
519
|
+
_.each(value, (val, key) => {
|
|
520
|
+
if (key !== COPY_IN_PROGRESS_ATTRIBUTE) {
|
|
521
|
+
result[key] = deepCircularCopy(val, customizer);
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
delete value[COPY_IN_PROGRESS_ATTRIBUTE];
|
|
526
|
+
return result
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
_.copyAndTruncateStrings = (object, maxStringLength) =>
|
|
530
|
+
deepCircularCopy(
|
|
531
|
+
object,
|
|
532
|
+
(value) => {
|
|
533
|
+
if (typeof value === 'string' && maxStringLength !== null) {
|
|
534
|
+
value = value.slice(0, maxStringLength);
|
|
535
|
+
}
|
|
536
|
+
return value
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
_.base64Encode = function (data) {
|
|
540
|
+
var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
541
|
+
var o1,
|
|
542
|
+
o2,
|
|
543
|
+
o3,
|
|
544
|
+
h1,
|
|
545
|
+
h2,
|
|
546
|
+
h3,
|
|
547
|
+
h4,
|
|
548
|
+
bits,
|
|
549
|
+
i = 0,
|
|
550
|
+
ac = 0,
|
|
551
|
+
enc = '',
|
|
552
|
+
tmp_arr = [];
|
|
553
|
+
|
|
554
|
+
if (!data) {
|
|
555
|
+
return data
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
data = _.utf8Encode(data);
|
|
559
|
+
|
|
560
|
+
do {
|
|
561
|
+
// pack three octets into four hexets
|
|
562
|
+
o1 = data.charCodeAt(i++);
|
|
563
|
+
o2 = data.charCodeAt(i++);
|
|
564
|
+
o3 = data.charCodeAt(i++);
|
|
565
|
+
|
|
566
|
+
bits = (o1 << 16) | (o2 << 8) | o3;
|
|
567
|
+
|
|
568
|
+
h1 = (bits >> 18) & 0x3f;
|
|
569
|
+
h2 = (bits >> 12) & 0x3f;
|
|
570
|
+
h3 = (bits >> 6) & 0x3f;
|
|
571
|
+
h4 = bits & 0x3f;
|
|
572
|
+
|
|
573
|
+
// use hexets to index into b64, and append result to encoded string
|
|
574
|
+
tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
|
|
575
|
+
} while (i < data.length)
|
|
576
|
+
|
|
577
|
+
enc = tmp_arr.join('');
|
|
578
|
+
|
|
579
|
+
switch (data.length % 3) {
|
|
580
|
+
case 1:
|
|
581
|
+
enc = enc.slice(0, -2) + '==';
|
|
582
|
+
break
|
|
583
|
+
case 2:
|
|
584
|
+
enc = enc.slice(0, -1) + '=';
|
|
585
|
+
break
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
return enc
|
|
589
|
+
};
|
|
590
|
+
|
|
591
|
+
_.utf8Encode = function (string) {
|
|
592
|
+
string = (string + '').replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
593
|
+
|
|
594
|
+
var utftext = '',
|
|
595
|
+
start,
|
|
596
|
+
end;
|
|
597
|
+
var stringl = 0,
|
|
598
|
+
n;
|
|
599
|
+
|
|
600
|
+
start = end = 0;
|
|
601
|
+
stringl = string.length;
|
|
602
|
+
|
|
603
|
+
for (n = 0; n < stringl; n++) {
|
|
604
|
+
var c1 = string.charCodeAt(n);
|
|
605
|
+
var enc = null;
|
|
606
|
+
|
|
607
|
+
if (c1 < 128) {
|
|
608
|
+
end++;
|
|
609
|
+
} else if (c1 > 127 && c1 < 2048) {
|
|
610
|
+
enc = String.fromCharCode((c1 >> 6) | 192, (c1 & 63) | 128);
|
|
611
|
+
} else {
|
|
612
|
+
enc = String.fromCharCode((c1 >> 12) | 224, ((c1 >> 6) & 63) | 128, (c1 & 63) | 128);
|
|
613
|
+
}
|
|
614
|
+
if (enc !== null) {
|
|
615
|
+
if (end > start) {
|
|
616
|
+
utftext += string.substring(start, end);
|
|
617
|
+
}
|
|
618
|
+
utftext += enc;
|
|
619
|
+
start = end = n + 1;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
if (end > start) {
|
|
624
|
+
utftext += string.substring(start, string.length);
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
return utftext
|
|
628
|
+
};
|
|
629
|
+
|
|
630
|
+
_.UUID = (function () {
|
|
631
|
+
// Time/ticks information
|
|
632
|
+
// 1*new Date() is a cross browser version of Date.now()
|
|
633
|
+
var T = function () {
|
|
634
|
+
var d = 1 * new Date(),
|
|
635
|
+
i = 0;
|
|
636
|
+
|
|
637
|
+
// this while loop figures how many browser ticks go by
|
|
638
|
+
// before 1*new Date() returns a new number, ie the amount
|
|
639
|
+
// of ticks that go by per millisecond
|
|
640
|
+
while (d == 1 * new Date()) {
|
|
641
|
+
i++;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
return d.toString(16) + i.toString(16)
|
|
645
|
+
};
|
|
646
|
+
|
|
647
|
+
// Math.Random entropy
|
|
648
|
+
var R = function () {
|
|
649
|
+
return Math.random().toString(16).replace('.', '')
|
|
650
|
+
};
|
|
651
|
+
|
|
652
|
+
// User agent entropy
|
|
653
|
+
// This function takes the user agent string, and then xors
|
|
654
|
+
// together each sequence of 8 bytes. This produces a final
|
|
655
|
+
// sequence of 8 bytes which it returns as hex.
|
|
656
|
+
var UA = function () {
|
|
657
|
+
var ua = userAgent,
|
|
658
|
+
i,
|
|
659
|
+
ch,
|
|
660
|
+
buffer = [],
|
|
661
|
+
ret = 0;
|
|
662
|
+
|
|
663
|
+
function xor(result, byte_array) {
|
|
664
|
+
var j,
|
|
665
|
+
tmp = 0;
|
|
666
|
+
for (j = 0; j < byte_array.length; j++) {
|
|
667
|
+
tmp |= buffer[j] << (j * 8);
|
|
668
|
+
}
|
|
669
|
+
return result ^ tmp
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
for (i = 0; i < ua.length; i++) {
|
|
673
|
+
ch = ua.charCodeAt(i);
|
|
674
|
+
buffer.unshift(ch & 0xff);
|
|
675
|
+
if (buffer.length >= 4) {
|
|
676
|
+
ret = xor(ret, buffer);
|
|
677
|
+
buffer = [];
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
if (buffer.length > 0) {
|
|
682
|
+
ret = xor(ret, buffer);
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
return ret.toString(16)
|
|
686
|
+
};
|
|
687
|
+
|
|
688
|
+
return function () {
|
|
689
|
+
var se = (window.screen.height * window.screen.width).toString(16);
|
|
690
|
+
return T() + '-' + R() + '-' + UA() + '-' + se + '-' + T()
|
|
691
|
+
}
|
|
692
|
+
})();
|
|
693
|
+
|
|
694
|
+
// _.isBlockedUA()
|
|
695
|
+
// This is to block various web spiders from executing our JS and
|
|
696
|
+
// sending false captureing data
|
|
697
|
+
_.isBlockedUA = function (ua) {
|
|
698
|
+
if (/(google web preview|baiduspider|yandexbot|bingbot|googlebot|yahoo! slurp)/i.test(ua)) {
|
|
699
|
+
return true
|
|
700
|
+
}
|
|
701
|
+
return false
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
/**
|
|
705
|
+
* @param {Object=} formdata
|
|
706
|
+
* @param {string=} arg_separator
|
|
707
|
+
*/
|
|
708
|
+
_.HTTPBuildQuery = function (formdata, arg_separator) {
|
|
709
|
+
var use_val,
|
|
710
|
+
use_key,
|
|
711
|
+
tph_arr = [];
|
|
712
|
+
|
|
713
|
+
if (_.isUndefined(arg_separator)) {
|
|
714
|
+
arg_separator = '&';
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
_.each(formdata, function (val, key) {
|
|
718
|
+
use_val = encodeURIComponent(val.toString());
|
|
719
|
+
use_key = encodeURIComponent(key);
|
|
720
|
+
tph_arr[tph_arr.length] = use_key + '=' + use_val;
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
return tph_arr.join(arg_separator)
|
|
724
|
+
};
|
|
725
|
+
|
|
726
|
+
_.getQueryParam = function (url, param) {
|
|
727
|
+
// Expects a raw URL
|
|
728
|
+
|
|
729
|
+
param = param.replace(/[[]/, '\\[').replace(/[\]]/, '\\]');
|
|
730
|
+
var regexS = '[\\?&]' + param + '=([^&#]*)',
|
|
731
|
+
regex = new RegExp(regexS),
|
|
732
|
+
results = regex.exec(url);
|
|
733
|
+
if (results === null || (results && typeof results[1] !== 'string' && results[1].length)) {
|
|
734
|
+
return ''
|
|
735
|
+
} else {
|
|
736
|
+
var result = results[1];
|
|
737
|
+
try {
|
|
738
|
+
result = decodeURIComponent(result);
|
|
739
|
+
} catch (err) {
|
|
740
|
+
}
|
|
741
|
+
return result.replace(/\+/g, ' ')
|
|
742
|
+
}
|
|
743
|
+
};
|
|
744
|
+
|
|
745
|
+
_.getHashParam = function (hash, param) {
|
|
746
|
+
var matches = hash.match(new RegExp(param + '=([^&]*)'));
|
|
747
|
+
return matches ? matches[1] : null
|
|
748
|
+
};
|
|
749
|
+
|
|
750
|
+
_.register_event = (function () {
|
|
751
|
+
// written by Dean Edwards, 2005
|
|
752
|
+
// with input from Tino Zijdel - crisp@xs4all.nl
|
|
753
|
+
// with input from Carl Sverre - mail@carlsverre.com
|
|
754
|
+
// http://dean.edwards.name/weblog/2005/10/add-event/
|
|
755
|
+
// https://gist.github.com/1930440
|
|
756
|
+
|
|
757
|
+
/**
|
|
758
|
+
* @param {Object} element
|
|
759
|
+
* @param {string} type
|
|
760
|
+
* @param {function(...*)} handler
|
|
761
|
+
* @param {boolean=} oldSchool
|
|
762
|
+
* @param {boolean=} useCapture
|
|
763
|
+
*/
|
|
764
|
+
var register_event = function (element, type, handler, oldSchool, useCapture) {
|
|
765
|
+
if (!element) {
|
|
766
|
+
return
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
if (element.addEventListener && !oldSchool) {
|
|
770
|
+
element.addEventListener(type, handler, !!useCapture);
|
|
771
|
+
} else {
|
|
772
|
+
var ontype = 'on' + type;
|
|
773
|
+
var old_handler = element[ontype]; // can be undefined
|
|
774
|
+
element[ontype] = makeHandler(element, handler, old_handler);
|
|
775
|
+
}
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
function makeHandler(element, new_handler, old_handlers) {
|
|
779
|
+
var handler = function (event) {
|
|
780
|
+
event = event || fixEvent(window.event);
|
|
781
|
+
|
|
782
|
+
// this basically happens in firefox whenever another script
|
|
783
|
+
// overwrites the onload callback and doesn't pass the event
|
|
784
|
+
// object to previously defined callbacks. All the browsers
|
|
785
|
+
// that don't define window.event implement addEventListener
|
|
786
|
+
// so the dom_loaded handler will still be fired as usual.
|
|
787
|
+
if (!event) {
|
|
788
|
+
return undefined
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
var ret = true;
|
|
792
|
+
var old_result, new_result;
|
|
793
|
+
|
|
794
|
+
if (_.isFunction(old_handlers)) {
|
|
795
|
+
old_result = old_handlers(event);
|
|
796
|
+
}
|
|
797
|
+
new_result = new_handler.call(element, event);
|
|
798
|
+
|
|
799
|
+
if (false === old_result || false === new_result) {
|
|
800
|
+
ret = false;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
return ret
|
|
804
|
+
};
|
|
805
|
+
|
|
806
|
+
return handler
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
function fixEvent(event) {
|
|
810
|
+
if (event) {
|
|
811
|
+
event.preventDefault = fixEvent.preventDefault;
|
|
812
|
+
event.stopPropagation = fixEvent.stopPropagation;
|
|
813
|
+
}
|
|
814
|
+
return event
|
|
815
|
+
}
|
|
816
|
+
fixEvent.preventDefault = function () {
|
|
817
|
+
this.returnValue = false;
|
|
818
|
+
};
|
|
819
|
+
fixEvent.stopPropagation = function () {
|
|
820
|
+
this.cancelBubble = true;
|
|
821
|
+
};
|
|
822
|
+
|
|
823
|
+
return register_event
|
|
824
|
+
})();
|
|
825
|
+
|
|
826
|
+
_.info = {
|
|
827
|
+
campaignParams: function () {
|
|
828
|
+
var campaign_keywords = 'utm_source utm_medium utm_campaign utm_content utm_term gclid'.split(' '),
|
|
829
|
+
kw = '',
|
|
830
|
+
params = {};
|
|
831
|
+
_.each(campaign_keywords, function (kwkey) {
|
|
832
|
+
kw = _.getQueryParam(document$1.URL, kwkey);
|
|
833
|
+
if (kw.length) {
|
|
834
|
+
params[kwkey] = kw;
|
|
835
|
+
}
|
|
836
|
+
});
|
|
837
|
+
|
|
838
|
+
return params
|
|
839
|
+
},
|
|
840
|
+
|
|
841
|
+
searchEngine: function (referrer) {
|
|
842
|
+
if (referrer.search('https?://(.*)google.([^/?]*)') === 0) {
|
|
843
|
+
return 'google'
|
|
844
|
+
} else if (referrer.search('https?://(.*)bing.com') === 0) {
|
|
845
|
+
return 'bing'
|
|
846
|
+
} else if (referrer.search('https?://(.*)yahoo.com') === 0) {
|
|
847
|
+
return 'yahoo'
|
|
848
|
+
} else if (referrer.search('https?://(.*)duckduckgo.com') === 0) {
|
|
849
|
+
return 'duckduckgo'
|
|
850
|
+
} else {
|
|
851
|
+
return null
|
|
852
|
+
}
|
|
853
|
+
},
|
|
854
|
+
|
|
855
|
+
searchInfo: function (referrer) {
|
|
856
|
+
var search = _.info.searchEngine(referrer),
|
|
857
|
+
param = search != 'yahoo' ? 'q' : 'p',
|
|
858
|
+
ret = {};
|
|
859
|
+
|
|
860
|
+
if (search !== null) {
|
|
861
|
+
ret['$search_engine'] = search;
|
|
862
|
+
|
|
863
|
+
var keyword = _.getQueryParam(referrer, param);
|
|
864
|
+
if (keyword.length) {
|
|
865
|
+
ret['ph_keyword'] = keyword;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
return ret
|
|
870
|
+
},
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* This function detects which browser is running this script.
|
|
874
|
+
* The order of the checks are important since many user agents
|
|
875
|
+
* include key words used in later checks.
|
|
876
|
+
*/
|
|
877
|
+
browser: function (user_agent, vendor, opera) {
|
|
878
|
+
vendor = vendor || ''; // vendor is undefined for at least IE9
|
|
879
|
+
if (opera || _.includes(user_agent, ' OPR/')) {
|
|
880
|
+
if (_.includes(user_agent, 'Mini')) {
|
|
881
|
+
return 'Opera Mini'
|
|
882
|
+
}
|
|
883
|
+
return 'Opera'
|
|
884
|
+
} else if (/(BlackBerry|PlayBook|BB10)/i.test(user_agent)) {
|
|
885
|
+
return 'BlackBerry'
|
|
886
|
+
} else if (_.includes(user_agent, 'IEMobile') || _.includes(user_agent, 'WPDesktop')) {
|
|
887
|
+
return 'Internet Explorer Mobile'
|
|
888
|
+
} else if (_.includes(user_agent, 'SamsungBrowser/')) {
|
|
889
|
+
// https://developer.samsung.com/internet/user-agent-string-format
|
|
890
|
+
return 'Samsung Internet'
|
|
891
|
+
} else if (_.includes(user_agent, 'Edge') || _.includes(user_agent, 'Edg/')) {
|
|
892
|
+
return 'Microsoft Edge'
|
|
893
|
+
} else if (_.includes(user_agent, 'FBIOS')) {
|
|
894
|
+
return 'Facebook Mobile'
|
|
895
|
+
} else if (_.includes(user_agent, 'Chrome')) {
|
|
896
|
+
return 'Chrome'
|
|
897
|
+
} else if (_.includes(user_agent, 'CriOS')) {
|
|
898
|
+
return 'Chrome iOS'
|
|
899
|
+
} else if (_.includes(user_agent, 'UCWEB') || _.includes(user_agent, 'UCBrowser')) {
|
|
900
|
+
return 'UC Browser'
|
|
901
|
+
} else if (_.includes(user_agent, 'FxiOS')) {
|
|
902
|
+
return 'Firefox iOS'
|
|
903
|
+
} else if (_.includes(vendor, 'Apple')) {
|
|
904
|
+
if (_.includes(user_agent, 'Mobile')) {
|
|
905
|
+
return 'Mobile Safari'
|
|
906
|
+
}
|
|
907
|
+
return 'Safari'
|
|
908
|
+
} else if (_.includes(user_agent, 'Android')) {
|
|
909
|
+
return 'Android Mobile'
|
|
910
|
+
} else if (_.includes(user_agent, 'Konqueror')) {
|
|
911
|
+
return 'Konqueror'
|
|
912
|
+
} else if (_.includes(user_agent, 'Firefox')) {
|
|
913
|
+
return 'Firefox'
|
|
914
|
+
} else if (_.includes(user_agent, 'MSIE') || _.includes(user_agent, 'Trident/')) {
|
|
915
|
+
return 'Internet Explorer'
|
|
916
|
+
} else if (_.includes(user_agent, 'Gecko')) {
|
|
917
|
+
return 'Mozilla'
|
|
918
|
+
} else {
|
|
919
|
+
return ''
|
|
920
|
+
}
|
|
921
|
+
},
|
|
922
|
+
|
|
923
|
+
/**
|
|
924
|
+
* This function detects which browser version is running this script,
|
|
925
|
+
* parsing major and minor version (e.g., 42.1). User agent strings from:
|
|
926
|
+
* http://www.useragentstring.com/pages/useragentstring.php
|
|
927
|
+
*/
|
|
928
|
+
browserVersion: function (userAgent, vendor, opera) {
|
|
929
|
+
var browser = _.info.browser(userAgent, vendor, opera);
|
|
930
|
+
var versionRegexs = {
|
|
931
|
+
'Internet Explorer Mobile': /rv:(\d+(\.\d+)?)/,
|
|
932
|
+
'Microsoft Edge': /Edge?\/(\d+(\.\d+)?)/,
|
|
933
|
+
Chrome: /Chrome\/(\d+(\.\d+)?)/,
|
|
934
|
+
'Chrome iOS': /CriOS\/(\d+(\.\d+)?)/,
|
|
935
|
+
'UC Browser': /(UCBrowser|UCWEB)\/(\d+(\.\d+)?)/,
|
|
936
|
+
Safari: /Version\/(\d+(\.\d+)?)/,
|
|
937
|
+
'Mobile Safari': /Version\/(\d+(\.\d+)?)/,
|
|
938
|
+
Opera: /(Opera|OPR)\/(\d+(\.\d+)?)/,
|
|
939
|
+
Firefox: /Firefox\/(\d+(\.\d+)?)/,
|
|
940
|
+
'Firefox iOS': /FxiOS\/(\d+(\.\d+)?)/,
|
|
941
|
+
Konqueror: /Konqueror:(\d+(\.\d+)?)/,
|
|
942
|
+
BlackBerry: /BlackBerry (\d+(\.\d+)?)/,
|
|
943
|
+
'Android Mobile': /android\s(\d+(\.\d+)?)/,
|
|
944
|
+
'Samsung Internet': /SamsungBrowser\/(\d+(\.\d+)?)/,
|
|
945
|
+
'Internet Explorer': /(rv:|MSIE )(\d+(\.\d+)?)/,
|
|
946
|
+
Mozilla: /rv:(\d+(\.\d+)?)/,
|
|
947
|
+
};
|
|
948
|
+
var regex = versionRegexs[browser];
|
|
949
|
+
if (regex === undefined) {
|
|
950
|
+
return null
|
|
951
|
+
}
|
|
952
|
+
var matches = userAgent.match(regex);
|
|
953
|
+
if (!matches) {
|
|
954
|
+
return null
|
|
955
|
+
}
|
|
956
|
+
return parseFloat(matches[matches.length - 2])
|
|
957
|
+
},
|
|
958
|
+
|
|
959
|
+
os: function () {
|
|
960
|
+
var a = userAgent;
|
|
961
|
+
if (/Windows/i.test(a)) {
|
|
962
|
+
if (/Phone/.test(a) || /WPDesktop/.test(a)) {
|
|
963
|
+
return 'Windows Phone'
|
|
964
|
+
}
|
|
965
|
+
return 'Windows'
|
|
966
|
+
} else if (/(iPhone|iPad|iPod)/.test(a)) {
|
|
967
|
+
return 'iOS'
|
|
968
|
+
} else if (/Android/.test(a)) {
|
|
969
|
+
return 'Android'
|
|
970
|
+
} else if (/(BlackBerry|PlayBook|BB10)/i.test(a)) {
|
|
971
|
+
return 'BlackBerry'
|
|
972
|
+
} else if (/Mac/i.test(a)) {
|
|
973
|
+
return 'Mac OS X'
|
|
974
|
+
} else if (/Linux/.test(a)) {
|
|
975
|
+
return 'Linux'
|
|
976
|
+
} else if (/CrOS/.test(a)) {
|
|
977
|
+
return 'Chrome OS'
|
|
978
|
+
} else {
|
|
979
|
+
return ''
|
|
980
|
+
}
|
|
981
|
+
},
|
|
982
|
+
|
|
983
|
+
device: function (user_agent) {
|
|
984
|
+
if (/Windows Phone/i.test(user_agent) || /WPDesktop/.test(user_agent)) {
|
|
985
|
+
return 'Windows Phone'
|
|
986
|
+
} else if (/iPad/.test(user_agent)) {
|
|
987
|
+
return 'iPad'
|
|
988
|
+
} else if (/iPod/.test(user_agent)) {
|
|
989
|
+
return 'iPod Touch'
|
|
990
|
+
} else if (/iPhone/.test(user_agent)) {
|
|
991
|
+
return 'iPhone'
|
|
992
|
+
} else if (/(BlackBerry|PlayBook|BB10)/i.test(user_agent)) {
|
|
993
|
+
return 'BlackBerry'
|
|
994
|
+
} else if (/Android/.test(user_agent) && !/Mobile/.test(user_agent)) {
|
|
995
|
+
return 'Android Tablet'
|
|
996
|
+
} else if (/Android/.test(user_agent)) {
|
|
997
|
+
return 'Android'
|
|
998
|
+
} else {
|
|
999
|
+
return ''
|
|
1000
|
+
}
|
|
1001
|
+
},
|
|
1002
|
+
|
|
1003
|
+
deviceType: function (user_agent) {
|
|
1004
|
+
const device = this.device(user_agent);
|
|
1005
|
+
if (device === 'iPad' || device === 'Android Tablet') {
|
|
1006
|
+
return 'Tablet'
|
|
1007
|
+
} else if (device) {
|
|
1008
|
+
return 'Mobile'
|
|
1009
|
+
} else {
|
|
1010
|
+
return 'Desktop'
|
|
1011
|
+
}
|
|
1012
|
+
},
|
|
1013
|
+
|
|
1014
|
+
referringDomain: function (referrer) {
|
|
1015
|
+
var split = referrer.split('/');
|
|
1016
|
+
if (split.length >= 3) {
|
|
1017
|
+
return split[2]
|
|
1018
|
+
}
|
|
1019
|
+
return ''
|
|
1020
|
+
},
|
|
1021
|
+
|
|
1022
|
+
properties: function () {
|
|
1023
|
+
return _.extend(
|
|
1024
|
+
_.strip_empty_properties({
|
|
1025
|
+
$os: _.info.os(),
|
|
1026
|
+
$browser: _.info.browser(userAgent, navigator$1.vendor, window.opera),
|
|
1027
|
+
$device: _.info.device(userAgent),
|
|
1028
|
+
$device_type: _.info.deviceType(userAgent),
|
|
1029
|
+
}),
|
|
1030
|
+
{
|
|
1031
|
+
$current_url: window.location.href,
|
|
1032
|
+
$host: window.location.host,
|
|
1033
|
+
$pathname: window.location.pathname,
|
|
1034
|
+
$browser_version: _.info.browserVersion(userAgent, navigator$1.vendor, window.opera),
|
|
1035
|
+
$screen_height: window.screen.height,
|
|
1036
|
+
$screen_width: window.screen.width,
|
|
1037
|
+
$viewport_height: window.innerHeight,
|
|
1038
|
+
$viewport_width: window.innerWidth,
|
|
1039
|
+
$lib: 'web',
|
|
1040
|
+
$lib_version: Config$1.LIB_VERSION,
|
|
1041
|
+
$insert_id: Math.random().toString(36).substring(2, 10) + Math.random().toString(36).substring(2, 10),
|
|
1042
|
+
$time: _.timestamp() / 1000, // epoch time in seconds
|
|
1043
|
+
}
|
|
1044
|
+
)
|
|
1045
|
+
},
|
|
1046
|
+
|
|
1047
|
+
people_properties: function () {
|
|
1048
|
+
return _.extend(
|
|
1049
|
+
_.strip_empty_properties({
|
|
1050
|
+
$os: _.info.os(),
|
|
1051
|
+
$browser: _.info.browser(userAgent, navigator$1.vendor, window.opera),
|
|
1052
|
+
}),
|
|
1053
|
+
{
|
|
1054
|
+
$browser_version: _.info.browserVersion(userAgent, navigator$1.vendor, window.opera),
|
|
1055
|
+
}
|
|
1056
|
+
)
|
|
1057
|
+
},
|
|
1058
|
+
};
|
|
1059
|
+
|
|
1060
|
+
// EXPORTS (for closure compiler)
|
|
1061
|
+
_['isObject'] = _.isObject;
|
|
1062
|
+
_['isBlockedUA'] = _.isBlockedUA;
|
|
1063
|
+
_['isEmptyObject'] = _.isEmptyObject;
|
|
1064
|
+
_['info'] = _.info;
|
|
1065
|
+
_['info']['device'] = _.info.device;
|
|
1066
|
+
_['info']['browser'] = _.info.browser;
|
|
1067
|
+
_['info']['browserVersion'] = _.info.browserVersion;
|
|
1068
|
+
_['info']['properties'] = _.info.properties;
|
|
1069
|
+
|
|
1070
|
+
var DOMAIN_MATCH_REGEX = /[a-z0-9][a-z0-9-]+\.[a-z.]{2,6}$/i;
|
|
1071
|
+
|
|
1072
|
+
// Methods partially borrowed from quirksmode.org/js/cookies.html
|
|
1073
|
+
const cookieStore = {
|
|
1074
|
+
get: function (name) {
|
|
1075
|
+
try {
|
|
1076
|
+
var nameEQ = name + '=';
|
|
1077
|
+
var ca = document.cookie.split(';');
|
|
1078
|
+
for (var i = 0; i < ca.length; i++) {
|
|
1079
|
+
var c = ca[i];
|
|
1080
|
+
while (c.charAt(0) == ' ') {
|
|
1081
|
+
c = c.substring(1, c.length);
|
|
1082
|
+
}
|
|
1083
|
+
if (c.indexOf(nameEQ) === 0) {
|
|
1084
|
+
return decodeURIComponent(c.substring(nameEQ.length, c.length))
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
} catch (err) {}
|
|
1088
|
+
return null
|
|
1089
|
+
},
|
|
1090
|
+
|
|
1091
|
+
parse: function (name) {
|
|
1092
|
+
var cookie;
|
|
1093
|
+
try {
|
|
1094
|
+
cookie = JSON.parse(cookieStore.get(name)) || {};
|
|
1095
|
+
} catch (err) {
|
|
1096
|
+
// noop
|
|
1097
|
+
}
|
|
1098
|
+
return cookie
|
|
1099
|
+
},
|
|
1100
|
+
|
|
1101
|
+
set: function (name, value, days, cross_subdomain, is_secure) {
|
|
1102
|
+
try {
|
|
1103
|
+
var cdomain = '',
|
|
1104
|
+
expires = '',
|
|
1105
|
+
secure = '';
|
|
1106
|
+
|
|
1107
|
+
if (cross_subdomain) {
|
|
1108
|
+
var matches = document.location.hostname.match(DOMAIN_MATCH_REGEX),
|
|
1109
|
+
domain = matches ? matches[0] : '';
|
|
1110
|
+
|
|
1111
|
+
cdomain = domain ? '; domain=.' + domain : '';
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
if (days) {
|
|
1115
|
+
var date = new Date();
|
|
1116
|
+
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
|
|
1117
|
+
expires = '; expires=' + date.toGMTString();
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
if (is_secure) {
|
|
1121
|
+
secure = '; secure';
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
var new_cookie_val =
|
|
1125
|
+
name + '=' + encodeURIComponent(JSON.stringify(value)) + expires + '; path=/' + cdomain + secure;
|
|
1126
|
+
document.cookie = new_cookie_val;
|
|
1127
|
+
return new_cookie_val
|
|
1128
|
+
} catch (err) {
|
|
1129
|
+
return
|
|
1130
|
+
}
|
|
1131
|
+
},
|
|
1132
|
+
|
|
1133
|
+
remove: function (name, cross_subdomain) {
|
|
1134
|
+
try {
|
|
1135
|
+
cookieStore.set(name, '', -1, cross_subdomain);
|
|
1136
|
+
} catch (err) {
|
|
1137
|
+
return
|
|
1138
|
+
}
|
|
1139
|
+
},
|
|
1140
|
+
};
|
|
1141
|
+
|
|
1142
|
+
var _localStorage_supported = null;
|
|
1143
|
+
const localStore = {
|
|
1144
|
+
is_supported: function () {
|
|
1145
|
+
if (_localStorage_supported !== null) {
|
|
1146
|
+
return _localStorage_supported
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
var supported = true;
|
|
1150
|
+
if (window) {
|
|
1151
|
+
try {
|
|
1152
|
+
var key = '__mplssupport__',
|
|
1153
|
+
val = 'xyz';
|
|
1154
|
+
localStore.set(key, val);
|
|
1155
|
+
if (localStore.get(key) !== '"xyz"') {
|
|
1156
|
+
supported = false;
|
|
1157
|
+
}
|
|
1158
|
+
localStore.remove(key);
|
|
1159
|
+
} catch (err) {
|
|
1160
|
+
supported = false;
|
|
1161
|
+
}
|
|
1162
|
+
} else {
|
|
1163
|
+
supported = false;
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
_localStorage_supported = supported;
|
|
1167
|
+
return supported
|
|
1168
|
+
},
|
|
1169
|
+
|
|
1170
|
+
error: function (msg) {
|
|
1171
|
+
},
|
|
1172
|
+
|
|
1173
|
+
get: function (name) {
|
|
1174
|
+
try {
|
|
1175
|
+
return window.localStorage.getItem(name)
|
|
1176
|
+
} catch (err) {
|
|
1177
|
+
localStore.error(err);
|
|
1178
|
+
}
|
|
1179
|
+
return null
|
|
1180
|
+
},
|
|
1181
|
+
|
|
1182
|
+
parse: function (name) {
|
|
1183
|
+
try {
|
|
1184
|
+
return JSON.parse(localStore.get(name)) || {}
|
|
1185
|
+
} catch (err) {
|
|
1186
|
+
// noop
|
|
1187
|
+
}
|
|
1188
|
+
return null
|
|
1189
|
+
},
|
|
1190
|
+
|
|
1191
|
+
set: function (name, value) {
|
|
1192
|
+
try {
|
|
1193
|
+
window.localStorage.setItem(name, JSON.stringify(value));
|
|
1194
|
+
} catch (err) {
|
|
1195
|
+
localStore.error(err);
|
|
1196
|
+
}
|
|
1197
|
+
},
|
|
1198
|
+
|
|
1199
|
+
remove: function (name) {
|
|
1200
|
+
try {
|
|
1201
|
+
window.localStorage.removeItem(name);
|
|
1202
|
+
} catch (err) {
|
|
1203
|
+
localStore.error(err);
|
|
1204
|
+
}
|
|
1205
|
+
},
|
|
1206
|
+
};
|
|
1207
|
+
|
|
1208
|
+
// Use localstorage for most data but still use cookie for distinct_id
|
|
1209
|
+
// This solves issues with cookies having too much data in them causing headers too large
|
|
1210
|
+
// Also makes sure we don't have to send a ton of data to the server
|
|
1211
|
+
const localPlusCookieStore = {
|
|
1212
|
+
...localStore,
|
|
1213
|
+
parse: function (name) {
|
|
1214
|
+
try {
|
|
1215
|
+
let extend = {};
|
|
1216
|
+
try {
|
|
1217
|
+
// See if there's a cookie stored with data.
|
|
1218
|
+
extend = cookieStore.parse(name) || {};
|
|
1219
|
+
if (extend['distinct_id']) {
|
|
1220
|
+
cookieStore.set(name, { distinct_id: extend['distinct_id'] });
|
|
1221
|
+
}
|
|
1222
|
+
} catch (err) {}
|
|
1223
|
+
const value = _.extend(extend, JSON.parse(localStore.get(name) || '{}'));
|
|
1224
|
+
localStore.set(name, value);
|
|
1225
|
+
return value
|
|
1226
|
+
} catch (err) {
|
|
1227
|
+
// noop
|
|
1228
|
+
}
|
|
1229
|
+
return null
|
|
1230
|
+
},
|
|
1231
|
+
|
|
1232
|
+
set: function (name, value) {
|
|
1233
|
+
try {
|
|
1234
|
+
localStore.set(name, value);
|
|
1235
|
+
if (value.distinct_id) {
|
|
1236
|
+
cookieStore.set(name, { distinct_id: value.distinct_id });
|
|
1237
|
+
}
|
|
1238
|
+
} catch (err) {
|
|
1239
|
+
localStore.error(err);
|
|
1240
|
+
}
|
|
1241
|
+
},
|
|
1242
|
+
|
|
1243
|
+
remove: function (name) {
|
|
1244
|
+
try {
|
|
1245
|
+
window.localStorage.removeItem(name);
|
|
1246
|
+
cookieStore.remove(name);
|
|
1247
|
+
} catch (err) {
|
|
1248
|
+
localStore.error(err);
|
|
1249
|
+
}
|
|
1250
|
+
},
|
|
1251
|
+
};
|
|
1252
|
+
|
|
1253
|
+
const memoryStorage = {};
|
|
1254
|
+
|
|
1255
|
+
// Storage that only lasts the length of the pageview if we don't want to use cookies
|
|
1256
|
+
const memoryStore = {
|
|
1257
|
+
is_supported: function () {
|
|
1258
|
+
return true
|
|
1259
|
+
},
|
|
1260
|
+
|
|
1261
|
+
error: function (msg) {
|
|
1262
|
+
},
|
|
1263
|
+
|
|
1264
|
+
parse: function (name) {
|
|
1265
|
+
return memoryStorage[name] || null
|
|
1266
|
+
},
|
|
1267
|
+
|
|
1268
|
+
set: function (name, value) {
|
|
1269
|
+
memoryStorage[name] = value;
|
|
1270
|
+
},
|
|
1271
|
+
|
|
1272
|
+
remove: function (name) {
|
|
1273
|
+
delete memoryStorage[name];
|
|
1274
|
+
},
|
|
1275
|
+
};
|
|
1276
|
+
|
|
1277
|
+
// Storage that only lasts the length of a tab/window. Survives page refreshes
|
|
1278
|
+
const sessionStore = {
|
|
1279
|
+
sessionStorageSupported: null,
|
|
1280
|
+
is_supported: function () {
|
|
1281
|
+
if (sessionStore.sessionStorageSupported !== null) {
|
|
1282
|
+
return sessionStore.sessionStorageSupported
|
|
1283
|
+
}
|
|
1284
|
+
sessionStore.sessionStorageSupported = true;
|
|
1285
|
+
if (window) {
|
|
1286
|
+
try {
|
|
1287
|
+
let key = '__support__',
|
|
1288
|
+
val = 'xyz';
|
|
1289
|
+
sessionStore.set(key, val);
|
|
1290
|
+
if (sessionStore.get(key) !== '"xyz"') {
|
|
1291
|
+
sessionStore.sessionStorageSupported = false;
|
|
1292
|
+
}
|
|
1293
|
+
sessionStore.remove(key);
|
|
1294
|
+
} catch (err) {
|
|
1295
|
+
sessionStore.sessionStorageSupported = false;
|
|
1296
|
+
}
|
|
1297
|
+
} else {
|
|
1298
|
+
sessionStore.sessionStorageSupported = false;
|
|
1299
|
+
}
|
|
1300
|
+
return sessionStore.sessionStorageSupported
|
|
1301
|
+
},
|
|
1302
|
+
error: function (msg) {
|
|
1303
|
+
if (Config.DEBUG) ;
|
|
1304
|
+
},
|
|
1305
|
+
|
|
1306
|
+
get: function (name) {
|
|
1307
|
+
try {
|
|
1308
|
+
return window.sessionStorage.getItem(name)
|
|
1309
|
+
} catch (err) {
|
|
1310
|
+
sessionStore.error(err);
|
|
1311
|
+
}
|
|
1312
|
+
return null
|
|
1313
|
+
},
|
|
1314
|
+
|
|
1315
|
+
parse: function (name) {
|
|
1316
|
+
try {
|
|
1317
|
+
return JSON.parse(sessionStore.get(name)) || null
|
|
1318
|
+
} catch (err) {
|
|
1319
|
+
// noop
|
|
1320
|
+
}
|
|
1321
|
+
return null
|
|
1322
|
+
},
|
|
1323
|
+
|
|
1324
|
+
set: function (name, value) {
|
|
1325
|
+
try {
|
|
1326
|
+
window.sessionStorage.setItem(name, JSON.stringify(value));
|
|
1327
|
+
} catch (err) {
|
|
1328
|
+
sessionStore.error(err);
|
|
1329
|
+
}
|
|
1330
|
+
},
|
|
1331
|
+
|
|
1332
|
+
remove: function (name) {
|
|
1333
|
+
try {
|
|
1334
|
+
window.sessionStorage.removeItem(name);
|
|
1335
|
+
} catch (err) {
|
|
1336
|
+
sessionStore.error(err);
|
|
1337
|
+
}
|
|
1338
|
+
},
|
|
1339
|
+
};
|
|
1340
|
+
|
|
1341
|
+
/* eslint camelcase: "off" */
|
|
1342
|
+
|
|
1343
|
+
/*
|
|
1344
|
+
* Constants
|
|
1345
|
+
*/
|
|
1346
|
+
/** @const */ var SET_QUEUE_KEY = '__mps';
|
|
1347
|
+
/** @const */ var SET_ONCE_QUEUE_KEY = '__mpso';
|
|
1348
|
+
/** @const */ var UNSET_QUEUE_KEY = '__mpus';
|
|
1349
|
+
/** @const */ var ADD_QUEUE_KEY = '__mpa';
|
|
1350
|
+
/** @const */ var APPEND_QUEUE_KEY = '__mpap';
|
|
1351
|
+
/** @const */ var REMOVE_QUEUE_KEY = '__mpr';
|
|
1352
|
+
/** @const */ var UNION_QUEUE_KEY = '__mpu';
|
|
1353
|
+
/** @const */ var CAMPAIGN_IDS_KEY = '__cmpns';
|
|
1354
|
+
/** @const */ var EVENT_TIMERS_KEY = '__timers';
|
|
1355
|
+
/** @const */ var SESSION_RECORDING_ENABLED = '$session_recording_enabled';
|
|
1356
|
+
/** @const */ var SESSION_ID = '$sesid';
|
|
1357
|
+
/** @const */ var ENABLED_FEATURE_FLAGS = '$enabled_feature_flags';
|
|
1358
|
+
/** @const */ var RESERVED_PROPERTIES = [
|
|
1359
|
+
SET_QUEUE_KEY,
|
|
1360
|
+
SET_ONCE_QUEUE_KEY,
|
|
1361
|
+
UNSET_QUEUE_KEY,
|
|
1362
|
+
ADD_QUEUE_KEY,
|
|
1363
|
+
APPEND_QUEUE_KEY,
|
|
1364
|
+
REMOVE_QUEUE_KEY,
|
|
1365
|
+
UNION_QUEUE_KEY,
|
|
1366
|
+
CAMPAIGN_IDS_KEY,
|
|
1367
|
+
EVENT_TIMERS_KEY,
|
|
1368
|
+
SESSION_RECORDING_ENABLED,
|
|
1369
|
+
SESSION_ID,
|
|
1370
|
+
ENABLED_FEATURE_FLAGS,
|
|
1371
|
+
];
|
|
1372
|
+
|
|
1373
|
+
/**
|
|
1374
|
+
* UserMaven Persistence Object
|
|
1375
|
+
* @constructor
|
|
1376
|
+
*/
|
|
1377
|
+
var UserMavenPersistence = function (config) {
|
|
1378
|
+
// clean chars that aren't accepted by the http spec for cookie values
|
|
1379
|
+
// https://datatracker.ietf.org/doc/html/rfc2616#section-2.2
|
|
1380
|
+
let token = '';
|
|
1381
|
+
|
|
1382
|
+
if (config['token']) {
|
|
1383
|
+
token = config['token'].replace(/\+/g, 'PL').replace(/\//g, 'SL').replace(/=/g, 'EQ');
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
this['props'] = {};
|
|
1387
|
+
this.campaign_params_saved = false;
|
|
1388
|
+
|
|
1389
|
+
if (config['persistence_name']) {
|
|
1390
|
+
this.name = 'um_' + config['persistence_name'];
|
|
1391
|
+
} else {
|
|
1392
|
+
this.name = 'um_' + token + '_usermaven';
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
var storage_type = config['persistence'];
|
|
1396
|
+
if (storage_type !== 'cookie' && storage_type.indexOf('localStorage') === -1 && storage_type !== 'memory') {
|
|
1397
|
+
console$1.critical('Unknown persistence type ' + storage_type + '; falling back to cookie');
|
|
1398
|
+
storage_type = config['persistence'] = 'cookie';
|
|
1399
|
+
}
|
|
1400
|
+
if (storage_type === 'localStorage' && localStore.is_supported()) {
|
|
1401
|
+
this.storage = localStore;
|
|
1402
|
+
} else if (storage_type === 'localStorage+cookie' && localPlusCookieStore.is_supported()) {
|
|
1403
|
+
this.storage = localPlusCookieStore;
|
|
1404
|
+
} else if (storage_type === 'memory') {
|
|
1405
|
+
this.storage = memoryStore;
|
|
1406
|
+
} else {
|
|
1407
|
+
this.storage = cookieStore;
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
this.load();
|
|
1411
|
+
this.update_config(config);
|
|
1412
|
+
this.save();
|
|
1413
|
+
};
|
|
1414
|
+
|
|
1415
|
+
UserMavenPersistence.prototype.properties = function () {
|
|
1416
|
+
var p = {};
|
|
1417
|
+
// Filter out reserved properties
|
|
1418
|
+
_.each(this['props'], function (v, k) {
|
|
1419
|
+
if (k === ENABLED_FEATURE_FLAGS && typeof v === 'object') {
|
|
1420
|
+
var keys = Object.keys(v);
|
|
1421
|
+
for (var i = 0; i < keys.length; i++) {
|
|
1422
|
+
p[`$feature/${keys[i]}`] = v[keys[i]];
|
|
1423
|
+
}
|
|
1424
|
+
} else if (!_.include(RESERVED_PROPERTIES, k)) {
|
|
1425
|
+
p[k] = v;
|
|
1426
|
+
}
|
|
1427
|
+
});
|
|
1428
|
+
return p
|
|
1429
|
+
};
|
|
1430
|
+
|
|
1431
|
+
UserMavenPersistence.prototype.load = function () {
|
|
1432
|
+
if (this.disabled) {
|
|
1433
|
+
return
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
var entry = this.storage.parse(this.name);
|
|
1437
|
+
|
|
1438
|
+
if (entry) {
|
|
1439
|
+
this['props'] = _.extend({}, entry);
|
|
1440
|
+
}
|
|
1441
|
+
};
|
|
1442
|
+
|
|
1443
|
+
UserMavenPersistence.prototype.save = function () {
|
|
1444
|
+
if (this.disabled) {
|
|
1445
|
+
return
|
|
1446
|
+
}
|
|
1447
|
+
this.storage.set(this.name, this['props'], this.expire_days, this.cross_subdomain, this.secure);
|
|
1448
|
+
};
|
|
1449
|
+
|
|
1450
|
+
UserMavenPersistence.prototype.remove = function () {
|
|
1451
|
+
// remove both domain and subdomain cookies
|
|
1452
|
+
this.storage.remove(this.name, false);
|
|
1453
|
+
this.storage.remove(this.name, true);
|
|
1454
|
+
};
|
|
1455
|
+
|
|
1456
|
+
// removes the storage entry and deletes all loaded data
|
|
1457
|
+
// forced name for tests
|
|
1458
|
+
UserMavenPersistence.prototype.clear = function () {
|
|
1459
|
+
this.remove();
|
|
1460
|
+
this['props'] = {};
|
|
1461
|
+
};
|
|
1462
|
+
|
|
1463
|
+
/**
|
|
1464
|
+
* @param {Object} props
|
|
1465
|
+
* @param {*=} default_value
|
|
1466
|
+
* @param {number=} days
|
|
1467
|
+
*/
|
|
1468
|
+
UserMavenPersistence.prototype.register_once = function (props, default_value, days) {
|
|
1469
|
+
if (_.isObject(props)) {
|
|
1470
|
+
if (typeof default_value === 'undefined') {
|
|
1471
|
+
default_value = 'None';
|
|
1472
|
+
}
|
|
1473
|
+
this.expire_days = typeof days === 'undefined' ? this.default_expiry : days;
|
|
1474
|
+
|
|
1475
|
+
_.each(
|
|
1476
|
+
props,
|
|
1477
|
+
function (val, prop) {
|
|
1478
|
+
if (!this['props'].hasOwnProperty(prop) || this['props'][prop] === default_value) {
|
|
1479
|
+
this['props'][prop] = val;
|
|
1480
|
+
}
|
|
1481
|
+
},
|
|
1482
|
+
this
|
|
1483
|
+
);
|
|
1484
|
+
|
|
1485
|
+
this.save();
|
|
1486
|
+
|
|
1487
|
+
return true
|
|
1488
|
+
}
|
|
1489
|
+
return false
|
|
1490
|
+
};
|
|
1491
|
+
|
|
1492
|
+
/**
|
|
1493
|
+
* @param {Object} props
|
|
1494
|
+
* @param {number=} days
|
|
1495
|
+
*/
|
|
1496
|
+
UserMavenPersistence.prototype.register = function (props, days) {
|
|
1497
|
+
if (_.isObject(props)) {
|
|
1498
|
+
this.expire_days = typeof days === 'undefined' ? this.default_expiry : days;
|
|
1499
|
+
|
|
1500
|
+
_.extend(this['props'], props);
|
|
1501
|
+
|
|
1502
|
+
this.save();
|
|
1503
|
+
|
|
1504
|
+
return true
|
|
1505
|
+
}
|
|
1506
|
+
return false
|
|
1507
|
+
};
|
|
1508
|
+
|
|
1509
|
+
UserMavenPersistence.prototype.unregister = function (prop) {
|
|
1510
|
+
if (prop in this['props']) {
|
|
1511
|
+
delete this['props'][prop];
|
|
1512
|
+
this.save();
|
|
1513
|
+
}
|
|
1514
|
+
};
|
|
1515
|
+
|
|
1516
|
+
UserMavenPersistence.prototype.update_campaign_params = function () {
|
|
1517
|
+
if (!this.campaign_params_saved) {
|
|
1518
|
+
this.register(_.info.campaignParams());
|
|
1519
|
+
this.campaign_params_saved = true;
|
|
1520
|
+
}
|
|
1521
|
+
};
|
|
1522
|
+
|
|
1523
|
+
UserMavenPersistence.prototype.update_search_keyword = function (referrer) {
|
|
1524
|
+
this.register(_.info.searchInfo(referrer));
|
|
1525
|
+
};
|
|
1526
|
+
|
|
1527
|
+
// EXPORTED METHOD, we test this directly.
|
|
1528
|
+
UserMavenPersistence.prototype.update_referrer_info = function (referrer) {
|
|
1529
|
+
// If referrer doesn't exist, we want to note the fact that it was type-in traffic.
|
|
1530
|
+
// Register once, so first touch
|
|
1531
|
+
this.register_once(
|
|
1532
|
+
{
|
|
1533
|
+
$initial_referrer: referrer || '$direct',
|
|
1534
|
+
$initial_referring_domain: _.info.referringDomain(referrer) || '$direct',
|
|
1535
|
+
},
|
|
1536
|
+
''
|
|
1537
|
+
);
|
|
1538
|
+
// Register the current referrer but override if it's different, hence register
|
|
1539
|
+
this.register({
|
|
1540
|
+
$referrer: referrer || this['props']['$referrer'] || '$direct',
|
|
1541
|
+
$referring_domain: _.info.referringDomain(referrer) || this['props']['$referring_domain'] || '$direct',
|
|
1542
|
+
});
|
|
1543
|
+
};
|
|
1544
|
+
|
|
1545
|
+
UserMavenPersistence.prototype.get_referrer_info = function () {
|
|
1546
|
+
return _.strip_empty_properties({
|
|
1547
|
+
$initial_referrer: this['props']['$initial_referrer'],
|
|
1548
|
+
$initial_referring_domain: this['props']['$initial_referring_domain'],
|
|
1549
|
+
})
|
|
1550
|
+
};
|
|
1551
|
+
|
|
1552
|
+
// safely fills the passed in object with stored properties,
|
|
1553
|
+
// does not override any properties defined in both
|
|
1554
|
+
// returns the passed in object
|
|
1555
|
+
UserMavenPersistence.prototype.safe_merge = function (props) {
|
|
1556
|
+
_.each(this['props'], function (val, prop) {
|
|
1557
|
+
if (!(prop in props)) {
|
|
1558
|
+
props[prop] = val;
|
|
1559
|
+
}
|
|
1560
|
+
});
|
|
1561
|
+
|
|
1562
|
+
return props
|
|
1563
|
+
};
|
|
1564
|
+
|
|
1565
|
+
UserMavenPersistence.prototype.update_config = function (config) {
|
|
1566
|
+
this.default_expiry = this.expire_days = config['cookie_expiration'];
|
|
1567
|
+
this.set_disabled(config['disable_persistence']);
|
|
1568
|
+
this.set_cross_subdomain(config['cross_subdomain_cookie']);
|
|
1569
|
+
this.set_secure(config['secure_cookie']);
|
|
1570
|
+
};
|
|
1571
|
+
|
|
1572
|
+
UserMavenPersistence.prototype.set_disabled = function (disabled) {
|
|
1573
|
+
this.disabled = disabled;
|
|
1574
|
+
if (this.disabled) {
|
|
1575
|
+
this.remove();
|
|
1576
|
+
} else {
|
|
1577
|
+
this.save();
|
|
1578
|
+
}
|
|
1579
|
+
};
|
|
1580
|
+
|
|
1581
|
+
UserMavenPersistence.prototype.set_cross_subdomain = function (cross_subdomain) {
|
|
1582
|
+
if (cross_subdomain !== this.cross_subdomain) {
|
|
1583
|
+
this.cross_subdomain = cross_subdomain;
|
|
1584
|
+
this.remove();
|
|
1585
|
+
this.save();
|
|
1586
|
+
}
|
|
1587
|
+
};
|
|
1588
|
+
|
|
1589
|
+
UserMavenPersistence.prototype.get_cross_subdomain = function () {
|
|
1590
|
+
return this.cross_subdomain
|
|
1591
|
+
};
|
|
1592
|
+
|
|
1593
|
+
UserMavenPersistence.prototype.set_secure = function (secure) {
|
|
1594
|
+
if (secure !== this.secure) {
|
|
1595
|
+
this.secure = secure ? true : false;
|
|
1596
|
+
this.remove();
|
|
1597
|
+
this.save();
|
|
1598
|
+
}
|
|
1599
|
+
};
|
|
1600
|
+
|
|
1601
|
+
UserMavenPersistence.prototype.set_event_timer = function (event_name, timestamp) {
|
|
1602
|
+
var timers = this['props'][EVENT_TIMERS_KEY] || {};
|
|
1603
|
+
timers[event_name] = timestamp;
|
|
1604
|
+
this['props'][EVENT_TIMERS_KEY] = timers;
|
|
1605
|
+
this.save();
|
|
1606
|
+
};
|
|
1607
|
+
|
|
1608
|
+
UserMavenPersistence.prototype.remove_event_timer = function (event_name) {
|
|
1609
|
+
var timers = this['props'][EVENT_TIMERS_KEY] || {};
|
|
1610
|
+
var timestamp = timers[event_name];
|
|
1611
|
+
if (!_.isUndefined(timestamp)) {
|
|
1612
|
+
delete this['props'][EVENT_TIMERS_KEY][event_name];
|
|
1613
|
+
this.save();
|
|
1614
|
+
}
|
|
1615
|
+
return timestamp
|
|
1616
|
+
};
|
|
1617
|
+
|
|
1618
|
+
// import { INCREMENTAL_SNAPSHOT_EVENT_TYPE, MUTATION_SOURCE_TYPE } from './extensions/sessionrecording'
|
|
1619
|
+
|
|
1620
|
+
const SESSION_CHANGE_THRESHOLD = 30 * 60 * 1000; // 30 mins
|
|
1621
|
+
/* const SESSION_CHANGE_THRESHOLD = 1 * 60 * 1000 // 1 min */
|
|
1622
|
+
|
|
1623
|
+
class SessionIdManager {
|
|
1624
|
+
constructor(config, persistence) {
|
|
1625
|
+
this.persistence = persistence;
|
|
1626
|
+
|
|
1627
|
+
if (config['persistence_name']) {
|
|
1628
|
+
this.window_id_storage_key = 'um_' + config['persistence_name'] + '_window_id';
|
|
1629
|
+
} else {
|
|
1630
|
+
this.window_id_storage_key = 'um_' + config['token'] + '_window_id';
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
// Note: this tries to store the windowId in sessionStorage. SessionStorage is unique to the current window/tab,
|
|
1635
|
+
// and persists page loads/reloads. So it's uniquely suited for storing the windowId. This function also respects
|
|
1636
|
+
// when persistence is disabled (by user config) and when sessionStorage is not supported (it *should* be supported on all browsers),
|
|
1637
|
+
// and in that case, it falls back to memory (which sadly, won't persist page loads)
|
|
1638
|
+
_setWindowId(windowId) {
|
|
1639
|
+
if (windowId !== this.windowId) {
|
|
1640
|
+
this.windowId = windowId;
|
|
1641
|
+
if (!this.persistence.disabled && sessionStore.is_supported()) {
|
|
1642
|
+
sessionStore.set(this.window_id_storage_key, windowId);
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
_getWindowId() {
|
|
1648
|
+
if (this.windowId) {
|
|
1649
|
+
return this.windowId
|
|
1650
|
+
}
|
|
1651
|
+
if (!this.persistence.disabled && sessionStore.is_supported()) {
|
|
1652
|
+
return sessionStore.parse(this.window_id_storage_key)
|
|
1653
|
+
}
|
|
1654
|
+
return null
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
// Note: 'this.persistence.register' can be disabled in the config.
|
|
1658
|
+
// In that case, this works by storing sessionId and the timestamp in memory.
|
|
1659
|
+
_setSessionId(sessionId, timestamp) {
|
|
1660
|
+
if (sessionId !== this.sessionId || timestamp !== this.timestamp) {
|
|
1661
|
+
this.timestamp = timestamp;
|
|
1662
|
+
this.sessionId = sessionId;
|
|
1663
|
+
this.persistence.register({ [SESSION_ID]: [timestamp, sessionId] });
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
_getSessionId() {
|
|
1668
|
+
if (this.sessionId && this.timestamp) {
|
|
1669
|
+
return [this.timestamp, this.sessionId]
|
|
1670
|
+
}
|
|
1671
|
+
return this.persistence['props'][SESSION_ID] || [0, null]
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1674
|
+
// Resets the session id by setting it to null. On the subsequent call to getSessionAndWindowId,
|
|
1675
|
+
// new ids will be generated.
|
|
1676
|
+
resetSessionId() {
|
|
1677
|
+
this._setSessionId(null, null);
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
getSessionAndWindowId(timestamp = null, recordingEvent = false) {
|
|
1681
|
+
// Some recording events are triggered by non-user events (e.g. "X minutes ago" text updating on the screen).
|
|
1682
|
+
// We don't want to update the session and window ids in these cases. These events are designated by event
|
|
1683
|
+
// type -> incremental update, and source -> mutation.
|
|
1684
|
+
/* const isUserInteraction = !(
|
|
1685
|
+
recordingEvent &&
|
|
1686
|
+
recordingEvent.type === INCREMENTAL_SNAPSHOT_EVENT_TYPE &&
|
|
1687
|
+
recordingEvent.data?.source === MUTATION_SOURCE_TYPE
|
|
1688
|
+
) */
|
|
1689
|
+
|
|
1690
|
+
const isUserInteraction = true;
|
|
1691
|
+
|
|
1692
|
+
timestamp = timestamp || new Date().getTime();
|
|
1693
|
+
|
|
1694
|
+
let [lastTimestamp, sessionId] = this._getSessionId();
|
|
1695
|
+
let windowId = this._getWindowId();
|
|
1696
|
+
|
|
1697
|
+
if (!sessionId || (Math.abs(timestamp - lastTimestamp) > SESSION_CHANGE_THRESHOLD)) {
|
|
1698
|
+
sessionId = _.UUID();
|
|
1699
|
+
windowId = _.UUID();
|
|
1700
|
+
} else if (!windowId) {
|
|
1701
|
+
windowId = _.UUID();
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
const newTimestamp = lastTimestamp === 0 || isUserInteraction ? timestamp : lastTimestamp;
|
|
1705
|
+
|
|
1706
|
+
this._setWindowId(windowId);
|
|
1707
|
+
this._setSessionId(sessionId, newTimestamp);
|
|
1708
|
+
|
|
1709
|
+
return {
|
|
1710
|
+
sessionId: sessionId,
|
|
1711
|
+
windowId: windowId,
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
|
|
220
1716
|
var VERSION_INFO = {
|
|
221
1717
|
env: 'production',
|
|
222
|
-
date: '2022-
|
|
223
|
-
version: '1.0.
|
|
1718
|
+
date: '2022-02-18T12:44:44.465Z',
|
|
1719
|
+
version: '1.0.4'
|
|
224
1720
|
};
|
|
225
1721
|
var USERMAVEN_VERSION = "".concat(VERSION_INFO.version, "/").concat(VERSION_INFO.env, "@").concat(VERSION_INFO.date);
|
|
226
1722
|
var beaconTransport = function (url, json) {
|
|
@@ -397,7 +1893,17 @@ var UsermavenClientImpl = /** @class */ (function () {
|
|
|
397
1893
|
};
|
|
398
1894
|
UsermavenClientImpl.prototype.getCtx = function () {
|
|
399
1895
|
var now = new Date();
|
|
400
|
-
|
|
1896
|
+
var _a = this.sessionManager.getSessionAndWindowId(), sessionId = _a.sessionId, windowId = _a.windowId;
|
|
1897
|
+
// extract company details from identity payload
|
|
1898
|
+
var user = __assign({ anonymous_id: this.anonymousId }, this.userProperties);
|
|
1899
|
+
var company = user['company'] || {};
|
|
1900
|
+
delete user['company'];
|
|
1901
|
+
var payload = __assign({ event_id: '', session_id: sessionId, window_id: windowId, user: user, ids: this._getIds(), user_agent: navigator.userAgent, utc_time: reformatDate(now.toISOString()), local_tz_offset: now.getTimezoneOffset(), referer: document.referrer, url: window.location.href, page_title: document.title, doc_path: document.location.pathname, doc_host: document.location.hostname, doc_search: window.location.search, screen_resolution: screen.width + 'x' + screen.height, vp_size: Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0) + 'x' + Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0), user_language: navigator.language, doc_encoding: document.characterSet }, getDataFromParams(parseQuery()));
|
|
1902
|
+
// id and name attributes will be checked on backend
|
|
1903
|
+
if (Object.keys(company).length) {
|
|
1904
|
+
payload['company'] = company;
|
|
1905
|
+
}
|
|
1906
|
+
return payload;
|
|
401
1907
|
};
|
|
402
1908
|
UsermavenClientImpl.prototype._getIds = function () {
|
|
403
1909
|
var cookies = getCookies(false);
|
|
@@ -417,7 +1923,7 @@ var UsermavenClientImpl = /** @class */ (function () {
|
|
|
417
1923
|
getLogger().debug('track event of type', type, data);
|
|
418
1924
|
var e = this.makeEvent(type, this.compatMode ?
|
|
419
1925
|
'eventn' :
|
|
420
|
-
'
|
|
1926
|
+
'usermaven', payload || {});
|
|
421
1927
|
return this.sendJson(e);
|
|
422
1928
|
};
|
|
423
1929
|
UsermavenClientImpl.prototype.init = function (options) {
|
|
@@ -478,6 +1984,7 @@ var UsermavenClientImpl = /** @class */ (function () {
|
|
|
478
1984
|
}
|
|
479
1985
|
getLogger().debug('Restored persistent properties', this.permanentProperties);
|
|
480
1986
|
}
|
|
1987
|
+
this.manageSession(options);
|
|
481
1988
|
if (options.capture_3rd_party_cookies === false) {
|
|
482
1989
|
this._3pCookies = {};
|
|
483
1990
|
}
|
|
@@ -570,6 +2077,29 @@ var UsermavenClientImpl = /** @class */ (function () {
|
|
|
570
2077
|
if (this.propsPersistance && persist) {
|
|
571
2078
|
this.propsPersistance.save(this.permanentProperties);
|
|
572
2079
|
}
|
|
2080
|
+
if (this.sessionManager) {
|
|
2081
|
+
this.sessionManager.resetSessionId();
|
|
2082
|
+
}
|
|
2083
|
+
};
|
|
2084
|
+
/**
|
|
2085
|
+
* Manage session capability
|
|
2086
|
+
* @param options
|
|
2087
|
+
*/
|
|
2088
|
+
UsermavenClientImpl.prototype.manageSession = function (options) {
|
|
2089
|
+
getLogger().debug('Options', options);
|
|
2090
|
+
var defaultConfig = {
|
|
2091
|
+
persistence: options ? options.persistence || 'cookie' : 'cookie',
|
|
2092
|
+
persistence_name: options ? options.persistence_name || 'session' : 'session',
|
|
2093
|
+
};
|
|
2094
|
+
// TODO: Default session name would be session_
|
|
2095
|
+
this.config = _.extend(defaultConfig, this.config || {}, {
|
|
2096
|
+
token: this.apiKey,
|
|
2097
|
+
});
|
|
2098
|
+
getLogger().debug('Default Configuration', this.config);
|
|
2099
|
+
this.persistence = new UserMavenPersistence(this.config);
|
|
2100
|
+
getLogger().debug('Persistence Configuration', this.persistence);
|
|
2101
|
+
this.sessionManager = new SessionIdManager(this.config, this.persistence);
|
|
2102
|
+
getLogger().debug('Session Configuration', this.sessionManager);
|
|
573
2103
|
};
|
|
574
2104
|
return UsermavenClientImpl;
|
|
575
2105
|
}());
|