@usermaven/sdk-js 1.0.8 → 1.1.1
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/README.md +1 -2
- package/dist/npm/usermaven.cjs.js +584 -1804
- package/dist/npm/usermaven.d.ts +72 -28
- package/dist/npm/usermaven.es.js +584 -1804
- package/dist/web/lib.js +1 -1
- package/package.json +1 -1
package/dist/npm/usermaven.es.js
CHANGED
|
@@ -411,1500 +411,291 @@ var getHostWithProtocol = function (host) {
|
|
|
411
411
|
}
|
|
412
412
|
};
|
|
413
413
|
|
|
414
|
-
var
|
|
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
|
-
}
|
|
414
|
+
var MemoryQueue = /** @class */ (function () {
|
|
415
|
+
function MemoryQueue() {
|
|
416
|
+
this.queue = [];
|
|
417
|
+
}
|
|
418
|
+
MemoryQueue.prototype.flush = function () {
|
|
419
|
+
var queue = this.queue;
|
|
420
|
+
this.queue = [];
|
|
421
|
+
return queue;
|
|
422
|
+
};
|
|
423
|
+
MemoryQueue.prototype.push = function () {
|
|
424
|
+
var _a;
|
|
425
|
+
var values = [];
|
|
426
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
427
|
+
values[_i] = arguments[_i];
|
|
428
|
+
}
|
|
429
|
+
(_a = this.queue).push.apply(_a, values);
|
|
430
|
+
};
|
|
431
|
+
return MemoryQueue;
|
|
432
|
+
}());
|
|
433
|
+
var LocalStorageQueue = /** @class */ (function () {
|
|
434
|
+
function LocalStorageQueue(key) {
|
|
435
|
+
this.key = key;
|
|
436
|
+
}
|
|
437
|
+
LocalStorageQueue.prototype.flush = function () {
|
|
438
|
+
var queue = this.get();
|
|
439
|
+
if (queue.length) {
|
|
440
|
+
this.set([]);
|
|
441
|
+
}
|
|
442
|
+
return queue;
|
|
443
|
+
};
|
|
444
|
+
LocalStorageQueue.prototype.push = function () {
|
|
445
|
+
var values = [];
|
|
446
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
447
|
+
values[_i] = arguments[_i];
|
|
448
|
+
}
|
|
449
|
+
var queue = this.get();
|
|
450
|
+
queue.push.apply(queue, values);
|
|
451
|
+
this.set(queue);
|
|
452
|
+
};
|
|
453
|
+
LocalStorageQueue.prototype.set = function (queue) {
|
|
454
|
+
localStorage.setItem(this.key, JSON.stringify(queue));
|
|
455
|
+
};
|
|
456
|
+
LocalStorageQueue.prototype.get = function () {
|
|
457
|
+
var data = localStorage.getItem(this.key);
|
|
458
|
+
if (data !== null && data !== "") {
|
|
459
|
+
return JSON.parse(data);
|
|
460
|
+
}
|
|
461
|
+
return [];
|
|
462
|
+
};
|
|
463
|
+
return LocalStorageQueue;
|
|
464
|
+
}());
|
|
449
465
|
|
|
450
|
-
|
|
451
|
-
var
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
466
|
+
var ObjProto = Object.prototype;
|
|
467
|
+
var toString = ObjProto.toString;
|
|
468
|
+
var hasOwnProperty = ObjProto.hasOwnProperty;
|
|
469
|
+
var ArrayProto = Array.prototype;
|
|
470
|
+
var nativeForEach = ArrayProto.forEach, nativeIsArray = Array.isArray, breaker = {};
|
|
471
|
+
var _isArray = nativeIsArray ||
|
|
472
|
+
function (obj) {
|
|
473
|
+
return toString.call(obj) === '[object Array]';
|
|
474
|
+
};
|
|
475
|
+
function _eachArray(obj, iterator, thisArg) {
|
|
476
|
+
if (Array.isArray(obj)) {
|
|
477
|
+
if (nativeForEach && obj.forEach === nativeForEach) {
|
|
478
|
+
obj.forEach(iterator, thisArg);
|
|
479
|
+
}
|
|
480
|
+
else if ('length' in obj && obj.length === +obj.length) {
|
|
481
|
+
for (var i = 0, l = obj.length; i < l; i++) {
|
|
482
|
+
if (i in obj && iterator.call(thisArg, obj[i], i) === breaker) {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
468
485
|
}
|
|
469
486
|
}
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
// UNDERSCORE
|
|
487
|
+
}
|
|
488
|
+
}
|
|
474
489
|
// Embed part of the Underscore Library
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
if (nativeBind && func.bind === nativeBind) {
|
|
478
|
-
return nativeBind.apply(func, slice.call(arguments, 1))
|
|
479
|
-
}
|
|
480
|
-
if (!_.isFunction(func)) {
|
|
481
|
-
throw new TypeError()
|
|
482
|
-
}
|
|
483
|
-
args = slice.call(arguments, 2);
|
|
484
|
-
bound = function () {
|
|
485
|
-
if (!(this instanceof bound)) {
|
|
486
|
-
return func.apply(context, args.concat(slice.call(arguments)))
|
|
487
|
-
}
|
|
488
|
-
var ctor = {};
|
|
489
|
-
ctor.prototype = func.prototype;
|
|
490
|
-
var self = new ctor();
|
|
491
|
-
ctor.prototype = null;
|
|
492
|
-
var result = func.apply(self, args.concat(slice.call(arguments)));
|
|
493
|
-
if (Object(result) === result) {
|
|
494
|
-
return result
|
|
495
|
-
}
|
|
496
|
-
return self
|
|
497
|
-
};
|
|
498
|
-
return bound
|
|
490
|
+
var _trim = function (str) {
|
|
491
|
+
return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
|
|
499
492
|
};
|
|
500
|
-
|
|
501
|
-
_.bind_instance_methods = function (obj) {
|
|
493
|
+
var _bind_instance_methods = function (obj) {
|
|
502
494
|
for (var func in obj) {
|
|
503
495
|
if (typeof obj[func] === 'function') {
|
|
504
|
-
obj[func] =
|
|
496
|
+
obj[func] = obj[func].bind(obj);
|
|
505
497
|
}
|
|
506
498
|
}
|
|
507
499
|
};
|
|
508
|
-
|
|
509
500
|
/**
|
|
510
501
|
* @param {*=} obj
|
|
511
502
|
* @param {function(...*)=} iterator
|
|
512
|
-
* @param {Object=}
|
|
503
|
+
* @param {Object=} thisArg
|
|
513
504
|
*/
|
|
514
|
-
|
|
505
|
+
function _each(obj, iterator, thisArg) {
|
|
515
506
|
if (obj === null || obj === undefined) {
|
|
516
|
-
return
|
|
507
|
+
return;
|
|
517
508
|
}
|
|
518
|
-
if (nativeForEach && obj.forEach === nativeForEach) {
|
|
519
|
-
obj.forEach(iterator,
|
|
520
|
-
}
|
|
509
|
+
if (nativeForEach && Array.isArray(obj) && obj.forEach === nativeForEach) {
|
|
510
|
+
obj.forEach(iterator, thisArg);
|
|
511
|
+
}
|
|
512
|
+
else if ('length' in obj && obj.length === +obj.length) {
|
|
521
513
|
for (var i = 0, l = obj.length; i < l; i++) {
|
|
522
|
-
if (i in obj && iterator.call(
|
|
523
|
-
return
|
|
514
|
+
if (i in obj && iterator.call(thisArg, obj[i], i) === breaker) {
|
|
515
|
+
return;
|
|
524
516
|
}
|
|
525
517
|
}
|
|
526
|
-
}
|
|
518
|
+
}
|
|
519
|
+
else {
|
|
527
520
|
for (var key in obj) {
|
|
528
521
|
if (hasOwnProperty.call(obj, key)) {
|
|
529
|
-
if (iterator.call(
|
|
530
|
-
return
|
|
522
|
+
if (iterator.call(thisArg, obj[key], key) === breaker) {
|
|
523
|
+
return;
|
|
531
524
|
}
|
|
532
525
|
}
|
|
533
526
|
}
|
|
534
527
|
}
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
528
|
+
}
|
|
529
|
+
var _extend = function (obj) {
|
|
530
|
+
var args = [];
|
|
531
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
532
|
+
args[_i - 1] = arguments[_i];
|
|
533
|
+
}
|
|
534
|
+
_eachArray(args, function (source) {
|
|
539
535
|
for (var prop in source) {
|
|
540
536
|
if (source[prop] !== void 0) {
|
|
541
537
|
obj[prop] = source[prop];
|
|
542
538
|
}
|
|
543
539
|
}
|
|
544
540
|
});
|
|
545
|
-
return obj
|
|
541
|
+
return obj;
|
|
546
542
|
};
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
function (obj) {
|
|
551
|
-
return toString.call(obj) === '[object Array]'
|
|
552
|
-
};
|
|
553
|
-
|
|
543
|
+
function _includes(str, needle) {
|
|
544
|
+
return str.indexOf(needle) !== -1;
|
|
545
|
+
}
|
|
554
546
|
// from a comment on http://dbj.org/dbj/?p=286
|
|
555
547
|
// fails on only one very rare and deliberate custom object:
|
|
556
|
-
//
|
|
557
|
-
|
|
548
|
+
// let bomb = { toString : undefined, valueOf: function(o) { return "function BOMBA!"; }};
|
|
549
|
+
var _isFunction = function (f) {
|
|
558
550
|
try {
|
|
559
|
-
return /^\s*\bfunction\b/.test(f)
|
|
560
|
-
} catch (x) {
|
|
561
|
-
return false
|
|
562
|
-
}
|
|
563
|
-
};
|
|
564
|
-
|
|
565
|
-
_.include = function (obj, target) {
|
|
566
|
-
var found = false;
|
|
567
|
-
if (obj === null) {
|
|
568
|
-
return found
|
|
551
|
+
return /^\s*\bfunction\b/.test(f);
|
|
569
552
|
}
|
|
570
|
-
|
|
571
|
-
return
|
|
553
|
+
catch (x) {
|
|
554
|
+
return false;
|
|
572
555
|
}
|
|
573
|
-
_.each(obj, function (value) {
|
|
574
|
-
if (found || (found = value === target)) {
|
|
575
|
-
return breaker
|
|
576
|
-
}
|
|
577
|
-
});
|
|
578
|
-
return found
|
|
579
556
|
};
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
return str.indexOf(needle) !== -1
|
|
557
|
+
var _isUndefined = function (obj) {
|
|
558
|
+
return obj === void 0;
|
|
583
559
|
};
|
|
584
|
-
|
|
585
|
-
// Underscore Addons
|
|
586
|
-
_.isObject = function (obj) {
|
|
587
|
-
return obj === Object(obj) && !_.isArray(obj)
|
|
588
|
-
};
|
|
589
|
-
|
|
590
|
-
_.isEmptyObject = function (obj) {
|
|
591
|
-
if (_.isObject(obj)) {
|
|
592
|
-
for (var key in obj) {
|
|
593
|
-
if (hasOwnProperty.call(obj, key)) {
|
|
594
|
-
return false
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
return true
|
|
598
|
-
}
|
|
599
|
-
return false
|
|
600
|
-
};
|
|
601
|
-
|
|
602
|
-
_.isUndefined = function (obj) {
|
|
603
|
-
return obj === void 0
|
|
604
|
-
};
|
|
605
|
-
|
|
606
|
-
_.isString = function (obj) {
|
|
607
|
-
return toString.call(obj) == '[object String]'
|
|
608
|
-
};
|
|
609
|
-
|
|
610
|
-
_.isDate = function (obj) {
|
|
611
|
-
return toString.call(obj) == '[object Date]'
|
|
612
|
-
};
|
|
613
|
-
|
|
614
|
-
_.isNumber = function (obj) {
|
|
615
|
-
return toString.call(obj) == '[object Number]'
|
|
616
|
-
};
|
|
617
|
-
|
|
618
|
-
_.encodeDates = function (obj) {
|
|
619
|
-
_.each(obj, function (v, k) {
|
|
620
|
-
if (_.isDate(v)) {
|
|
621
|
-
obj[k] = _.formatDate(v);
|
|
622
|
-
} else if (_.isObject(v)) {
|
|
623
|
-
obj[k] = _.encodeDates(v); // recurse
|
|
624
|
-
}
|
|
625
|
-
});
|
|
626
|
-
return obj
|
|
627
|
-
};
|
|
628
|
-
|
|
629
|
-
_.timestamp = function () {
|
|
630
|
-
Date.now =
|
|
631
|
-
Date.now ||
|
|
632
|
-
function () {
|
|
633
|
-
return +new Date()
|
|
634
|
-
};
|
|
635
|
-
return Date.now()
|
|
636
|
-
};
|
|
637
|
-
|
|
638
|
-
_.formatDate = function (d) {
|
|
639
|
-
// YYYY-MM-DDTHH:MM:SS in UTC
|
|
640
|
-
function pad(n) {
|
|
641
|
-
return n < 10 ? '0' + n : n
|
|
642
|
-
}
|
|
643
|
-
return (
|
|
644
|
-
d.getUTCFullYear() +
|
|
645
|
-
'-' +
|
|
646
|
-
pad(d.getUTCMonth() + 1) +
|
|
647
|
-
'-' +
|
|
648
|
-
pad(d.getUTCDate()) +
|
|
649
|
-
'T' +
|
|
650
|
-
pad(d.getUTCHours()) +
|
|
651
|
-
':' +
|
|
652
|
-
pad(d.getUTCMinutes()) +
|
|
653
|
-
':' +
|
|
654
|
-
pad(d.getUTCSeconds())
|
|
655
|
-
)
|
|
656
|
-
};
|
|
657
|
-
|
|
658
|
-
_.safewrap = function (f) {
|
|
659
|
-
return function () {
|
|
660
|
-
try {
|
|
661
|
-
return f.apply(this, arguments)
|
|
662
|
-
} catch (e) {
|
|
663
|
-
console$1.critical('Implementation error. Please turn on debug and contact support@usermaven.com.');
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
};
|
|
667
|
-
|
|
668
|
-
_.safewrap_class = function (klass, functions) {
|
|
669
|
-
for (var i = 0; i < functions.length; i++) {
|
|
670
|
-
klass.prototype[functions[i]] = _.safewrap(klass.prototype[functions[i]]);
|
|
671
|
-
}
|
|
672
|
-
};
|
|
673
|
-
|
|
674
|
-
_.safewrap_instance_methods = function (obj) {
|
|
675
|
-
for (var func in obj) {
|
|
676
|
-
if (typeof obj[func] === 'function') {
|
|
677
|
-
obj[func] = _.safewrap(obj[func]);
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
};
|
|
681
|
-
|
|
682
|
-
_.strip_empty_properties = function (p) {
|
|
683
|
-
var ret = {};
|
|
684
|
-
_.each(p, function (v, k) {
|
|
685
|
-
if (_.isString(v) && v.length > 0) {
|
|
686
|
-
ret[k] = v;
|
|
687
|
-
}
|
|
688
|
-
});
|
|
689
|
-
return ret
|
|
690
|
-
};
|
|
691
|
-
|
|
692
|
-
// Deep copies an object.
|
|
693
|
-
// It handles cycles by replacing all references to them with `undefined`
|
|
694
|
-
// Also supports customizing native values
|
|
695
|
-
const COPY_IN_PROGRESS_ATTRIBUTE =
|
|
696
|
-
typeof Symbol !== 'undefined' ? Symbol('__deepCircularCopyInProgress__') : '__deepCircularCopyInProgress__';
|
|
697
|
-
|
|
698
|
-
function deepCircularCopy(value, customizer) {
|
|
699
|
-
if (value !== Object(value)) return customizer ? customizer(value) : value // primitive value
|
|
700
|
-
|
|
701
|
-
if (value[COPY_IN_PROGRESS_ATTRIBUTE]) return undefined
|
|
702
|
-
|
|
703
|
-
value[COPY_IN_PROGRESS_ATTRIBUTE] = true;
|
|
704
|
-
let result;
|
|
705
|
-
|
|
706
|
-
if (_.isArray(value)) {
|
|
707
|
-
result = [];
|
|
708
|
-
_.each(value, (it) => {
|
|
709
|
-
result.push(deepCircularCopy(it, customizer));
|
|
710
|
-
});
|
|
711
|
-
} else {
|
|
712
|
-
result = {};
|
|
713
|
-
_.each(value, (val, key) => {
|
|
714
|
-
if (key !== COPY_IN_PROGRESS_ATTRIBUTE) {
|
|
715
|
-
result[key] = deepCircularCopy(val, customizer);
|
|
716
|
-
}
|
|
717
|
-
});
|
|
718
|
-
}
|
|
719
|
-
delete value[COPY_IN_PROGRESS_ATTRIBUTE];
|
|
720
|
-
return result
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
_.copyAndTruncateStrings = (object, maxStringLength) =>
|
|
724
|
-
deepCircularCopy(
|
|
725
|
-
object,
|
|
726
|
-
(value) => {
|
|
727
|
-
if (typeof value === 'string' && maxStringLength !== null) {
|
|
728
|
-
value = value.slice(0, maxStringLength);
|
|
729
|
-
}
|
|
730
|
-
return value
|
|
731
|
-
});
|
|
732
|
-
|
|
733
|
-
_.base64Encode = function (data) {
|
|
734
|
-
var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
735
|
-
var o1,
|
|
736
|
-
o2,
|
|
737
|
-
o3,
|
|
738
|
-
h1,
|
|
739
|
-
h2,
|
|
740
|
-
h3,
|
|
741
|
-
h4,
|
|
742
|
-
bits,
|
|
743
|
-
i = 0,
|
|
744
|
-
ac = 0,
|
|
745
|
-
enc = '',
|
|
746
|
-
tmp_arr = [];
|
|
747
|
-
|
|
748
|
-
if (!data) {
|
|
749
|
-
return data
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
data = _.utf8Encode(data);
|
|
753
|
-
|
|
754
|
-
do {
|
|
755
|
-
// pack three octets into four hexets
|
|
756
|
-
o1 = data.charCodeAt(i++);
|
|
757
|
-
o2 = data.charCodeAt(i++);
|
|
758
|
-
o3 = data.charCodeAt(i++);
|
|
759
|
-
|
|
760
|
-
bits = (o1 << 16) | (o2 << 8) | o3;
|
|
761
|
-
|
|
762
|
-
h1 = (bits >> 18) & 0x3f;
|
|
763
|
-
h2 = (bits >> 12) & 0x3f;
|
|
764
|
-
h3 = (bits >> 6) & 0x3f;
|
|
765
|
-
h4 = bits & 0x3f;
|
|
766
|
-
|
|
767
|
-
// use hexets to index into b64, and append result to encoded string
|
|
768
|
-
tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
|
|
769
|
-
} while (i < data.length)
|
|
770
|
-
|
|
771
|
-
enc = tmp_arr.join('');
|
|
772
|
-
|
|
773
|
-
switch (data.length % 3) {
|
|
774
|
-
case 1:
|
|
775
|
-
enc = enc.slice(0, -2) + '==';
|
|
776
|
-
break
|
|
777
|
-
case 2:
|
|
778
|
-
enc = enc.slice(0, -1) + '=';
|
|
779
|
-
break
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
return enc
|
|
783
|
-
};
|
|
784
|
-
|
|
785
|
-
_.utf8Encode = function (string) {
|
|
786
|
-
string = (string + '').replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
787
|
-
|
|
788
|
-
var utftext = '',
|
|
789
|
-
start,
|
|
790
|
-
end;
|
|
791
|
-
var stringl = 0,
|
|
792
|
-
n;
|
|
793
|
-
|
|
794
|
-
start = end = 0;
|
|
795
|
-
stringl = string.length;
|
|
796
|
-
|
|
797
|
-
for (n = 0; n < stringl; n++) {
|
|
798
|
-
var c1 = string.charCodeAt(n);
|
|
799
|
-
var enc = null;
|
|
800
|
-
|
|
801
|
-
if (c1 < 128) {
|
|
802
|
-
end++;
|
|
803
|
-
} else if (c1 > 127 && c1 < 2048) {
|
|
804
|
-
enc = String.fromCharCode((c1 >> 6) | 192, (c1 & 63) | 128);
|
|
805
|
-
} else {
|
|
806
|
-
enc = String.fromCharCode((c1 >> 12) | 224, ((c1 >> 6) & 63) | 128, (c1 & 63) | 128);
|
|
807
|
-
}
|
|
808
|
-
if (enc !== null) {
|
|
809
|
-
if (end > start) {
|
|
810
|
-
utftext += string.substring(start, end);
|
|
811
|
-
}
|
|
812
|
-
utftext += enc;
|
|
813
|
-
start = end = n + 1;
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
if (end > start) {
|
|
818
|
-
utftext += string.substring(start, string.length);
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
return utftext
|
|
822
|
-
};
|
|
823
|
-
|
|
824
|
-
_.UUID = (function () {
|
|
825
|
-
// Time/ticks information
|
|
826
|
-
// 1*new Date() is a cross browser version of Date.now()
|
|
827
|
-
var T = function () {
|
|
828
|
-
var d = 1 * new Date(),
|
|
829
|
-
i = 0;
|
|
830
|
-
|
|
831
|
-
// this while loop figures how many browser ticks go by
|
|
832
|
-
// before 1*new Date() returns a new number, ie the amount
|
|
833
|
-
// of ticks that go by per millisecond
|
|
834
|
-
while (d == 1 * new Date()) {
|
|
835
|
-
i++;
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
return d.toString(16) + i.toString(16)
|
|
839
|
-
};
|
|
840
|
-
|
|
841
|
-
// Math.Random entropy
|
|
842
|
-
var R = function () {
|
|
843
|
-
return Math.random().toString(16).replace('.', '')
|
|
844
|
-
};
|
|
845
|
-
|
|
846
|
-
// User agent entropy
|
|
847
|
-
// This function takes the user agent string, and then xors
|
|
848
|
-
// together each sequence of 8 bytes. This produces a final
|
|
849
|
-
// sequence of 8 bytes which it returns as hex.
|
|
850
|
-
var UA = function () {
|
|
851
|
-
var ua = userAgent,
|
|
852
|
-
i,
|
|
853
|
-
ch,
|
|
854
|
-
buffer = [],
|
|
855
|
-
ret = 0;
|
|
856
|
-
|
|
857
|
-
function xor(result, byte_array) {
|
|
858
|
-
var j,
|
|
859
|
-
tmp = 0;
|
|
860
|
-
for (j = 0; j < byte_array.length; j++) {
|
|
861
|
-
tmp |= buffer[j] << (j * 8);
|
|
862
|
-
}
|
|
863
|
-
return result ^ tmp
|
|
864
|
-
}
|
|
865
|
-
|
|
866
|
-
for (i = 0; i < ua.length; i++) {
|
|
867
|
-
ch = ua.charCodeAt(i);
|
|
868
|
-
buffer.unshift(ch & 0xff);
|
|
869
|
-
if (buffer.length >= 4) {
|
|
870
|
-
ret = xor(ret, buffer);
|
|
871
|
-
buffer = [];
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
if (buffer.length > 0) {
|
|
876
|
-
ret = xor(ret, buffer);
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
return ret.toString(16)
|
|
880
|
-
};
|
|
881
|
-
|
|
882
|
-
return function () {
|
|
883
|
-
var se = (window.screen.height * window.screen.width).toString(16);
|
|
884
|
-
return T() + '-' + R() + '-' + UA() + '-' + se + '-' + T()
|
|
885
|
-
}
|
|
886
|
-
})();
|
|
887
|
-
|
|
888
|
-
// _.isBlockedUA()
|
|
889
|
-
// This is to block various web spiders from executing our JS and
|
|
890
|
-
// sending false captureing data
|
|
891
|
-
_.isBlockedUA = function (ua) {
|
|
892
|
-
if (/(google web preview|baiduspider|yandexbot|bingbot|googlebot|yahoo! slurp)/i.test(ua)) {
|
|
893
|
-
return true
|
|
894
|
-
}
|
|
895
|
-
return false
|
|
896
|
-
};
|
|
897
|
-
|
|
898
|
-
/**
|
|
899
|
-
* @param {Object=} formdata
|
|
900
|
-
* @param {string=} arg_separator
|
|
901
|
-
*/
|
|
902
|
-
_.HTTPBuildQuery = function (formdata, arg_separator) {
|
|
903
|
-
var use_val,
|
|
904
|
-
use_key,
|
|
905
|
-
tph_arr = [];
|
|
906
|
-
|
|
907
|
-
if (_.isUndefined(arg_separator)) {
|
|
908
|
-
arg_separator = '&';
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
_.each(formdata, function (val, key) {
|
|
912
|
-
use_val = encodeURIComponent(val.toString());
|
|
913
|
-
use_key = encodeURIComponent(key);
|
|
914
|
-
tph_arr[tph_arr.length] = use_key + '=' + use_val;
|
|
915
|
-
});
|
|
916
|
-
|
|
917
|
-
return tph_arr.join(arg_separator)
|
|
918
|
-
};
|
|
919
|
-
|
|
920
|
-
_.getQueryParam = function (url, param) {
|
|
921
|
-
// Expects a raw URL
|
|
922
|
-
|
|
923
|
-
param = param.replace(/[[]/, '\\[').replace(/[\]]/, '\\]');
|
|
924
|
-
var regexS = '[\\?&]' + param + '=([^&#]*)',
|
|
925
|
-
regex = new RegExp(regexS),
|
|
926
|
-
results = regex.exec(url);
|
|
927
|
-
if (results === null || (results && typeof results[1] !== 'string' && results[1].length)) {
|
|
928
|
-
return ''
|
|
929
|
-
} else {
|
|
930
|
-
var result = results[1];
|
|
931
|
-
try {
|
|
932
|
-
result = decodeURIComponent(result);
|
|
933
|
-
} catch (err) {
|
|
934
|
-
}
|
|
935
|
-
return result.replace(/\+/g, ' ')
|
|
936
|
-
}
|
|
937
|
-
};
|
|
938
|
-
|
|
939
|
-
_.getHashParam = function (hash, param) {
|
|
940
|
-
var matches = hash.match(new RegExp(param + '=([^&]*)'));
|
|
941
|
-
return matches ? matches[1] : null
|
|
942
|
-
};
|
|
943
|
-
|
|
944
|
-
_.register_event = (function () {
|
|
560
|
+
var _register_event = (function () {
|
|
945
561
|
// written by Dean Edwards, 2005
|
|
946
562
|
// with input from Tino Zijdel - crisp@xs4all.nl
|
|
947
|
-
// with input from Carl Sverre - mail@carlsverre.com
|
|
948
|
-
//
|
|
949
|
-
//
|
|
950
|
-
|
|
951
|
-
/**
|
|
952
|
-
* @param {Object} element
|
|
953
|
-
* @param {string} type
|
|
954
|
-
* @param {function(...*)} handler
|
|
955
|
-
* @param {boolean=} oldSchool
|
|
956
|
-
* @param {boolean=} useCapture
|
|
957
|
-
*/
|
|
958
|
-
var register_event = function (element, type, handler, oldSchool, useCapture) {
|
|
959
|
-
if (!element) {
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
if (element.addEventListener && !oldSchool) {
|
|
964
|
-
element.addEventListener(type, handler, !!useCapture);
|
|
965
|
-
} else {
|
|
966
|
-
var ontype = 'on' + type;
|
|
967
|
-
var old_handler = element[ontype]; // can be undefined
|
|
968
|
-
element[ontype] = makeHandler(element, handler, old_handler);
|
|
969
|
-
}
|
|
970
|
-
};
|
|
971
|
-
|
|
972
|
-
function makeHandler(element, new_handler, old_handlers) {
|
|
973
|
-
var handler = function (event) {
|
|
974
|
-
event = event || fixEvent(window.event);
|
|
975
|
-
|
|
976
|
-
// this basically happens in firefox whenever another script
|
|
977
|
-
// overwrites the onload callback and doesn't pass the event
|
|
978
|
-
// object to previously defined callbacks. All the browsers
|
|
979
|
-
// that don't define window.event implement addEventListener
|
|
980
|
-
// so the dom_loaded handler will still be fired as usual.
|
|
981
|
-
if (!event) {
|
|
982
|
-
return undefined
|
|
983
|
-
}
|
|
984
|
-
|
|
985
|
-
var ret = true;
|
|
986
|
-
var old_result, new_result;
|
|
987
|
-
|
|
988
|
-
if (_.isFunction(old_handlers)) {
|
|
989
|
-
old_result = old_handlers(event);
|
|
990
|
-
}
|
|
991
|
-
new_result = new_handler.call(element, event);
|
|
992
|
-
|
|
993
|
-
if (false === old_result || false === new_result) {
|
|
994
|
-
ret = false;
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
return ret
|
|
998
|
-
};
|
|
999
|
-
|
|
1000
|
-
return handler
|
|
1001
|
-
}
|
|
1002
|
-
|
|
1003
|
-
function fixEvent(event) {
|
|
1004
|
-
if (event) {
|
|
1005
|
-
event.preventDefault = fixEvent.preventDefault;
|
|
1006
|
-
event.stopPropagation = fixEvent.stopPropagation;
|
|
1007
|
-
}
|
|
1008
|
-
return event
|
|
1009
|
-
}
|
|
1010
|
-
fixEvent.preventDefault = function () {
|
|
1011
|
-
this.returnValue = false;
|
|
1012
|
-
};
|
|
1013
|
-
fixEvent.stopPropagation = function () {
|
|
1014
|
-
this.cancelBubble = true;
|
|
1015
|
-
};
|
|
1016
|
-
|
|
1017
|
-
return register_event
|
|
1018
|
-
})();
|
|
1019
|
-
|
|
1020
|
-
_.info = {
|
|
1021
|
-
campaignParams: function () {
|
|
1022
|
-
var campaign_keywords = 'utm_source utm_medium utm_campaign utm_content utm_term gclid'.split(' '),
|
|
1023
|
-
kw = '',
|
|
1024
|
-
params = {};
|
|
1025
|
-
_.each(campaign_keywords, function (kwkey) {
|
|
1026
|
-
kw = _.getQueryParam(document$1.URL, kwkey);
|
|
1027
|
-
if (kw.length) {
|
|
1028
|
-
params[kwkey] = kw;
|
|
1029
|
-
}
|
|
1030
|
-
});
|
|
1031
|
-
|
|
1032
|
-
return params
|
|
1033
|
-
},
|
|
1034
|
-
|
|
1035
|
-
searchEngine: function (referrer) {
|
|
1036
|
-
if (referrer.search('https?://(.*)google.([^/?]*)') === 0) {
|
|
1037
|
-
return 'google'
|
|
1038
|
-
} else if (referrer.search('https?://(.*)bing.com') === 0) {
|
|
1039
|
-
return 'bing'
|
|
1040
|
-
} else if (referrer.search('https?://(.*)yahoo.com') === 0) {
|
|
1041
|
-
return 'yahoo'
|
|
1042
|
-
} else if (referrer.search('https?://(.*)duckduckgo.com') === 0) {
|
|
1043
|
-
return 'duckduckgo'
|
|
1044
|
-
} else {
|
|
1045
|
-
return null
|
|
1046
|
-
}
|
|
1047
|
-
},
|
|
1048
|
-
|
|
1049
|
-
searchInfo: function (referrer) {
|
|
1050
|
-
var search = _.info.searchEngine(referrer),
|
|
1051
|
-
param = search != 'yahoo' ? 'q' : 'p',
|
|
1052
|
-
ret = {};
|
|
1053
|
-
|
|
1054
|
-
if (search !== null) {
|
|
1055
|
-
ret['$search_engine'] = search;
|
|
1056
|
-
|
|
1057
|
-
var keyword = _.getQueryParam(referrer, param);
|
|
1058
|
-
if (keyword.length) {
|
|
1059
|
-
ret['um_keyword'] = keyword;
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
|
|
1063
|
-
return ret
|
|
1064
|
-
},
|
|
1065
|
-
|
|
1066
|
-
/**
|
|
1067
|
-
* This function detects which browser is running this script.
|
|
1068
|
-
* The order of the checks are important since many user agents
|
|
1069
|
-
* include key words used in later checks.
|
|
1070
|
-
*/
|
|
1071
|
-
browser: function (user_agent, vendor, opera) {
|
|
1072
|
-
vendor = vendor || ''; // vendor is undefined for at least IE9
|
|
1073
|
-
if (opera || _.includes(user_agent, ' OPR/')) {
|
|
1074
|
-
if (_.includes(user_agent, 'Mini')) {
|
|
1075
|
-
return 'Opera Mini'
|
|
1076
|
-
}
|
|
1077
|
-
return 'Opera'
|
|
1078
|
-
} else if (/(BlackBerry|PlayBook|BB10)/i.test(user_agent)) {
|
|
1079
|
-
return 'BlackBerry'
|
|
1080
|
-
} else if (_.includes(user_agent, 'IEMobile') || _.includes(user_agent, 'WPDesktop')) {
|
|
1081
|
-
return 'Internet Explorer Mobile'
|
|
1082
|
-
} else if (_.includes(user_agent, 'SamsungBrowser/')) {
|
|
1083
|
-
// https://developer.samsung.com/internet/user-agent-string-format
|
|
1084
|
-
return 'Samsung Internet'
|
|
1085
|
-
} else if (_.includes(user_agent, 'Edge') || _.includes(user_agent, 'Edg/')) {
|
|
1086
|
-
return 'Microsoft Edge'
|
|
1087
|
-
} else if (_.includes(user_agent, 'FBIOS')) {
|
|
1088
|
-
return 'Facebook Mobile'
|
|
1089
|
-
} else if (_.includes(user_agent, 'Chrome')) {
|
|
1090
|
-
return 'Chrome'
|
|
1091
|
-
} else if (_.includes(user_agent, 'CriOS')) {
|
|
1092
|
-
return 'Chrome iOS'
|
|
1093
|
-
} else if (_.includes(user_agent, 'UCWEB') || _.includes(user_agent, 'UCBrowser')) {
|
|
1094
|
-
return 'UC Browser'
|
|
1095
|
-
} else if (_.includes(user_agent, 'FxiOS')) {
|
|
1096
|
-
return 'Firefox iOS'
|
|
1097
|
-
} else if (_.includes(vendor, 'Apple')) {
|
|
1098
|
-
if (_.includes(user_agent, 'Mobile')) {
|
|
1099
|
-
return 'Mobile Safari'
|
|
1100
|
-
}
|
|
1101
|
-
return 'Safari'
|
|
1102
|
-
} else if (_.includes(user_agent, 'Android')) {
|
|
1103
|
-
return 'Android Mobile'
|
|
1104
|
-
} else if (_.includes(user_agent, 'Konqueror')) {
|
|
1105
|
-
return 'Konqueror'
|
|
1106
|
-
} else if (_.includes(user_agent, 'Firefox')) {
|
|
1107
|
-
return 'Firefox'
|
|
1108
|
-
} else if (_.includes(user_agent, 'MSIE') || _.includes(user_agent, 'Trident/')) {
|
|
1109
|
-
return 'Internet Explorer'
|
|
1110
|
-
} else if (_.includes(user_agent, 'Gecko')) {
|
|
1111
|
-
return 'Mozilla'
|
|
1112
|
-
} else {
|
|
1113
|
-
return ''
|
|
1114
|
-
}
|
|
1115
|
-
},
|
|
1116
|
-
|
|
1117
|
-
/**
|
|
1118
|
-
* This function detects which browser version is running this script,
|
|
1119
|
-
* parsing major and minor version (e.g., 42.1). User agent strings from:
|
|
1120
|
-
* http://www.useragentstring.com/pages/useragentstring.php
|
|
1121
|
-
*/
|
|
1122
|
-
browserVersion: function (userAgent, vendor, opera) {
|
|
1123
|
-
var browser = _.info.browser(userAgent, vendor, opera);
|
|
1124
|
-
var versionRegexs = {
|
|
1125
|
-
'Internet Explorer Mobile': /rv:(\d+(\.\d+)?)/,
|
|
1126
|
-
'Microsoft Edge': /Edge?\/(\d+(\.\d+)?)/,
|
|
1127
|
-
Chrome: /Chrome\/(\d+(\.\d+)?)/,
|
|
1128
|
-
'Chrome iOS': /CriOS\/(\d+(\.\d+)?)/,
|
|
1129
|
-
'UC Browser': /(UCBrowser|UCWEB)\/(\d+(\.\d+)?)/,
|
|
1130
|
-
Safari: /Version\/(\d+(\.\d+)?)/,
|
|
1131
|
-
'Mobile Safari': /Version\/(\d+(\.\d+)?)/,
|
|
1132
|
-
Opera: /(Opera|OPR)\/(\d+(\.\d+)?)/,
|
|
1133
|
-
Firefox: /Firefox\/(\d+(\.\d+)?)/,
|
|
1134
|
-
'Firefox iOS': /FxiOS\/(\d+(\.\d+)?)/,
|
|
1135
|
-
Konqueror: /Konqueror:(\d+(\.\d+)?)/,
|
|
1136
|
-
BlackBerry: /BlackBerry (\d+(\.\d+)?)/,
|
|
1137
|
-
'Android Mobile': /android\s(\d+(\.\d+)?)/,
|
|
1138
|
-
'Samsung Internet': /SamsungBrowser\/(\d+(\.\d+)?)/,
|
|
1139
|
-
'Internet Explorer': /(rv:|MSIE )(\d+(\.\d+)?)/,
|
|
1140
|
-
Mozilla: /rv:(\d+(\.\d+)?)/,
|
|
1141
|
-
};
|
|
1142
|
-
var regex = versionRegexs[browser];
|
|
1143
|
-
if (regex === undefined) {
|
|
1144
|
-
return null
|
|
1145
|
-
}
|
|
1146
|
-
var matches = userAgent.match(regex);
|
|
1147
|
-
if (!matches) {
|
|
1148
|
-
return null
|
|
1149
|
-
}
|
|
1150
|
-
return parseFloat(matches[matches.length - 2])
|
|
1151
|
-
},
|
|
1152
|
-
|
|
1153
|
-
os: function () {
|
|
1154
|
-
var a = userAgent;
|
|
1155
|
-
if (/Windows/i.test(a)) {
|
|
1156
|
-
if (/Phone/.test(a) || /WPDesktop/.test(a)) {
|
|
1157
|
-
return 'Windows Phone'
|
|
1158
|
-
}
|
|
1159
|
-
return 'Windows'
|
|
1160
|
-
} else if (/(iPhone|iPad|iPod)/.test(a)) {
|
|
1161
|
-
return 'iOS'
|
|
1162
|
-
} else if (/Android/.test(a)) {
|
|
1163
|
-
return 'Android'
|
|
1164
|
-
} else if (/(BlackBerry|PlayBook|BB10)/i.test(a)) {
|
|
1165
|
-
return 'BlackBerry'
|
|
1166
|
-
} else if (/Mac/i.test(a)) {
|
|
1167
|
-
return 'Mac OS X'
|
|
1168
|
-
} else if (/Linux/.test(a)) {
|
|
1169
|
-
return 'Linux'
|
|
1170
|
-
} else if (/CrOS/.test(a)) {
|
|
1171
|
-
return 'Chrome OS'
|
|
1172
|
-
} else {
|
|
1173
|
-
return ''
|
|
1174
|
-
}
|
|
1175
|
-
},
|
|
1176
|
-
|
|
1177
|
-
device: function (user_agent) {
|
|
1178
|
-
if (/Windows Phone/i.test(user_agent) || /WPDesktop/.test(user_agent)) {
|
|
1179
|
-
return 'Windows Phone'
|
|
1180
|
-
} else if (/iPad/.test(user_agent)) {
|
|
1181
|
-
return 'iPad'
|
|
1182
|
-
} else if (/iPod/.test(user_agent)) {
|
|
1183
|
-
return 'iPod Touch'
|
|
1184
|
-
} else if (/iPhone/.test(user_agent)) {
|
|
1185
|
-
return 'iPhone'
|
|
1186
|
-
} else if (/(BlackBerry|PlayBook|BB10)/i.test(user_agent)) {
|
|
1187
|
-
return 'BlackBerry'
|
|
1188
|
-
} else if (/Android/.test(user_agent) && !/Mobile/.test(user_agent)) {
|
|
1189
|
-
return 'Android Tablet'
|
|
1190
|
-
} else if (/Android/.test(user_agent)) {
|
|
1191
|
-
return 'Android'
|
|
1192
|
-
} else {
|
|
1193
|
-
return ''
|
|
1194
|
-
}
|
|
1195
|
-
},
|
|
1196
|
-
|
|
1197
|
-
deviceType: function (user_agent) {
|
|
1198
|
-
const device = this.device(user_agent);
|
|
1199
|
-
if (device === 'iPad' || device === 'Android Tablet') {
|
|
1200
|
-
return 'Tablet'
|
|
1201
|
-
} else if (device) {
|
|
1202
|
-
return 'Mobile'
|
|
1203
|
-
} else {
|
|
1204
|
-
return 'Desktop'
|
|
1205
|
-
}
|
|
1206
|
-
},
|
|
1207
|
-
|
|
1208
|
-
referringDomain: function (referrer) {
|
|
1209
|
-
var split = referrer.split('/');
|
|
1210
|
-
if (split.length >= 3) {
|
|
1211
|
-
return split[2]
|
|
1212
|
-
}
|
|
1213
|
-
return ''
|
|
1214
|
-
},
|
|
1215
|
-
|
|
1216
|
-
properties: function () {
|
|
1217
|
-
return _.extend(
|
|
1218
|
-
_.strip_empty_properties({
|
|
1219
|
-
$os: _.info.os(),
|
|
1220
|
-
$browser: _.info.browser(userAgent, navigator$1.vendor, window.opera),
|
|
1221
|
-
$device: _.info.device(userAgent),
|
|
1222
|
-
$device_type: _.info.deviceType(userAgent),
|
|
1223
|
-
}),
|
|
1224
|
-
{
|
|
1225
|
-
$current_url: window.location.href,
|
|
1226
|
-
$host: window.location.host,
|
|
1227
|
-
$pathname: window.location.pathname,
|
|
1228
|
-
$browser_version: _.info.browserVersion(userAgent, navigator$1.vendor, window.opera),
|
|
1229
|
-
$screen_height: window.screen.height,
|
|
1230
|
-
$screen_width: window.screen.width,
|
|
1231
|
-
$viewport_height: window.innerHeight,
|
|
1232
|
-
$viewport_width: window.innerWidth,
|
|
1233
|
-
$lib: 'web',
|
|
1234
|
-
$lib_version: Config$1.LIB_VERSION,
|
|
1235
|
-
$insert_id: Math.random().toString(36).substring(2, 10) + Math.random().toString(36).substring(2, 10),
|
|
1236
|
-
$time: _.timestamp() / 1000, // epoch time in seconds
|
|
1237
|
-
}
|
|
1238
|
-
)
|
|
1239
|
-
},
|
|
1240
|
-
|
|
1241
|
-
people_properties: function () {
|
|
1242
|
-
return _.extend(
|
|
1243
|
-
_.strip_empty_properties({
|
|
1244
|
-
$os: _.info.os(),
|
|
1245
|
-
$browser: _.info.browser(userAgent, navigator$1.vendor, window.opera),
|
|
1246
|
-
}),
|
|
1247
|
-
{
|
|
1248
|
-
$browser_version: _.info.browserVersion(userAgent, navigator$1.vendor, window.opera),
|
|
1249
|
-
}
|
|
1250
|
-
)
|
|
1251
|
-
},
|
|
1252
|
-
};
|
|
1253
|
-
|
|
1254
|
-
// EXPORTS (for closure compiler)
|
|
1255
|
-
_['isObject'] = _.isObject;
|
|
1256
|
-
_['isBlockedUA'] = _.isBlockedUA;
|
|
1257
|
-
_['isEmptyObject'] = _.isEmptyObject;
|
|
1258
|
-
_['info'] = _.info;
|
|
1259
|
-
_['info']['device'] = _.info.device;
|
|
1260
|
-
_['info']['browser'] = _.info.browser;
|
|
1261
|
-
_['info']['browserVersion'] = _.info.browserVersion;
|
|
1262
|
-
_['info']['properties'] = _.info.properties;
|
|
1263
|
-
|
|
1264
|
-
var DOMAIN_MATCH_REGEX = /[a-z0-9][a-z0-9-]+\.[a-z.]{2,6}$/i;
|
|
1265
|
-
|
|
1266
|
-
// Methods partially borrowed from quirksmode.org/js/cookies.html
|
|
1267
|
-
const cookieStore = {
|
|
1268
|
-
get: function (name) {
|
|
1269
|
-
try {
|
|
1270
|
-
var nameEQ = name + '=';
|
|
1271
|
-
var ca = document.cookie.split(';');
|
|
1272
|
-
for (var i = 0; i < ca.length; i++) {
|
|
1273
|
-
var c = ca[i];
|
|
1274
|
-
while (c.charAt(0) == ' ') {
|
|
1275
|
-
c = c.substring(1, c.length);
|
|
1276
|
-
}
|
|
1277
|
-
if (c.indexOf(nameEQ) === 0) {
|
|
1278
|
-
return decodeURIComponent(c.substring(nameEQ.length, c.length))
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
} catch (err) {}
|
|
1282
|
-
return null
|
|
1283
|
-
},
|
|
1284
|
-
|
|
1285
|
-
parse: function (name) {
|
|
1286
|
-
var cookie;
|
|
1287
|
-
try {
|
|
1288
|
-
cookie = JSON.parse(cookieStore.get(name)) || {};
|
|
1289
|
-
} catch (err) {
|
|
1290
|
-
// noop
|
|
1291
|
-
}
|
|
1292
|
-
return cookie
|
|
1293
|
-
},
|
|
1294
|
-
|
|
1295
|
-
set: function (name, value, days, cross_subdomain, is_secure) {
|
|
1296
|
-
try {
|
|
1297
|
-
var cdomain = '',
|
|
1298
|
-
expires = '',
|
|
1299
|
-
secure = '';
|
|
1300
|
-
|
|
1301
|
-
if (cross_subdomain) {
|
|
1302
|
-
var matches = document.location.hostname.match(DOMAIN_MATCH_REGEX),
|
|
1303
|
-
domain = matches ? matches[0] : '';
|
|
1304
|
-
|
|
1305
|
-
cdomain = domain ? '; domain=.' + domain : '';
|
|
1306
|
-
}
|
|
1307
|
-
|
|
1308
|
-
if (days) {
|
|
1309
|
-
var date = new Date();
|
|
1310
|
-
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
|
|
1311
|
-
expires = '; expires=' + date.toGMTString();
|
|
1312
|
-
}
|
|
1313
|
-
|
|
1314
|
-
if (is_secure) {
|
|
1315
|
-
secure = '; secure';
|
|
1316
|
-
}
|
|
1317
|
-
|
|
1318
|
-
var new_cookie_val =
|
|
1319
|
-
name + '=' + encodeURIComponent(JSON.stringify(value)) + expires + '; path=/' + cdomain + secure;
|
|
1320
|
-
document.cookie = new_cookie_val;
|
|
1321
|
-
return new_cookie_val
|
|
1322
|
-
} catch (err) {
|
|
1323
|
-
return
|
|
1324
|
-
}
|
|
1325
|
-
},
|
|
1326
|
-
|
|
1327
|
-
remove: function (name, cross_subdomain) {
|
|
1328
|
-
try {
|
|
1329
|
-
cookieStore.set(name, '', -1, cross_subdomain);
|
|
1330
|
-
} catch (err) {
|
|
1331
|
-
return
|
|
1332
|
-
}
|
|
1333
|
-
},
|
|
1334
|
-
};
|
|
1335
|
-
|
|
1336
|
-
var _localStorage_supported = null;
|
|
1337
|
-
const localStore = {
|
|
1338
|
-
is_supported: function () {
|
|
1339
|
-
if (_localStorage_supported !== null) {
|
|
1340
|
-
return _localStorage_supported
|
|
1341
|
-
}
|
|
1342
|
-
|
|
1343
|
-
var supported = true;
|
|
1344
|
-
if (window) {
|
|
1345
|
-
try {
|
|
1346
|
-
var key = '__mplssupport__',
|
|
1347
|
-
val = 'xyz';
|
|
1348
|
-
localStore.set(key, val);
|
|
1349
|
-
if (localStore.get(key) !== '"xyz"') {
|
|
1350
|
-
supported = false;
|
|
1351
|
-
}
|
|
1352
|
-
localStore.remove(key);
|
|
1353
|
-
} catch (err) {
|
|
1354
|
-
supported = false;
|
|
1355
|
-
}
|
|
1356
|
-
} else {
|
|
1357
|
-
supported = false;
|
|
1358
|
-
}
|
|
1359
|
-
|
|
1360
|
-
_localStorage_supported = supported;
|
|
1361
|
-
return supported
|
|
1362
|
-
},
|
|
1363
|
-
|
|
1364
|
-
error: function (msg) {
|
|
1365
|
-
},
|
|
1366
|
-
|
|
1367
|
-
get: function (name) {
|
|
1368
|
-
try {
|
|
1369
|
-
return window.localStorage.getItem(name)
|
|
1370
|
-
} catch (err) {
|
|
1371
|
-
localStore.error(err);
|
|
1372
|
-
}
|
|
1373
|
-
return null
|
|
1374
|
-
},
|
|
1375
|
-
|
|
1376
|
-
parse: function (name) {
|
|
1377
|
-
try {
|
|
1378
|
-
return JSON.parse(localStore.get(name)) || {}
|
|
1379
|
-
} catch (err) {
|
|
1380
|
-
// noop
|
|
1381
|
-
}
|
|
1382
|
-
return null
|
|
1383
|
-
},
|
|
1384
|
-
|
|
1385
|
-
set: function (name, value) {
|
|
1386
|
-
try {
|
|
1387
|
-
window.localStorage.setItem(name, JSON.stringify(value));
|
|
1388
|
-
} catch (err) {
|
|
1389
|
-
localStore.error(err);
|
|
1390
|
-
}
|
|
1391
|
-
},
|
|
1392
|
-
|
|
1393
|
-
remove: function (name) {
|
|
1394
|
-
try {
|
|
1395
|
-
window.localStorage.removeItem(name);
|
|
1396
|
-
} catch (err) {
|
|
1397
|
-
localStore.error(err);
|
|
1398
|
-
}
|
|
1399
|
-
},
|
|
1400
|
-
};
|
|
1401
|
-
|
|
1402
|
-
// Use localstorage for most data but still use cookie for distinct_id
|
|
1403
|
-
// This solves issues with cookies having too much data in them causing headers too large
|
|
1404
|
-
// Also makes sure we don't have to send a ton of data to the server
|
|
1405
|
-
const localPlusCookieStore = {
|
|
1406
|
-
...localStore,
|
|
1407
|
-
parse: function (name) {
|
|
1408
|
-
try {
|
|
1409
|
-
let extend = {};
|
|
1410
|
-
try {
|
|
1411
|
-
// See if there's a cookie stored with data.
|
|
1412
|
-
extend = cookieStore.parse(name) || {};
|
|
1413
|
-
if (extend['distinct_id']) {
|
|
1414
|
-
cookieStore.set(name, { distinct_id: extend['distinct_id'] });
|
|
1415
|
-
}
|
|
1416
|
-
} catch (err) {}
|
|
1417
|
-
const value = _.extend(extend, JSON.parse(localStore.get(name) || '{}'));
|
|
1418
|
-
localStore.set(name, value);
|
|
1419
|
-
return value
|
|
1420
|
-
} catch (err) {
|
|
1421
|
-
// noop
|
|
1422
|
-
}
|
|
1423
|
-
return null
|
|
1424
|
-
},
|
|
1425
|
-
|
|
1426
|
-
set: function (name, value) {
|
|
1427
|
-
try {
|
|
1428
|
-
localStore.set(name, value);
|
|
1429
|
-
if (value.distinct_id) {
|
|
1430
|
-
cookieStore.set(name, { distinct_id: value.distinct_id });
|
|
1431
|
-
}
|
|
1432
|
-
} catch (err) {
|
|
1433
|
-
localStore.error(err);
|
|
1434
|
-
}
|
|
1435
|
-
},
|
|
1436
|
-
|
|
1437
|
-
remove: function (name) {
|
|
1438
|
-
try {
|
|
1439
|
-
window.localStorage.removeItem(name);
|
|
1440
|
-
cookieStore.remove(name);
|
|
1441
|
-
} catch (err) {
|
|
1442
|
-
localStore.error(err);
|
|
1443
|
-
}
|
|
1444
|
-
},
|
|
1445
|
-
};
|
|
1446
|
-
|
|
1447
|
-
const memoryStorage = {};
|
|
1448
|
-
|
|
1449
|
-
// Storage that only lasts the length of the pageview if we don't want to use cookies
|
|
1450
|
-
const memoryStore = {
|
|
1451
|
-
is_supported: function () {
|
|
1452
|
-
return true
|
|
1453
|
-
},
|
|
1454
|
-
|
|
1455
|
-
error: function (msg) {
|
|
1456
|
-
},
|
|
1457
|
-
|
|
1458
|
-
parse: function (name) {
|
|
1459
|
-
return memoryStorage[name] || null
|
|
1460
|
-
},
|
|
1461
|
-
|
|
1462
|
-
set: function (name, value) {
|
|
1463
|
-
memoryStorage[name] = value;
|
|
1464
|
-
},
|
|
1465
|
-
|
|
1466
|
-
remove: function (name) {
|
|
1467
|
-
delete memoryStorage[name];
|
|
1468
|
-
},
|
|
1469
|
-
};
|
|
1470
|
-
|
|
1471
|
-
// Storage that only lasts the length of a tab/window. Survives page refreshes
|
|
1472
|
-
const sessionStore = {
|
|
1473
|
-
sessionStorageSupported: null,
|
|
1474
|
-
is_supported: function () {
|
|
1475
|
-
if (sessionStore.sessionStorageSupported !== null) {
|
|
1476
|
-
return sessionStore.sessionStorageSupported
|
|
1477
|
-
}
|
|
1478
|
-
sessionStore.sessionStorageSupported = true;
|
|
1479
|
-
if (window) {
|
|
1480
|
-
try {
|
|
1481
|
-
let key = '__support__',
|
|
1482
|
-
val = 'xyz';
|
|
1483
|
-
sessionStore.set(key, val);
|
|
1484
|
-
if (sessionStore.get(key) !== '"xyz"') {
|
|
1485
|
-
sessionStore.sessionStorageSupported = false;
|
|
1486
|
-
}
|
|
1487
|
-
sessionStore.remove(key);
|
|
1488
|
-
} catch (err) {
|
|
1489
|
-
sessionStore.sessionStorageSupported = false;
|
|
1490
|
-
}
|
|
1491
|
-
} else {
|
|
1492
|
-
sessionStore.sessionStorageSupported = false;
|
|
1493
|
-
}
|
|
1494
|
-
return sessionStore.sessionStorageSupported
|
|
1495
|
-
},
|
|
1496
|
-
error: function (msg) {
|
|
1497
|
-
if (Config.DEBUG) ;
|
|
1498
|
-
},
|
|
1499
|
-
|
|
1500
|
-
get: function (name) {
|
|
1501
|
-
try {
|
|
1502
|
-
return window.sessionStorage.getItem(name)
|
|
1503
|
-
} catch (err) {
|
|
1504
|
-
sessionStore.error(err);
|
|
1505
|
-
}
|
|
1506
|
-
return null
|
|
1507
|
-
},
|
|
1508
|
-
|
|
1509
|
-
parse: function (name) {
|
|
1510
|
-
try {
|
|
1511
|
-
return JSON.parse(sessionStore.get(name)) || null
|
|
1512
|
-
} catch (err) {
|
|
1513
|
-
// noop
|
|
1514
|
-
}
|
|
1515
|
-
return null
|
|
1516
|
-
},
|
|
1517
|
-
|
|
1518
|
-
set: function (name, value) {
|
|
1519
|
-
try {
|
|
1520
|
-
window.sessionStorage.setItem(name, JSON.stringify(value));
|
|
1521
|
-
} catch (err) {
|
|
1522
|
-
sessionStore.error(err);
|
|
1523
|
-
}
|
|
1524
|
-
},
|
|
1525
|
-
|
|
1526
|
-
remove: function (name) {
|
|
1527
|
-
try {
|
|
1528
|
-
window.sessionStorage.removeItem(name);
|
|
1529
|
-
} catch (err) {
|
|
1530
|
-
sessionStore.error(err);
|
|
1531
|
-
}
|
|
1532
|
-
},
|
|
1533
|
-
};
|
|
1534
|
-
|
|
1535
|
-
/* eslint camelcase: "off" */
|
|
1536
|
-
|
|
1537
|
-
/*
|
|
1538
|
-
* Constants
|
|
1539
|
-
*/
|
|
1540
|
-
/** @const */ var SET_QUEUE_KEY = '__mps';
|
|
1541
|
-
/** @const */ var SET_ONCE_QUEUE_KEY = '__mpso';
|
|
1542
|
-
/** @const */ var UNSET_QUEUE_KEY = '__mpus';
|
|
1543
|
-
/** @const */ var ADD_QUEUE_KEY = '__mpa';
|
|
1544
|
-
/** @const */ var APPEND_QUEUE_KEY = '__mpap';
|
|
1545
|
-
/** @const */ var REMOVE_QUEUE_KEY = '__mpr';
|
|
1546
|
-
/** @const */ var UNION_QUEUE_KEY = '__mpu';
|
|
1547
|
-
/** @const */ var CAMPAIGN_IDS_KEY = '__cmpns';
|
|
1548
|
-
/** @const */ var EVENT_TIMERS_KEY = '__timers';
|
|
1549
|
-
/** @const */ var SESSION_RECORDING_ENABLED = '$session_recording_enabled';
|
|
1550
|
-
/** @const */ var SESSION_ID = '$sesid';
|
|
1551
|
-
/** @const */ var ENABLED_FEATURE_FLAGS = '$enabled_feature_flags';
|
|
1552
|
-
/** @const */ var RESERVED_PROPERTIES = [
|
|
1553
|
-
SET_QUEUE_KEY,
|
|
1554
|
-
SET_ONCE_QUEUE_KEY,
|
|
1555
|
-
UNSET_QUEUE_KEY,
|
|
1556
|
-
ADD_QUEUE_KEY,
|
|
1557
|
-
APPEND_QUEUE_KEY,
|
|
1558
|
-
REMOVE_QUEUE_KEY,
|
|
1559
|
-
UNION_QUEUE_KEY,
|
|
1560
|
-
CAMPAIGN_IDS_KEY,
|
|
1561
|
-
EVENT_TIMERS_KEY,
|
|
1562
|
-
SESSION_RECORDING_ENABLED,
|
|
1563
|
-
SESSION_ID,
|
|
1564
|
-
ENABLED_FEATURE_FLAGS,
|
|
1565
|
-
];
|
|
1566
|
-
|
|
1567
|
-
/**
|
|
1568
|
-
* UserMaven Persistence Object
|
|
1569
|
-
* @constructor
|
|
1570
|
-
*/
|
|
1571
|
-
var UserMavenPersistence = function (config) {
|
|
1572
|
-
// clean chars that aren't accepted by the http spec for cookie values
|
|
1573
|
-
// https://datatracker.ietf.org/doc/html/rfc2616#section-2.2
|
|
1574
|
-
let token = '';
|
|
1575
|
-
|
|
1576
|
-
if (config['token']) {
|
|
1577
|
-
token = config['token'].replace(/\+/g, 'PL').replace(/\//g, 'SL').replace(/=/g, 'EQ');
|
|
1578
|
-
}
|
|
1579
|
-
|
|
1580
|
-
this['props'] = {};
|
|
1581
|
-
this.campaign_params_saved = false;
|
|
1582
|
-
|
|
1583
|
-
if (config['persistence_name']) {
|
|
1584
|
-
this.name = 'um_' + config['persistence_name'];
|
|
1585
|
-
} else {
|
|
1586
|
-
this.name = 'um_' + token + '_usermaven';
|
|
1587
|
-
}
|
|
1588
|
-
|
|
1589
|
-
var storage_type = config['persistence'];
|
|
1590
|
-
if (storage_type !== 'cookie' && storage_type.indexOf('localStorage') === -1 && storage_type !== 'memory') {
|
|
1591
|
-
console$1.critical('Unknown persistence type ' + storage_type + '; falling back to cookie');
|
|
1592
|
-
storage_type = config['persistence'] = 'cookie';
|
|
1593
|
-
}
|
|
1594
|
-
if (storage_type === 'localStorage' && localStore.is_supported()) {
|
|
1595
|
-
this.storage = localStore;
|
|
1596
|
-
} else if (storage_type === 'localStorage+cookie' && localPlusCookieStore.is_supported()) {
|
|
1597
|
-
this.storage = localPlusCookieStore;
|
|
1598
|
-
} else if (storage_type === 'memory') {
|
|
1599
|
-
this.storage = memoryStore;
|
|
1600
|
-
} else {
|
|
1601
|
-
this.storage = cookieStore;
|
|
1602
|
-
}
|
|
1603
|
-
|
|
1604
|
-
this.load();
|
|
1605
|
-
this.update_config(config);
|
|
1606
|
-
this.save();
|
|
1607
|
-
};
|
|
1608
|
-
|
|
1609
|
-
UserMavenPersistence.prototype.properties = function () {
|
|
1610
|
-
var p = {};
|
|
1611
|
-
// Filter out reserved properties
|
|
1612
|
-
_.each(this['props'], function (v, k) {
|
|
1613
|
-
if (k === ENABLED_FEATURE_FLAGS && typeof v === 'object') {
|
|
1614
|
-
var keys = Object.keys(v);
|
|
1615
|
-
for (var i = 0; i < keys.length; i++) {
|
|
1616
|
-
p[`$feature/${keys[i]}`] = v[keys[i]];
|
|
1617
|
-
}
|
|
1618
|
-
} else if (!_.include(RESERVED_PROPERTIES, k)) {
|
|
1619
|
-
p[k] = v;
|
|
1620
|
-
}
|
|
1621
|
-
});
|
|
1622
|
-
return p
|
|
1623
|
-
};
|
|
1624
|
-
|
|
1625
|
-
UserMavenPersistence.prototype.load = function () {
|
|
1626
|
-
if (this.disabled) {
|
|
1627
|
-
return
|
|
1628
|
-
}
|
|
1629
|
-
|
|
1630
|
-
var entry = this.storage.parse(this.name);
|
|
1631
|
-
|
|
1632
|
-
if (entry) {
|
|
1633
|
-
this['props'] = _.extend({}, entry);
|
|
1634
|
-
}
|
|
1635
|
-
};
|
|
1636
|
-
|
|
1637
|
-
UserMavenPersistence.prototype.save = function () {
|
|
1638
|
-
if (this.disabled) {
|
|
1639
|
-
return
|
|
1640
|
-
}
|
|
1641
|
-
this.storage.set(this.name, this['props'], this.expire_days, this.cross_subdomain, this.secure);
|
|
1642
|
-
};
|
|
1643
|
-
|
|
1644
|
-
UserMavenPersistence.prototype.remove = function () {
|
|
1645
|
-
// remove both domain and subdomain cookies
|
|
1646
|
-
this.storage.remove(this.name, false);
|
|
1647
|
-
this.storage.remove(this.name, true);
|
|
1648
|
-
};
|
|
1649
|
-
|
|
1650
|
-
// removes the storage entry and deletes all loaded data
|
|
1651
|
-
// forced name for tests
|
|
1652
|
-
UserMavenPersistence.prototype.clear = function () {
|
|
1653
|
-
this.remove();
|
|
1654
|
-
this['props'] = {};
|
|
1655
|
-
};
|
|
1656
|
-
|
|
1657
|
-
/**
|
|
1658
|
-
* @param {Object} props
|
|
1659
|
-
* @param {*=} default_value
|
|
1660
|
-
* @param {number=} days
|
|
1661
|
-
*/
|
|
1662
|
-
UserMavenPersistence.prototype.register_once = function (props, default_value, days) {
|
|
1663
|
-
if (_.isObject(props)) {
|
|
1664
|
-
if (typeof default_value === 'undefined') {
|
|
1665
|
-
default_value = 'None';
|
|
1666
|
-
}
|
|
1667
|
-
this.expire_days = typeof days === 'undefined' ? this.default_expiry : days;
|
|
1668
|
-
|
|
1669
|
-
_.each(
|
|
1670
|
-
props,
|
|
1671
|
-
function (val, prop) {
|
|
1672
|
-
if (!this['props'].hasOwnProperty(prop) || this['props'][prop] === default_value) {
|
|
1673
|
-
this['props'][prop] = val;
|
|
1674
|
-
}
|
|
1675
|
-
},
|
|
1676
|
-
this
|
|
1677
|
-
);
|
|
1678
|
-
|
|
1679
|
-
this.save();
|
|
1680
|
-
|
|
1681
|
-
return true
|
|
1682
|
-
}
|
|
1683
|
-
return false
|
|
1684
|
-
};
|
|
1685
|
-
|
|
1686
|
-
/**
|
|
1687
|
-
* @param {Object} props
|
|
1688
|
-
* @param {number=} days
|
|
1689
|
-
*/
|
|
1690
|
-
UserMavenPersistence.prototype.register = function (props, days) {
|
|
1691
|
-
if (_.isObject(props)) {
|
|
1692
|
-
this.expire_days = typeof days === 'undefined' ? this.default_expiry : days;
|
|
1693
|
-
|
|
1694
|
-
_.extend(this['props'], props);
|
|
1695
|
-
|
|
1696
|
-
this.save();
|
|
1697
|
-
|
|
1698
|
-
return true
|
|
1699
|
-
}
|
|
1700
|
-
return false
|
|
1701
|
-
};
|
|
1702
|
-
|
|
1703
|
-
UserMavenPersistence.prototype.unregister = function (prop) {
|
|
1704
|
-
if (prop in this['props']) {
|
|
1705
|
-
delete this['props'][prop];
|
|
1706
|
-
this.save();
|
|
1707
|
-
}
|
|
1708
|
-
};
|
|
1709
|
-
|
|
1710
|
-
UserMavenPersistence.prototype.update_campaign_params = function () {
|
|
1711
|
-
if (!this.campaign_params_saved) {
|
|
1712
|
-
this.register(_.info.campaignParams());
|
|
1713
|
-
this.campaign_params_saved = true;
|
|
1714
|
-
}
|
|
1715
|
-
};
|
|
1716
|
-
|
|
1717
|
-
UserMavenPersistence.prototype.update_search_keyword = function (referrer) {
|
|
1718
|
-
this.register(_.info.searchInfo(referrer));
|
|
1719
|
-
};
|
|
1720
|
-
|
|
1721
|
-
// EXPORTED METHOD, we test this directly.
|
|
1722
|
-
UserMavenPersistence.prototype.update_referrer_info = function (referrer) {
|
|
1723
|
-
// If referrer doesn't exist, we want to note the fact that it was type-in traffic.
|
|
1724
|
-
// Register once, so first touch
|
|
1725
|
-
this.register_once(
|
|
1726
|
-
{
|
|
1727
|
-
$initial_referrer: referrer || '$direct',
|
|
1728
|
-
$initial_referring_domain: _.info.referringDomain(referrer) || '$direct',
|
|
1729
|
-
},
|
|
1730
|
-
''
|
|
1731
|
-
);
|
|
1732
|
-
// Register the current referrer but override if it's different, hence register
|
|
1733
|
-
this.register({
|
|
1734
|
-
$referrer: referrer || this['props']['$referrer'] || '$direct',
|
|
1735
|
-
$referring_domain: _.info.referringDomain(referrer) || this['props']['$referring_domain'] || '$direct',
|
|
1736
|
-
});
|
|
1737
|
-
};
|
|
1738
|
-
|
|
1739
|
-
UserMavenPersistence.prototype.get_referrer_info = function () {
|
|
1740
|
-
return _.strip_empty_properties({
|
|
1741
|
-
$initial_referrer: this['props']['$initial_referrer'],
|
|
1742
|
-
$initial_referring_domain: this['props']['$initial_referring_domain'],
|
|
1743
|
-
})
|
|
1744
|
-
};
|
|
1745
|
-
|
|
1746
|
-
// safely fills the passed in object with stored properties,
|
|
1747
|
-
// does not override any properties defined in both
|
|
1748
|
-
// returns the passed in object
|
|
1749
|
-
UserMavenPersistence.prototype.safe_merge = function (props) {
|
|
1750
|
-
_.each(this['props'], function (val, prop) {
|
|
1751
|
-
if (!(prop in props)) {
|
|
1752
|
-
props[prop] = val;
|
|
1753
|
-
}
|
|
1754
|
-
});
|
|
1755
|
-
|
|
1756
|
-
return props
|
|
1757
|
-
};
|
|
1758
|
-
|
|
1759
|
-
UserMavenPersistence.prototype.update_config = function (config) {
|
|
1760
|
-
this.default_expiry = this.expire_days = config['cookie_expiration'];
|
|
1761
|
-
this.set_disabled(config['disable_persistence']);
|
|
1762
|
-
this.set_cross_subdomain(config['cross_subdomain_cookie']);
|
|
1763
|
-
this.set_secure(config['secure_cookie']);
|
|
1764
|
-
};
|
|
1765
|
-
|
|
1766
|
-
UserMavenPersistence.prototype.set_disabled = function (disabled) {
|
|
1767
|
-
this.disabled = disabled;
|
|
1768
|
-
if (this.disabled) {
|
|
1769
|
-
this.remove();
|
|
1770
|
-
} else {
|
|
1771
|
-
this.save();
|
|
1772
|
-
}
|
|
1773
|
-
};
|
|
1774
|
-
|
|
1775
|
-
UserMavenPersistence.prototype.set_cross_subdomain = function (cross_subdomain) {
|
|
1776
|
-
if (cross_subdomain !== this.cross_subdomain) {
|
|
1777
|
-
this.cross_subdomain = cross_subdomain;
|
|
1778
|
-
this.remove();
|
|
1779
|
-
this.save();
|
|
1780
|
-
}
|
|
1781
|
-
};
|
|
1782
|
-
|
|
1783
|
-
UserMavenPersistence.prototype.get_cross_subdomain = function () {
|
|
1784
|
-
return this.cross_subdomain
|
|
1785
|
-
};
|
|
1786
|
-
|
|
1787
|
-
UserMavenPersistence.prototype.set_secure = function (secure) {
|
|
1788
|
-
if (secure !== this.secure) {
|
|
1789
|
-
this.secure = secure ? true : false;
|
|
1790
|
-
this.remove();
|
|
1791
|
-
this.save();
|
|
1792
|
-
}
|
|
1793
|
-
};
|
|
1794
|
-
|
|
1795
|
-
UserMavenPersistence.prototype.set_event_timer = function (event_name, timestamp) {
|
|
1796
|
-
var timers = this['props'][EVENT_TIMERS_KEY] || {};
|
|
1797
|
-
timers[event_name] = timestamp;
|
|
1798
|
-
this['props'][EVENT_TIMERS_KEY] = timers;
|
|
1799
|
-
this.save();
|
|
1800
|
-
};
|
|
1801
|
-
|
|
1802
|
-
UserMavenPersistence.prototype.remove_event_timer = function (event_name) {
|
|
1803
|
-
var timers = this['props'][EVENT_TIMERS_KEY] || {};
|
|
1804
|
-
var timestamp = timers[event_name];
|
|
1805
|
-
if (!_.isUndefined(timestamp)) {
|
|
1806
|
-
delete this['props'][EVENT_TIMERS_KEY][event_name];
|
|
1807
|
-
this.save();
|
|
1808
|
-
}
|
|
1809
|
-
return timestamp
|
|
1810
|
-
};
|
|
1811
|
-
|
|
1812
|
-
class SessionIdManager {
|
|
1813
|
-
constructor(config, persistence) {
|
|
1814
|
-
this.persistence = persistence;
|
|
1815
|
-
this.session_change_threshold = config['persistence_time'] || 1800; // 30 mins
|
|
1816
|
-
// this.session_change_threshold = config['persistence_time'] || 60 // 1 min
|
|
1817
|
-
this.session_change_threshold *= 1000;
|
|
1818
|
-
|
|
1819
|
-
if (config['persistence_name']) {
|
|
1820
|
-
this.window_id_storage_key = 'um_' + config['persistence_name'] + '_window_id';
|
|
1821
|
-
} else {
|
|
1822
|
-
this.window_id_storage_key = 'um_' + config['token'] + '_window_id';
|
|
563
|
+
// with input from Carl Sverre - mail@carlsverre.com
|
|
564
|
+
// with input from PostHog
|
|
565
|
+
// http://dean.edwards.name/weblog/2005/10/add-event/
|
|
566
|
+
// https://gist.github.com/1930440
|
|
567
|
+
/**
|
|
568
|
+
* @param {Object} element
|
|
569
|
+
* @param {string} type
|
|
570
|
+
* @param {function(...*)} handler
|
|
571
|
+
* @param {boolean=} oldSchool
|
|
572
|
+
* @param {boolean=} useCapture
|
|
573
|
+
*/
|
|
574
|
+
var register_event = function (element, type, handler, oldSchool, useCapture) {
|
|
575
|
+
if (!element) {
|
|
576
|
+
getLogger().error('No valid element provided to register_event');
|
|
577
|
+
return;
|
|
1823
578
|
}
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
579
|
+
if (element.addEventListener && !oldSchool) {
|
|
580
|
+
element.addEventListener(type, handler, !!useCapture);
|
|
581
|
+
}
|
|
582
|
+
else {
|
|
583
|
+
var ontype = 'on' + type;
|
|
584
|
+
var old_handler = element[ontype] // can be undefined
|
|
585
|
+
;
|
|
586
|
+
element[ontype] = makeHandler(element, handler, old_handler);
|
|
587
|
+
}
|
|
588
|
+
};
|
|
589
|
+
function makeHandler(element, new_handler, old_handlers) {
|
|
590
|
+
return function (event) {
|
|
591
|
+
event = event || fixEvent(window.event);
|
|
592
|
+
// this basically happens in firefox whenever another script
|
|
593
|
+
// overwrites the onload callback and doesn't pass the event
|
|
594
|
+
// object to previously defined callbacks. All the browsers
|
|
595
|
+
// that don't define window.event implement addEventListener
|
|
596
|
+
// so the dom_loaded handler will still be fired as usual.
|
|
597
|
+
if (!event) {
|
|
598
|
+
return undefined;
|
|
1835
599
|
}
|
|
600
|
+
var ret = true;
|
|
601
|
+
var old_result;
|
|
602
|
+
if (_isFunction(old_handlers)) {
|
|
603
|
+
old_result = old_handlers(event);
|
|
604
|
+
}
|
|
605
|
+
var new_result = new_handler.call(element, event);
|
|
606
|
+
if (false === old_result || false === new_result) {
|
|
607
|
+
ret = false;
|
|
608
|
+
}
|
|
609
|
+
return ret;
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
function fixEvent(event) {
|
|
613
|
+
if (event) {
|
|
614
|
+
event.preventDefault = fixEvent.preventDefault;
|
|
615
|
+
event.stopPropagation = fixEvent.stopPropagation;
|
|
1836
616
|
}
|
|
617
|
+
return event;
|
|
1837
618
|
}
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
619
|
+
fixEvent.preventDefault = function () {
|
|
620
|
+
this.returnValue = false;
|
|
621
|
+
};
|
|
622
|
+
fixEvent.stopPropagation = function () {
|
|
623
|
+
this.cancelBubble = true;
|
|
624
|
+
};
|
|
625
|
+
return register_event;
|
|
626
|
+
})();
|
|
627
|
+
var _safewrap = function (f) {
|
|
628
|
+
return function () {
|
|
629
|
+
var args = [];
|
|
630
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
631
|
+
args[_i] = arguments[_i];
|
|
1842
632
|
}
|
|
1843
|
-
|
|
1844
|
-
|
|
633
|
+
try {
|
|
634
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
635
|
+
// @ts-ignore
|
|
636
|
+
return f.apply(this, args);
|
|
1845
637
|
}
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
_setSessionId(sessionId, timestamp) {
|
|
1852
|
-
if (sessionId !== this.sessionId || timestamp !== this.timestamp) {
|
|
1853
|
-
this.timestamp = timestamp;
|
|
1854
|
-
this.sessionId = sessionId;
|
|
1855
|
-
this.persistence.register({ [SESSION_ID]: [timestamp, sessionId] });
|
|
638
|
+
catch (e) {
|
|
639
|
+
getLogger().error('Implementation error. Please turn on debug and contact support@usermaven.com.', e);
|
|
640
|
+
// if (Config.DEBUG) {
|
|
641
|
+
// getLogger.critical(e)
|
|
642
|
+
// }
|
|
1856
643
|
}
|
|
1857
|
-
}
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
644
|
+
};
|
|
645
|
+
};
|
|
646
|
+
var _safewrap_instance_methods = function (obj) {
|
|
647
|
+
for (var func in obj) {
|
|
648
|
+
if (typeof obj[func] === 'function') {
|
|
649
|
+
obj[func] = _safewrap(obj[func]);
|
|
1862
650
|
}
|
|
1863
|
-
return this.persistence['props'][SESSION_ID] || [0, null]
|
|
1864
651
|
}
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
652
|
+
};
|
|
653
|
+
var COPY_IN_PROGRESS_ATTRIBUTE = typeof Symbol !== 'undefined' ? Symbol('__deepCircularCopyInProgress__') : '__deepCircularCopyInProgress__';
|
|
654
|
+
/**
|
|
655
|
+
* Deep copies an object.
|
|
656
|
+
* It handles cycles by replacing all references to them with `undefined`
|
|
657
|
+
* Also supports customizing native values
|
|
658
|
+
*
|
|
659
|
+
* @param value
|
|
660
|
+
* @param customizer
|
|
661
|
+
* @param [key] if provided this is the object key associated with the value to be copied. It allows the customizer function to have context when it runs
|
|
662
|
+
* @returns {{}|undefined|*}
|
|
663
|
+
*/
|
|
664
|
+
function deepCircularCopy(value, customizer, key) {
|
|
665
|
+
if (value !== Object(value))
|
|
666
|
+
return customizer ? customizer(value, key) : value; // primitive value
|
|
667
|
+
if (value[COPY_IN_PROGRESS_ATTRIBUTE])
|
|
668
|
+
return undefined;
|
|
669
|
+
value[COPY_IN_PROGRESS_ATTRIBUTE] = true;
|
|
670
|
+
var result;
|
|
671
|
+
if (_isArray(value)) {
|
|
672
|
+
result = [];
|
|
673
|
+
_eachArray(value, function (it) {
|
|
674
|
+
result.push(deepCircularCopy(it, customizer));
|
|
675
|
+
});
|
|
1870
676
|
}
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
timestamp = timestamp || new Date().getTime();
|
|
1888
|
-
|
|
1889
|
-
let [lastTimestamp, sessionId] = this._getSessionId();
|
|
1890
|
-
let windowId = this._getWindowId();
|
|
1891
|
-
|
|
1892
|
-
if (!sessionId || (Math.abs(timestamp - lastTimestamp) > this.session_change_threshold)) {
|
|
1893
|
-
sessionId = _.UUID();
|
|
1894
|
-
windowId = _.UUID();
|
|
1895
|
-
} else if (!windowId) {
|
|
1896
|
-
windowId = _.UUID();
|
|
677
|
+
else {
|
|
678
|
+
result = {};
|
|
679
|
+
_each(value, function (val, key) {
|
|
680
|
+
if (key !== COPY_IN_PROGRESS_ATTRIBUTE) {
|
|
681
|
+
result[key] = deepCircularCopy(val, customizer, key);
|
|
682
|
+
}
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
delete value[COPY_IN_PROGRESS_ATTRIBUTE];
|
|
686
|
+
return result;
|
|
687
|
+
}
|
|
688
|
+
var LONG_STRINGS_ALLOW_LIST = ['$performance_raw'];
|
|
689
|
+
function _copyAndTruncateStrings(object, maxStringLength) {
|
|
690
|
+
return deepCircularCopy(object, function (value, key) {
|
|
691
|
+
if (key && LONG_STRINGS_ALLOW_LIST.indexOf(key) > -1) {
|
|
692
|
+
return value;
|
|
1897
693
|
}
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
this._setWindowId(windowId);
|
|
1902
|
-
this._setSessionId(sessionId, newTimestamp);
|
|
1903
|
-
return {
|
|
1904
|
-
session_id: sessionId,
|
|
1905
|
-
window_id: windowId,
|
|
694
|
+
if (typeof value === 'string' && maxStringLength !== null) {
|
|
695
|
+
return value.slice(0, maxStringLength);
|
|
1906
696
|
}
|
|
1907
|
-
|
|
697
|
+
return value;
|
|
698
|
+
});
|
|
1908
699
|
}
|
|
1909
700
|
|
|
1910
701
|
/*
|
|
@@ -1915,15 +706,15 @@ class SessionIdManager {
|
|
|
1915
706
|
function getClassName(el) {
|
|
1916
707
|
switch (typeof el.className) {
|
|
1917
708
|
case 'string':
|
|
1918
|
-
return el.className
|
|
709
|
+
return el.className;
|
|
710
|
+
// TODO: when is this ever used?
|
|
1919
711
|
case 'object': // handle cases where className might be SVGAnimatedString or some other type
|
|
1920
|
-
return el.className.baseVal || el.getAttribute('class') || ''
|
|
712
|
+
return ('baseVal' in el.className ? el.className.baseVal : null) || el.getAttribute('class') || '';
|
|
1921
713
|
default:
|
|
1922
714
|
// future proof
|
|
1923
|
-
return ''
|
|
715
|
+
return '';
|
|
1924
716
|
}
|
|
1925
717
|
}
|
|
1926
|
-
|
|
1927
718
|
/*
|
|
1928
719
|
* Get the direct text content of an element, protecting against sensitive data collection.
|
|
1929
720
|
* Concats textContent of each of the element's text node children; this avoids potential
|
|
@@ -1935,11 +726,10 @@ function getClassName(el) {
|
|
|
1935
726
|
*/
|
|
1936
727
|
function getSafeText(el) {
|
|
1937
728
|
var elText = '';
|
|
1938
|
-
|
|
1939
729
|
if (shouldCaptureElement(el) && !isSensitiveElement(el) && el.childNodes && el.childNodes.length) {
|
|
1940
|
-
|
|
730
|
+
_each(el.childNodes, function (child) {
|
|
1941
731
|
if (isTextNode(child) && child.textContent) {
|
|
1942
|
-
elText +=
|
|
732
|
+
elText += _trim(child.textContent)
|
|
1943
733
|
// scrub potentially sensitive values
|
|
1944
734
|
.split(/(\s+)/)
|
|
1945
735
|
.filter(shouldCaptureValue)
|
|
@@ -1952,19 +742,16 @@ function getSafeText(el) {
|
|
|
1952
742
|
}
|
|
1953
743
|
});
|
|
1954
744
|
}
|
|
1955
|
-
|
|
1956
|
-
return _.trim(elText)
|
|
745
|
+
return _trim(elText);
|
|
1957
746
|
}
|
|
1958
|
-
|
|
1959
747
|
/*
|
|
1960
748
|
* Check whether an element has nodeType Node.ELEMENT_NODE
|
|
1961
749
|
* @param {Element} el - element to check
|
|
1962
750
|
* @returns {boolean} whether el is of the correct nodeType
|
|
1963
751
|
*/
|
|
1964
752
|
function isElementNode(el) {
|
|
1965
|
-
return el && el.nodeType === 1 // Node.ELEMENT_NODE - use integer constant for browser portability
|
|
753
|
+
return !!el && el.nodeType === 1; // Node.ELEMENT_NODE - use integer constant for browser portability
|
|
1966
754
|
}
|
|
1967
|
-
|
|
1968
755
|
/*
|
|
1969
756
|
* Check whether an element is of a given tag type.
|
|
1970
757
|
* Due to potential reference discrepancies (such as the webcomponents.js polyfill),
|
|
@@ -1976,18 +763,24 @@ function isElementNode(el) {
|
|
|
1976
763
|
* @returns {boolean} whether el is of the given tag type
|
|
1977
764
|
*/
|
|
1978
765
|
function isTag(el, tag) {
|
|
1979
|
-
return el && el.tagName && el.tagName.toLowerCase() === tag.toLowerCase()
|
|
766
|
+
return !!el && !!el.tagName && el.tagName.toLowerCase() === tag.toLowerCase();
|
|
1980
767
|
}
|
|
1981
|
-
|
|
1982
768
|
/*
|
|
1983
769
|
* Check whether an element has nodeType Node.TEXT_NODE
|
|
1984
770
|
* @param {Element} el - element to check
|
|
1985
771
|
* @returns {boolean} whether el is of the correct nodeType
|
|
1986
772
|
*/
|
|
1987
773
|
function isTextNode(el) {
|
|
1988
|
-
return el && el.nodeType === 3 // Node.TEXT_NODE - use integer constant for browser portability
|
|
774
|
+
return !!el && el.nodeType === 3; // Node.TEXT_NODE - use integer constant for browser portability
|
|
775
|
+
}
|
|
776
|
+
/*
|
|
777
|
+
* Check whether an element has nodeType Node.DOCUMENT_FRAGMENT_NODE
|
|
778
|
+
* @param {Element} el - element to check
|
|
779
|
+
* @returns {boolean} whether el is of the correct nodeType
|
|
780
|
+
*/
|
|
781
|
+
function isDocumentFragment(el) {
|
|
782
|
+
return !!el && el.nodeType === 11; // Node.DOCUMENT_FRAGMENT_NODE - use integer constant for browser portability
|
|
1989
783
|
}
|
|
1990
|
-
|
|
1991
784
|
var usefulElements = ['a', 'button', 'form', 'input', 'select', 'textarea', 'label'];
|
|
1992
785
|
/*
|
|
1993
786
|
* Check whether a DOM event should be "captured" or if it may contain sentitive data
|
|
@@ -1998,60 +791,56 @@ var usefulElements = ['a', 'button', 'form', 'input', 'select', 'textarea', 'lab
|
|
|
1998
791
|
*/
|
|
1999
792
|
function shouldCaptureDomEvent(el, event) {
|
|
2000
793
|
if (!el || isTag(el, 'html') || !isElementNode(el)) {
|
|
2001
|
-
return false
|
|
794
|
+
return false;
|
|
2002
795
|
}
|
|
2003
|
-
|
|
2004
796
|
var parentIsUsefulElement = false;
|
|
2005
|
-
var targetElementList = [el];
|
|
797
|
+
var targetElementList = [el]; // TODO: remove this var, it's never queried
|
|
2006
798
|
var parentNode = true;
|
|
2007
799
|
var curEl = el;
|
|
2008
800
|
while (curEl.parentNode && !isTag(curEl, 'body')) {
|
|
2009
801
|
// If element is a shadow root, we skip it
|
|
2010
|
-
if (curEl.parentNode
|
|
802
|
+
if (isDocumentFragment(curEl.parentNode)) {
|
|
2011
803
|
targetElementList.push(curEl.parentNode.host);
|
|
2012
804
|
curEl = curEl.parentNode.host;
|
|
2013
|
-
continue
|
|
805
|
+
continue;
|
|
2014
806
|
}
|
|
2015
|
-
parentNode = curEl.parentNode;
|
|
2016
|
-
if (!parentNode)
|
|
807
|
+
parentNode = curEl.parentNode || false;
|
|
808
|
+
if (!parentNode)
|
|
809
|
+
break;
|
|
2017
810
|
if (usefulElements.indexOf(parentNode.tagName.toLowerCase()) > -1) {
|
|
2018
811
|
parentIsUsefulElement = true;
|
|
2019
|
-
}
|
|
2020
|
-
|
|
2021
|
-
|
|
812
|
+
}
|
|
813
|
+
else {
|
|
814
|
+
var compStyles_1 = window.getComputedStyle(parentNode);
|
|
815
|
+
if (compStyles_1 && compStyles_1.getPropertyValue('cursor') === 'pointer') {
|
|
2022
816
|
parentIsUsefulElement = true;
|
|
2023
817
|
}
|
|
2024
818
|
}
|
|
2025
|
-
|
|
2026
819
|
targetElementList.push(parentNode);
|
|
2027
820
|
curEl = parentNode;
|
|
2028
821
|
}
|
|
2029
|
-
|
|
2030
|
-
let compStyles = window.getComputedStyle(el);
|
|
822
|
+
var compStyles = window.getComputedStyle(el);
|
|
2031
823
|
if (compStyles && compStyles.getPropertyValue('cursor') === 'pointer' && event.type === 'click') {
|
|
2032
|
-
return true
|
|
824
|
+
return true;
|
|
2033
825
|
}
|
|
2034
|
-
|
|
2035
826
|
var tag = el.tagName.toLowerCase();
|
|
2036
827
|
switch (tag) {
|
|
2037
828
|
case 'html':
|
|
2038
|
-
return false
|
|
829
|
+
return false;
|
|
2039
830
|
case 'form':
|
|
2040
|
-
return event.type === 'submit'
|
|
831
|
+
return event.type === 'submit';
|
|
2041
832
|
case 'input':
|
|
2042
|
-
return event.type === 'change' || event.type === 'click'
|
|
833
|
+
return event.type === 'change' || event.type === 'click';
|
|
2043
834
|
case 'select':
|
|
2044
835
|
case 'textarea':
|
|
2045
|
-
return event.type === 'change' || event.type === 'click'
|
|
836
|
+
return event.type === 'change' || event.type === 'click';
|
|
2046
837
|
default:
|
|
2047
|
-
if (parentIsUsefulElement)
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
(usefulElements.indexOf(tag) > -1 || el.getAttribute('contenteditable') === 'true')
|
|
2051
|
-
)
|
|
838
|
+
if (parentIsUsefulElement)
|
|
839
|
+
return event.type === 'click';
|
|
840
|
+
return (event.type === 'click' &&
|
|
841
|
+
(usefulElements.indexOf(tag) > -1 || el.getAttribute('contenteditable') === 'true'));
|
|
2052
842
|
}
|
|
2053
843
|
}
|
|
2054
|
-
|
|
2055
844
|
/*
|
|
2056
845
|
* Check whether a DOM element should be "captured" or if it may contain sentitive data
|
|
2057
846
|
* using a variety of heuristics.
|
|
@@ -2061,40 +850,38 @@ function shouldCaptureDomEvent(el, event) {
|
|
|
2061
850
|
function shouldCaptureElement(el) {
|
|
2062
851
|
for (var curEl = el; curEl.parentNode && !isTag(curEl, 'body'); curEl = curEl.parentNode) {
|
|
2063
852
|
var classes = getClassName(curEl).split(' ');
|
|
2064
|
-
if (
|
|
2065
|
-
return false
|
|
853
|
+
if (_includes(classes, 'ph-sensitive') || _includes(classes, 'ph-no-capture')) {
|
|
854
|
+
return false;
|
|
2066
855
|
}
|
|
2067
856
|
}
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
return true
|
|
857
|
+
if (_includes(getClassName(el).split(' '), 'ph-include')) {
|
|
858
|
+
return true;
|
|
2071
859
|
}
|
|
2072
|
-
|
|
2073
860
|
// don't include hidden or password fields
|
|
2074
861
|
var type = el.type || '';
|
|
2075
862
|
if (typeof type === 'string') {
|
|
2076
863
|
// it's possible for el.type to be a DOM element if el is a form with a child input[name="type"]
|
|
2077
864
|
switch (type.toLowerCase()) {
|
|
2078
865
|
case 'hidden':
|
|
2079
|
-
return false
|
|
866
|
+
return false;
|
|
2080
867
|
case 'password':
|
|
2081
|
-
return false
|
|
868
|
+
return false;
|
|
2082
869
|
}
|
|
2083
870
|
}
|
|
2084
|
-
|
|
2085
871
|
// filter out data from fields that look like sensitive fields
|
|
2086
872
|
var name = el.name || el.id || '';
|
|
873
|
+
// See https://github.com/posthog/posthog-js/issues/165
|
|
874
|
+
// Under specific circumstances a bug caused .replace to be called on a DOM element
|
|
875
|
+
// instead of a string, removing the element from the page. Ensure this issue is mitigated.
|
|
2087
876
|
if (typeof name === 'string') {
|
|
2088
877
|
// it's possible for el.name or el.id to be a DOM element if el is a form with a child input[name="name"]
|
|
2089
878
|
var sensitiveNameRegex = /^cc|cardnum|ccnum|creditcard|csc|cvc|cvv|exp|pass|pwd|routing|seccode|securitycode|securitynum|socialsec|socsec|ssn/i;
|
|
2090
879
|
if (sensitiveNameRegex.test(name.replace(/[^a-zA-Z0-9]/g, ''))) {
|
|
2091
|
-
return false
|
|
880
|
+
return false;
|
|
2092
881
|
}
|
|
2093
882
|
}
|
|
2094
|
-
|
|
2095
|
-
return true
|
|
883
|
+
return true;
|
|
2096
884
|
}
|
|
2097
|
-
|
|
2098
885
|
/*
|
|
2099
886
|
* Check whether a DOM element is 'sensitive' and we should only capture limited data
|
|
2100
887
|
* @param {Element} el - element to check
|
|
@@ -2103,18 +890,15 @@ function shouldCaptureElement(el) {
|
|
|
2103
890
|
function isSensitiveElement(el) {
|
|
2104
891
|
// don't send data from inputs or similar elements since there will always be
|
|
2105
892
|
// a risk of clientside javascript placing sensitive data in attributes
|
|
2106
|
-
|
|
2107
|
-
if (
|
|
2108
|
-
(isTag(el, 'input') && !allowedInputTypes.includes(el.type)) ||
|
|
893
|
+
var allowedInputTypes = ['button', 'checkbox', 'submit', 'reset'];
|
|
894
|
+
if ((isTag(el, 'input') && !allowedInputTypes.includes(el.type)) ||
|
|
2109
895
|
isTag(el, 'select') ||
|
|
2110
896
|
isTag(el, 'textarea') ||
|
|
2111
|
-
el.getAttribute('contenteditable') === 'true'
|
|
2112
|
-
|
|
2113
|
-
return true
|
|
897
|
+
el.getAttribute('contenteditable') === 'true') {
|
|
898
|
+
return true;
|
|
2114
899
|
}
|
|
2115
|
-
return false
|
|
900
|
+
return false;
|
|
2116
901
|
}
|
|
2117
|
-
|
|
2118
902
|
/*
|
|
2119
903
|
* Check whether a string value should be "captured" or if it may contain sentitive data
|
|
2120
904
|
* using a variety of heuristics.
|
|
@@ -2122,30 +906,25 @@ function isSensitiveElement(el) {
|
|
|
2122
906
|
* @returns {boolean} whether the element should be captured
|
|
2123
907
|
*/
|
|
2124
908
|
function shouldCaptureValue(value) {
|
|
2125
|
-
if (value === null ||
|
|
2126
|
-
return false
|
|
909
|
+
if (value === null || _isUndefined(value)) {
|
|
910
|
+
return false;
|
|
2127
911
|
}
|
|
2128
|
-
|
|
2129
912
|
if (typeof value === 'string') {
|
|
2130
|
-
value =
|
|
2131
|
-
|
|
913
|
+
value = _trim(value);
|
|
2132
914
|
// check to see if input value looks like a credit card number
|
|
2133
915
|
// see: https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9781449327453/ch04s20.html
|
|
2134
916
|
var ccRegex = /^(?:(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[0-9]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11}))$/;
|
|
2135
917
|
if (ccRegex.test((value || '').replace(/[- ]/g, ''))) {
|
|
2136
|
-
return false
|
|
918
|
+
return false;
|
|
2137
919
|
}
|
|
2138
|
-
|
|
2139
920
|
// check to see if input value looks like a social security number
|
|
2140
921
|
var ssnRegex = /(^\d{3}-?\d{2}-?\d{4}$)/;
|
|
2141
922
|
if (ssnRegex.test(value)) {
|
|
2142
|
-
return false
|
|
923
|
+
return false;
|
|
2143
924
|
}
|
|
2144
925
|
}
|
|
2145
|
-
|
|
2146
|
-
return true
|
|
926
|
+
return true;
|
|
2147
927
|
}
|
|
2148
|
-
|
|
2149
928
|
/*
|
|
2150
929
|
* Check whether an attribute name is an Angular style attr (either _ngcontent or _nghost)
|
|
2151
930
|
* These update on each build and lead to noise in the element chain
|
|
@@ -2155,69 +934,58 @@ function shouldCaptureValue(value) {
|
|
|
2155
934
|
*/
|
|
2156
935
|
function isAngularStyleAttr(attributeName) {
|
|
2157
936
|
if (typeof attributeName === 'string') {
|
|
2158
|
-
return attributeName.substring(0, 10) === '_ngcontent' || attributeName.substring(0, 7) === '_nghost'
|
|
2159
|
-
}
|
|
2160
|
-
return false
|
|
2161
|
-
}
|
|
2162
|
-
|
|
2163
|
-
function isDataAttribute(attributeName)
|
|
2164
|
-
{
|
|
2165
|
-
if (typeof attributeName === 'string') {
|
|
2166
|
-
return attributeName.startsWith('data-')
|
|
937
|
+
return attributeName.substring(0, 10) === '_ngcontent' || attributeName.substring(0, 7) === '_nghost';
|
|
2167
938
|
}
|
|
2168
|
-
return false
|
|
939
|
+
return false;
|
|
2169
940
|
}
|
|
2170
941
|
|
|
2171
942
|
// Naive rage click implementation: If mouse has not moved than RAGE_CLICK_THRESHOLD_PX
|
|
2172
943
|
// over RAGE_CLICK_CLICK_COUNT clicks with max RAGE_CLICK_TIMEOUT_MS between clicks, it's
|
|
2173
944
|
// counted as a rage click
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
945
|
+
var RAGE_CLICK_THRESHOLD_PX = 30;
|
|
946
|
+
var RAGE_CLICK_TIMEOUT_MS = 1000;
|
|
947
|
+
var RAGE_CLICK_CLICK_COUNT = 3;
|
|
948
|
+
var RageClick = /** @class */ (function () {
|
|
949
|
+
function RageClick(instance, enabled) {
|
|
950
|
+
if (enabled === void 0) { enabled = false; }
|
|
2180
951
|
this.clicks = [];
|
|
2181
952
|
this.instance = instance;
|
|
2182
953
|
this.enabled = enabled;
|
|
2183
954
|
}
|
|
2184
|
-
|
|
2185
|
-
click(x, y, timestamp) {
|
|
955
|
+
RageClick.prototype.click = function (x, y, timestamp) {
|
|
2186
956
|
if (!this.enabled) {
|
|
2187
|
-
return
|
|
957
|
+
return;
|
|
2188
958
|
}
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
if (
|
|
2192
|
-
lastClick &&
|
|
959
|
+
var lastClick = this.clicks[this.clicks.length - 1];
|
|
960
|
+
if (lastClick &&
|
|
2193
961
|
Math.abs(x - lastClick.x) + Math.abs(y - lastClick.y) < RAGE_CLICK_THRESHOLD_PX &&
|
|
2194
|
-
timestamp - lastClick.timestamp < RAGE_CLICK_TIMEOUT_MS
|
|
2195
|
-
|
|
2196
|
-
this.clicks.push({ x, y, timestamp });
|
|
2197
|
-
|
|
962
|
+
timestamp - lastClick.timestamp < RAGE_CLICK_TIMEOUT_MS) {
|
|
963
|
+
this.clicks.push({ x: x, y: y, timestamp: timestamp });
|
|
2198
964
|
if (this.clicks.length === RAGE_CLICK_CLICK_COUNT) {
|
|
2199
965
|
this.instance.capture('$rageclick');
|
|
2200
966
|
}
|
|
2201
|
-
} else {
|
|
2202
|
-
this.clicks = [{ x, y, timestamp }];
|
|
2203
967
|
}
|
|
2204
|
-
|
|
2205
|
-
}
|
|
968
|
+
else {
|
|
969
|
+
this.clicks = [{ x: x, y: y, timestamp: timestamp }];
|
|
970
|
+
}
|
|
971
|
+
};
|
|
972
|
+
return RageClick;
|
|
973
|
+
}());
|
|
2206
974
|
|
|
2207
975
|
var autocapture = {
|
|
2208
976
|
_initializedTokens: [],
|
|
2209
|
-
|
|
2210
977
|
_previousElementSibling: function (el) {
|
|
2211
978
|
if (el.previousElementSibling) {
|
|
2212
|
-
return el.previousElementSibling
|
|
2213
|
-
}
|
|
979
|
+
return el.previousElementSibling;
|
|
980
|
+
}
|
|
981
|
+
else {
|
|
982
|
+
var _el = el;
|
|
2214
983
|
do {
|
|
2215
|
-
|
|
2216
|
-
} while (
|
|
2217
|
-
return
|
|
984
|
+
_el = _el.previousSibling; // resolves to ChildNode->Node, which is Element's parent class
|
|
985
|
+
} while (_el && !isElementNode(_el));
|
|
986
|
+
return _el;
|
|
2218
987
|
}
|
|
2219
988
|
},
|
|
2220
|
-
|
|
2221
989
|
_getPropertiesFromElement: function (elem, maskInputs, maskText) {
|
|
2222
990
|
var tag_name = elem.tagName.toLowerCase();
|
|
2223
991
|
var props = {
|
|
@@ -2226,22 +994,19 @@ var autocapture = {
|
|
|
2226
994
|
if (usefulElements.indexOf(tag_name) > -1 && !maskText) {
|
|
2227
995
|
props['$el_text'] = getSafeText(elem);
|
|
2228
996
|
}
|
|
2229
|
-
|
|
2230
997
|
var classes = getClassName(elem);
|
|
2231
998
|
if (classes.length > 0)
|
|
2232
999
|
props['classes'] = classes.split(' ').filter(function (c) {
|
|
2233
|
-
return c !== ''
|
|
1000
|
+
return c !== '';
|
|
2234
1001
|
});
|
|
2235
|
-
|
|
2236
|
-
_.each(elem.attributes, function (attr) {
|
|
1002
|
+
_each(elem.attributes, function (attr) {
|
|
2237
1003
|
// Only capture attributes we know are safe
|
|
2238
|
-
if (isSensitiveElement(elem) && ['name', 'id', 'class'].indexOf(attr.name) === -1)
|
|
2239
|
-
|
|
2240
|
-
if (!maskInputs && shouldCaptureValue(attr.value) && !isAngularStyleAttr(attr.name)
|
|
1004
|
+
if (isSensitiveElement(elem) && ['name', 'id', 'class'].indexOf(attr.name) === -1)
|
|
1005
|
+
return;
|
|
1006
|
+
if (!maskInputs && shouldCaptureValue(attr.value) && !isAngularStyleAttr(attr.name)) {
|
|
2241
1007
|
props['attr__' + attr.name] = attr.value;
|
|
2242
1008
|
}
|
|
2243
1009
|
});
|
|
2244
|
-
|
|
2245
1010
|
var nthChild = 1;
|
|
2246
1011
|
var nthOfType = 1;
|
|
2247
1012
|
var currentElem = elem;
|
|
@@ -2254,219 +1019,178 @@ var autocapture = {
|
|
|
2254
1019
|
}
|
|
2255
1020
|
props['nth_child'] = nthChild;
|
|
2256
1021
|
props['nth_of_type'] = nthOfType;
|
|
2257
|
-
|
|
2258
|
-
return props
|
|
1022
|
+
return props;
|
|
2259
1023
|
},
|
|
2260
|
-
|
|
2261
1024
|
_getDefaultProperties: function (eventType) {
|
|
2262
1025
|
return {
|
|
2263
1026
|
$event_type: eventType,
|
|
2264
1027
|
$ce_version: 1,
|
|
2265
|
-
}
|
|
1028
|
+
};
|
|
2266
1029
|
},
|
|
2267
|
-
|
|
2268
1030
|
_extractCustomPropertyValue: function (customProperty) {
|
|
2269
1031
|
var propValues = [];
|
|
2270
|
-
|
|
1032
|
+
_each(document.querySelectorAll(customProperty['css_selector']), function (matchedElem) {
|
|
2271
1033
|
var value;
|
|
2272
|
-
|
|
2273
1034
|
if (['input', 'select'].indexOf(matchedElem.tagName.toLowerCase()) > -1) {
|
|
2274
1035
|
value = matchedElem['value'];
|
|
2275
|
-
}
|
|
1036
|
+
}
|
|
1037
|
+
else if (matchedElem['textContent']) {
|
|
2276
1038
|
value = matchedElem['textContent'];
|
|
2277
1039
|
}
|
|
2278
|
-
|
|
2279
1040
|
if (shouldCaptureValue(value)) {
|
|
2280
1041
|
propValues.push(value);
|
|
2281
1042
|
}
|
|
2282
1043
|
});
|
|
2283
|
-
return propValues.join(', ')
|
|
1044
|
+
return propValues.join(', ');
|
|
2284
1045
|
},
|
|
2285
|
-
|
|
1046
|
+
// TODO: delete custom_properties after changeless typescript refactor
|
|
2286
1047
|
_getCustomProperties: function (targetElementList) {
|
|
2287
|
-
var
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
function (
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
}
|
|
2301
|
-
},
|
|
2302
|
-
this
|
|
2303
|
-
);
|
|
2304
|
-
},
|
|
2305
|
-
this
|
|
2306
|
-
);
|
|
2307
|
-
},
|
|
2308
|
-
this
|
|
2309
|
-
);
|
|
2310
|
-
return props
|
|
1048
|
+
var _this = this;
|
|
1049
|
+
var props = {}; // will be deleted
|
|
1050
|
+
_each(this._customProperties, function (customProperty) {
|
|
1051
|
+
_each(customProperty['event_selectors'], function (eventSelector) {
|
|
1052
|
+
var eventElements = document.querySelectorAll(eventSelector);
|
|
1053
|
+
_each(eventElements, function (eventElement) {
|
|
1054
|
+
if (_includes(targetElementList, eventElement) && shouldCaptureElement(eventElement)) {
|
|
1055
|
+
props[customProperty['name']] = _this._extractCustomPropertyValue(customProperty);
|
|
1056
|
+
}
|
|
1057
|
+
});
|
|
1058
|
+
});
|
|
1059
|
+
});
|
|
1060
|
+
return props;
|
|
2311
1061
|
},
|
|
2312
|
-
|
|
2313
1062
|
_getEventTarget: function (e) {
|
|
1063
|
+
var _a;
|
|
2314
1064
|
// https://developer.mozilla.org/en-US/docs/Web/API/Event/target#Compatibility_notes
|
|
2315
1065
|
if (typeof e.target === 'undefined') {
|
|
2316
|
-
return e.srcElement
|
|
2317
|
-
}
|
|
2318
|
-
|
|
2319
|
-
|
|
1066
|
+
return e.srcElement || null;
|
|
1067
|
+
}
|
|
1068
|
+
else {
|
|
1069
|
+
if ((_a = e.target) === null || _a === void 0 ? void 0 : _a.shadowRoot) {
|
|
1070
|
+
return e.composedPath()[0] || null;
|
|
2320
1071
|
}
|
|
2321
|
-
return e.target
|
|
1072
|
+
return e.target || null;
|
|
2322
1073
|
}
|
|
2323
1074
|
},
|
|
2324
|
-
|
|
2325
|
-
|
|
1075
|
+
_captureEvent: function (e, instance, opts) {
|
|
1076
|
+
var _this = this;
|
|
1077
|
+
var _a;
|
|
2326
1078
|
/*** Don't mess with this code without running IE8 tests on it ***/
|
|
2327
1079
|
var target = this._getEventTarget(e);
|
|
2328
1080
|
if (isTextNode(target)) {
|
|
2329
1081
|
// defeat Safari bug (see: http://www.quirksmode.org/js/events_properties.html)
|
|
2330
|
-
target = target.parentNode;
|
|
1082
|
+
target = (target.parentNode || null);
|
|
2331
1083
|
}
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
this.rageclicks.click(e.clientX, e.clientY, new Date().getTime());
|
|
1084
|
+
if (e.type === 'click' && e instanceof MouseEvent) {
|
|
1085
|
+
(_a = this.rageclicks) === null || _a === void 0 ? void 0 : _a.click(e.clientX, e.clientY, new Date().getTime());
|
|
2335
1086
|
}
|
|
2336
|
-
|
|
2337
|
-
if (shouldCaptureDomEvent(target, e)) {
|
|
1087
|
+
if (target && shouldCaptureDomEvent(target, e)) {
|
|
2338
1088
|
var targetElementList = [target];
|
|
2339
1089
|
var curEl = target;
|
|
2340
1090
|
while (curEl.parentNode && !isTag(curEl, 'body')) {
|
|
2341
|
-
if (curEl.parentNode
|
|
1091
|
+
if (isDocumentFragment(curEl.parentNode)) {
|
|
2342
1092
|
targetElementList.push(curEl.parentNode.host);
|
|
2343
1093
|
curEl = curEl.parentNode.host;
|
|
2344
|
-
continue
|
|
1094
|
+
continue;
|
|
2345
1095
|
}
|
|
2346
1096
|
targetElementList.push(curEl.parentNode);
|
|
2347
1097
|
curEl = curEl.parentNode;
|
|
2348
1098
|
}
|
|
2349
|
-
|
|
2350
|
-
var
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
explicitNoCapture = true;
|
|
2369
|
-
}
|
|
2370
|
-
|
|
2371
|
-
elementsJson.push(
|
|
2372
|
-
this._getPropertiesFromElement(
|
|
2373
|
-
el,
|
|
2374
|
-
instance.get_config('mask_all_element_attributes'),
|
|
2375
|
-
instance.get_config('mask_all_text')
|
|
2376
|
-
)
|
|
2377
|
-
);
|
|
2378
|
-
},
|
|
2379
|
-
this
|
|
2380
|
-
);
|
|
2381
|
-
|
|
2382
|
-
if (!instance.get_config('mask_all_text')) {
|
|
2383
|
-
elementsJson[0]['$el_text'] = getSafeText(target);
|
|
1099
|
+
var elementsJson_1 = [];
|
|
1100
|
+
var href_1, explicitNoCapture_1 = false;
|
|
1101
|
+
_each(targetElementList, function (el) {
|
|
1102
|
+
var shouldCaptureEl = shouldCaptureElement(el);
|
|
1103
|
+
// if the element or a parent element is an anchor tag
|
|
1104
|
+
// include the href as a property
|
|
1105
|
+
if (el.tagName.toLowerCase() === 'a') {
|
|
1106
|
+
href_1 = el.getAttribute('href');
|
|
1107
|
+
href_1 = shouldCaptureEl && shouldCaptureValue(href_1) && href_1;
|
|
1108
|
+
}
|
|
1109
|
+
// allow users to programmatically prevent capturing of elements by adding class 'ph-no-capture'
|
|
1110
|
+
var classes = getClassName(el).split(' ');
|
|
1111
|
+
if (_includes(classes, 'ph-no-capture')) {
|
|
1112
|
+
explicitNoCapture_1 = true;
|
|
1113
|
+
}
|
|
1114
|
+
elementsJson_1.push(_this._getPropertiesFromElement(el, opts === null || opts === void 0 ? void 0 : opts.mask_all_element_attributes, opts === null || opts === void 0 ? void 0 : opts.mask_all_text));
|
|
1115
|
+
});
|
|
1116
|
+
if (!(opts === null || opts === void 0 ? void 0 : opts.mask_all_text)) {
|
|
1117
|
+
elementsJson_1[0]['$el_text'] = getSafeText(target);
|
|
2384
1118
|
}
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
elementsJson[0]['attr__href'] = href;
|
|
1119
|
+
if (href_1) {
|
|
1120
|
+
elementsJson_1[0]['attr__href'] = href_1;
|
|
2388
1121
|
}
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
return false
|
|
1122
|
+
if (explicitNoCapture_1) {
|
|
1123
|
+
return false;
|
|
2392
1124
|
}
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
{
|
|
2397
|
-
$elements: elementsJson,
|
|
2398
|
-
},
|
|
2399
|
-
this._getCustomProperties(targetElementList)
|
|
2400
|
-
);
|
|
2401
|
-
|
|
1125
|
+
var props = _extend(this._getDefaultProperties(e.type), {
|
|
1126
|
+
$elements: elementsJson_1,
|
|
1127
|
+
}, this._getCustomProperties(targetElementList));
|
|
2402
1128
|
instance.capture('$autocapture', props);
|
|
2403
|
-
return true
|
|
1129
|
+
return true;
|
|
2404
1130
|
}
|
|
2405
1131
|
},
|
|
2406
|
-
|
|
2407
1132
|
// only reason is to stub for unit tests
|
|
2408
1133
|
// since you can't override window.location props
|
|
2409
1134
|
_navigate: function (href) {
|
|
2410
1135
|
window.location.href = href;
|
|
2411
1136
|
},
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
var handler =
|
|
1137
|
+
_addDomEventHandlers: function (instance, opts) {
|
|
1138
|
+
var _this = this;
|
|
1139
|
+
var handler = function (e) {
|
|
2415
1140
|
e = e || window.event;
|
|
2416
|
-
|
|
2417
|
-
}
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
1141
|
+
_this._captureEvent(e, instance, opts);
|
|
1142
|
+
};
|
|
1143
|
+
_register_event(document, 'submit', handler, false, true);
|
|
1144
|
+
_register_event(document, 'change', handler, false, true);
|
|
1145
|
+
_register_event(document, 'click', handler, false, true);
|
|
2421
1146
|
},
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
if (this._initializedTokens.indexOf(token) > -1) {
|
|
2428
|
-
console.log('autocapture already initialized for token "' + token + '"');
|
|
2429
|
-
return
|
|
2430
|
-
}
|
|
2431
|
-
|
|
2432
|
-
this._initializedTokens.push(token);
|
|
2433
|
-
|
|
2434
|
-
if (instance.get_config('autocapture')) {
|
|
2435
|
-
this._addDomEventHandlers(instance);
|
|
2436
|
-
} else {
|
|
2437
|
-
instance['__autocapture_enabled'] = false;
|
|
2438
|
-
}
|
|
2439
|
-
|
|
1147
|
+
_customProperties: [],
|
|
1148
|
+
rageclicks: null,
|
|
1149
|
+
opts: {},
|
|
1150
|
+
init: function (instance, opts) {
|
|
1151
|
+
var _this = this;
|
|
2440
1152
|
this.rageclicks = new RageClick(instance);
|
|
1153
|
+
this.opts = opts;
|
|
1154
|
+
if (!(document && document.body)) {
|
|
1155
|
+
console.log('document not ready yet, trying again in 500 milliseconds...');
|
|
1156
|
+
setTimeout(function () {
|
|
1157
|
+
_this.readyAutocapture(instance, opts);
|
|
1158
|
+
}, 500);
|
|
1159
|
+
return;
|
|
1160
|
+
}
|
|
1161
|
+
this.readyAutocapture(instance, opts);
|
|
1162
|
+
},
|
|
1163
|
+
readyAutocapture: function (instance, opts) {
|
|
1164
|
+
this._addDomEventHandlers(instance, opts);
|
|
2441
1165
|
},
|
|
2442
|
-
|
|
2443
1166
|
// this is a mechanism to ramp up CE with no server-side interaction.
|
|
2444
1167
|
// when CE is active, every page load results in a decide request. we
|
|
2445
1168
|
// need to gently ramp this up so we don't overload decide. this decides
|
|
2446
1169
|
// deterministically if CE is enabled for this project by modding the char
|
|
2447
1170
|
// value of the project token.
|
|
2448
1171
|
enabledForProject: function (token, numBuckets, numEnabledBuckets) {
|
|
2449
|
-
|
|
2450
|
-
|
|
1172
|
+
if (!token) {
|
|
1173
|
+
return true;
|
|
1174
|
+
}
|
|
1175
|
+
numBuckets = !_isUndefined(numBuckets) ? numBuckets : 10;
|
|
1176
|
+
numEnabledBuckets = !_isUndefined(numEnabledBuckets) ? numEnabledBuckets : 10;
|
|
2451
1177
|
var charCodeSum = 0;
|
|
2452
1178
|
for (var i = 0; i < token.length; i++) {
|
|
2453
1179
|
charCodeSum += token.charCodeAt(i);
|
|
2454
1180
|
}
|
|
2455
|
-
return charCodeSum % numBuckets < numEnabledBuckets
|
|
1181
|
+
return charCodeSum % numBuckets < numEnabledBuckets;
|
|
2456
1182
|
},
|
|
2457
|
-
|
|
2458
1183
|
isBrowserSupported: function () {
|
|
2459
|
-
return
|
|
1184
|
+
return _isFunction(document.querySelectorAll);
|
|
2460
1185
|
},
|
|
2461
1186
|
};
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
_.safewrap_instance_methods(autocapture);
|
|
1187
|
+
_bind_instance_methods(autocapture);
|
|
1188
|
+
_safewrap_instance_methods(autocapture);
|
|
2465
1189
|
|
|
2466
1190
|
var VERSION_INFO = {
|
|
2467
1191
|
env: 'production',
|
|
2468
|
-
date: '2022-
|
|
2469
|
-
version: '1.
|
|
1192
|
+
date: '2022-09-03T14:16:30.304Z',
|
|
1193
|
+
version: '1.1.1'
|
|
2470
1194
|
};
|
|
2471
1195
|
var USERMAVEN_VERSION = "".concat(VERSION_INFO.version, "/").concat(VERSION_INFO.env, "@").concat(VERSION_INFO.date);
|
|
2472
1196
|
var MAX_AGE_TEN_YEARS = 31622400 * 10;
|
|
@@ -2789,33 +1513,53 @@ var fetchTransport = function (fetch) {
|
|
|
2789
1513
|
return function (url, jsonPayload, additionalHeaders, handler) {
|
|
2790
1514
|
if (handler === void 0) { handler = function (code, body) { }; }
|
|
2791
1515
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
2792
|
-
var res, e_1, resJson;
|
|
2793
|
-
|
|
2794
|
-
|
|
1516
|
+
var res, e_1, resJson, text, contentType, e_2;
|
|
1517
|
+
var _a, _b;
|
|
1518
|
+
return __generator(this, function (_c) {
|
|
1519
|
+
switch (_c.label) {
|
|
2795
1520
|
case 0:
|
|
2796
|
-
|
|
1521
|
+
_c.trys.push([0, 2, , 3]);
|
|
2797
1522
|
return [4 /*yield*/, fetch(url, {
|
|
2798
1523
|
method: "POST",
|
|
2799
1524
|
headers: __assign({ Accept: "application/json", "Content-Type": "application/json" }, (additionalHeaders || {})),
|
|
2800
1525
|
body: jsonPayload,
|
|
2801
1526
|
})];
|
|
2802
1527
|
case 1:
|
|
2803
|
-
res =
|
|
1528
|
+
res = _c.sent();
|
|
2804
1529
|
return [3 /*break*/, 3];
|
|
2805
1530
|
case 2:
|
|
2806
|
-
e_1 =
|
|
1531
|
+
e_1 = _c.sent();
|
|
2807
1532
|
getLogger().error("Failed to send", jsonPayload, e_1);
|
|
2808
1533
|
handler(-1, {});
|
|
2809
|
-
|
|
1534
|
+
return [2 /*return*/];
|
|
2810
1535
|
case 3:
|
|
2811
1536
|
if (res.status !== 200) {
|
|
2812
1537
|
getLogger().warn("Failed to send data to ".concat(url, " (#").concat(res.status, " - ").concat(res.statusText, ")"), jsonPayload);
|
|
2813
|
-
|
|
1538
|
+
handler(res.status, {});
|
|
1539
|
+
return [2 /*return*/];
|
|
2814
1540
|
}
|
|
2815
|
-
|
|
1541
|
+
resJson = {};
|
|
1542
|
+
text = "";
|
|
1543
|
+
contentType = (_b = (_a = res.headers) === null || _a === void 0 ? void 0 : _a.get('Content-Type')) !== null && _b !== void 0 ? _b : "";
|
|
1544
|
+
_c.label = 4;
|
|
2816
1545
|
case 4:
|
|
2817
|
-
|
|
2818
|
-
|
|
1546
|
+
_c.trys.push([4, 6, , 7]);
|
|
1547
|
+
return [4 /*yield*/, res.text()];
|
|
1548
|
+
case 5:
|
|
1549
|
+
text = _c.sent();
|
|
1550
|
+
resJson = JSON.parse(text);
|
|
1551
|
+
return [3 /*break*/, 7];
|
|
1552
|
+
case 6:
|
|
1553
|
+
e_2 = _c.sent();
|
|
1554
|
+
getLogger().error("Failed to parse ".concat(url, " response. Content-type: ").concat(contentType, " text: ").concat(text), e_2);
|
|
1555
|
+
return [3 /*break*/, 7];
|
|
1556
|
+
case 7:
|
|
1557
|
+
try {
|
|
1558
|
+
handler(res.status, resJson);
|
|
1559
|
+
}
|
|
1560
|
+
catch (e) {
|
|
1561
|
+
getLogger().error("Failed to handle ".concat(url, " response. Content-type: ").concat(contentType, " text: ").concat(text), e);
|
|
1562
|
+
}
|
|
2819
1563
|
return [2 /*return*/];
|
|
2820
1564
|
}
|
|
2821
1565
|
});
|
|
@@ -2841,6 +1585,14 @@ var UsermavenClientImpl = /** @class */ (function () {
|
|
|
2841
1585
|
this.beaconApi = false;
|
|
2842
1586
|
this.transport = xmlHttpTransport;
|
|
2843
1587
|
this.customHeaders = function () { return ({}); };
|
|
1588
|
+
this.queue = new MemoryQueue();
|
|
1589
|
+
this.maxSendAttempts = 4;
|
|
1590
|
+
this.retryTimeout = [500, 1e12];
|
|
1591
|
+
this.flushing = false;
|
|
1592
|
+
this.attempt = 1;
|
|
1593
|
+
this.propertyBlacklist = [];
|
|
1594
|
+
// public persistence?: UserMavenPersistence;
|
|
1595
|
+
// public sessionManager?: SessionIdManager;
|
|
2844
1596
|
this.__autocapture_enabled = false;
|
|
2845
1597
|
}
|
|
2846
1598
|
// private anonymousId: string = '';
|
|
@@ -2895,6 +1647,24 @@ var UsermavenClientImpl = /** @class */ (function () {
|
|
|
2895
1647
|
return this.sendJson(e);
|
|
2896
1648
|
};
|
|
2897
1649
|
UsermavenClientImpl.prototype.sendJson = function (json) {
|
|
1650
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
1651
|
+
return __generator(this, function (_a) {
|
|
1652
|
+
switch (_a.label) {
|
|
1653
|
+
case 0:
|
|
1654
|
+
if (!(this.maxSendAttempts > 1)) return [3 /*break*/, 1];
|
|
1655
|
+
this.queue.push([json, 0]);
|
|
1656
|
+
this.scheduleFlush(0);
|
|
1657
|
+
return [3 /*break*/, 3];
|
|
1658
|
+
case 1: return [4 /*yield*/, this.doSendJson(json)];
|
|
1659
|
+
case 2:
|
|
1660
|
+
_a.sent();
|
|
1661
|
+
_a.label = 3;
|
|
1662
|
+
case 3: return [2 /*return*/];
|
|
1663
|
+
}
|
|
1664
|
+
});
|
|
1665
|
+
});
|
|
1666
|
+
};
|
|
1667
|
+
UsermavenClientImpl.prototype.doSendJson = function (json) {
|
|
2898
1668
|
var _this = this;
|
|
2899
1669
|
var cookiePolicy = this.cookiePolicy !== "keep" ? "&cookie_policy=".concat(this.cookiePolicy) : "";
|
|
2900
1670
|
var ipPolicy = this.ipPolicy !== "keep" ? "&ip_policy=".concat(this.ipPolicy) : "";
|
|
@@ -2909,6 +1679,68 @@ var UsermavenClientImpl = /** @class */ (function () {
|
|
|
2909
1679
|
return _this.postHandle(code, body);
|
|
2910
1680
|
});
|
|
2911
1681
|
};
|
|
1682
|
+
UsermavenClientImpl.prototype.scheduleFlush = function (timeout) {
|
|
1683
|
+
var _this = this;
|
|
1684
|
+
if (this.flushing) {
|
|
1685
|
+
return;
|
|
1686
|
+
}
|
|
1687
|
+
this.flushing = true;
|
|
1688
|
+
if (typeof timeout === "undefined") {
|
|
1689
|
+
var random = Math.random() + 1;
|
|
1690
|
+
var factor = Math.pow(2, this.attempt++);
|
|
1691
|
+
timeout = Math.min(this.retryTimeout[0] * random * factor, this.retryTimeout[1]);
|
|
1692
|
+
}
|
|
1693
|
+
getLogger().debug("Scheduling event queue flush in ".concat(timeout, " ms."));
|
|
1694
|
+
setTimeout(function () { return _this.flush(); }, timeout);
|
|
1695
|
+
};
|
|
1696
|
+
UsermavenClientImpl.prototype.flush = function () {
|
|
1697
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
1698
|
+
var queue;
|
|
1699
|
+
var _a;
|
|
1700
|
+
var _this = this;
|
|
1701
|
+
return __generator(this, function (_b) {
|
|
1702
|
+
switch (_b.label) {
|
|
1703
|
+
case 0:
|
|
1704
|
+
if (isWindowAvailable() && !window.navigator.onLine) {
|
|
1705
|
+
this.flushing = false;
|
|
1706
|
+
this.scheduleFlush();
|
|
1707
|
+
}
|
|
1708
|
+
queue = this.queue.flush();
|
|
1709
|
+
this.flushing = false;
|
|
1710
|
+
if (queue.length === 0) {
|
|
1711
|
+
return [2 /*return*/];
|
|
1712
|
+
}
|
|
1713
|
+
_b.label = 1;
|
|
1714
|
+
case 1:
|
|
1715
|
+
_b.trys.push([1, 3, , 4]);
|
|
1716
|
+
return [4 /*yield*/, this.doSendJson(queue.map(function (el) { return el[0]; }))];
|
|
1717
|
+
case 2:
|
|
1718
|
+
_b.sent();
|
|
1719
|
+
this.attempt = 1;
|
|
1720
|
+
getLogger().debug("Successfully flushed ".concat(queue.length, " events from queue"));
|
|
1721
|
+
return [3 /*break*/, 4];
|
|
1722
|
+
case 3:
|
|
1723
|
+
_b.sent();
|
|
1724
|
+
queue = queue.map(function (el) { return [el[0], el[1] + 1]; }).filter(function (el) {
|
|
1725
|
+
if (el[1] >= _this.maxSendAttempts) {
|
|
1726
|
+
getLogger().error("Dropping queued event after ".concat(el[1], " attempts since max send attempts ").concat(_this.maxSendAttempts, " reached. See logs for details"));
|
|
1727
|
+
return false;
|
|
1728
|
+
}
|
|
1729
|
+
return true;
|
|
1730
|
+
});
|
|
1731
|
+
if (queue.length > 0) {
|
|
1732
|
+
(_a = this.queue).push.apply(_a, queue);
|
|
1733
|
+
this.scheduleFlush();
|
|
1734
|
+
}
|
|
1735
|
+
else {
|
|
1736
|
+
this.attempt = 1;
|
|
1737
|
+
}
|
|
1738
|
+
return [3 /*break*/, 4];
|
|
1739
|
+
case 4: return [2 /*return*/];
|
|
1740
|
+
}
|
|
1741
|
+
});
|
|
1742
|
+
});
|
|
1743
|
+
};
|
|
2912
1744
|
UsermavenClientImpl.prototype.postHandle = function (status, response) {
|
|
2913
1745
|
if (this.cookiePolicy === "strict" || this.cookiePolicy === "comply") {
|
|
2914
1746
|
if (status === 200) {
|
|
@@ -2954,10 +1786,9 @@ var UsermavenClientImpl = /** @class */ (function () {
|
|
|
2954
1786
|
UsermavenClientImpl.prototype.getCtx = function (env) {
|
|
2955
1787
|
var now = new Date();
|
|
2956
1788
|
var props = env.describeClient() || {};
|
|
2957
|
-
var _a = this.sessionManager.getSessionAndWindowId(), session_id = _a.session_id, window_id = _a.window_id;
|
|
2958
1789
|
var company = this.userProperties['company'] || {};
|
|
2959
1790
|
delete this.userProperties['company'];
|
|
2960
|
-
var payload = __assign(__assign({ event_id: "",
|
|
1791
|
+
var payload = __assign(__assign({ event_id: "", user: __assign({ anonymous_id: this.cookiePolicy !== "strict"
|
|
2961
1792
|
? env.getAnonymousId({
|
|
2962
1793
|
name: this.idCookieName,
|
|
2963
1794
|
domain: this.cookieDomain,
|
|
@@ -2991,7 +1822,7 @@ var UsermavenClientImpl = /** @class */ (function () {
|
|
|
2991
1822
|
};
|
|
2992
1823
|
UsermavenClientImpl.prototype.init = function (options) {
|
|
2993
1824
|
var _this = this;
|
|
2994
|
-
var _a, _b;
|
|
1825
|
+
var _a, _b, _c, _d;
|
|
2995
1826
|
if (isWindowAvailable() && !options.force_use_fetch) {
|
|
2996
1827
|
if (options.fetch) {
|
|
2997
1828
|
getLogger().warn("Custom fetch implementation is provided to Usermaven. However, it will be ignored since Usermaven runs in browser");
|
|
@@ -3078,21 +1909,17 @@ var UsermavenClientImpl = /** @class */ (function () {
|
|
|
3078
1909
|
}
|
|
3079
1910
|
getLogger().debug("Restored persistent properties", this.permanentProperties);
|
|
3080
1911
|
}
|
|
3081
|
-
|
|
1912
|
+
this.propertyBlacklist = options.property_blacklist && options.property_blacklist.length > 0 ? options.property_blacklist : [];
|
|
1913
|
+
// // Added these configuration for session management + autocapture
|
|
3082
1914
|
var defaultConfig = {
|
|
3083
|
-
persistence: 'cookie',
|
|
3084
|
-
persistence_name: 'session',
|
|
3085
1915
|
autocapture: false,
|
|
3086
|
-
capture_pageview: true,
|
|
3087
|
-
store_google: false,
|
|
3088
|
-
save_referrer: false,
|
|
3089
1916
|
properties_string_max_length: null,
|
|
3090
1917
|
property_blacklist: [],
|
|
3091
1918
|
sanitize_properties: null
|
|
3092
1919
|
};
|
|
3093
|
-
this.config =
|
|
1920
|
+
this.config = _extend({}, defaultConfig, options || {}, this.config || {}, { token: this.apiKey });
|
|
3094
1921
|
getLogger().debug('Default Configuration', this.config);
|
|
3095
|
-
this.manageSession(this.config);
|
|
1922
|
+
// this.manageSession(this.config);
|
|
3096
1923
|
this.manageAutoCapture(this.config);
|
|
3097
1924
|
if (options.capture_3rd_party_cookies === false) {
|
|
3098
1925
|
this._3pCookies = {};
|
|
@@ -3112,9 +1939,21 @@ var UsermavenClientImpl = /** @class */ (function () {
|
|
|
3112
1939
|
if (options.segment_hook) {
|
|
3113
1940
|
interceptSegmentCalls(this);
|
|
3114
1941
|
}
|
|
1942
|
+
if (isWindowAvailable()) {
|
|
1943
|
+
if (!options.disable_event_persistence) {
|
|
1944
|
+
this.queue = new LocalStorageQueue("jitsu-event-queue");
|
|
1945
|
+
this.scheduleFlush(0);
|
|
1946
|
+
}
|
|
1947
|
+
window.addEventListener("beforeunload", function () { return _this.flush(); });
|
|
1948
|
+
}
|
|
1949
|
+
this.retryTimeout = [
|
|
1950
|
+
(_c = options.min_send_timeout) !== null && _c !== void 0 ? _c : this.retryTimeout[0],
|
|
1951
|
+
(_d = options.max_send_timeout) !== null && _d !== void 0 ? _d : this.retryTimeout[1],
|
|
1952
|
+
];
|
|
1953
|
+
if (!!options.max_send_attempts) {
|
|
1954
|
+
this.maxSendAttempts = options.max_send_attempts;
|
|
1955
|
+
}
|
|
3115
1956
|
this.initialized = true;
|
|
3116
|
-
// Set up the window close event handler "unload"
|
|
3117
|
-
window.addEventListener && window.addEventListener('unload', this._handle_unload.bind(this));
|
|
3118
1957
|
};
|
|
3119
1958
|
UsermavenClientImpl.prototype.interceptAnalytics = function (analytics) {
|
|
3120
1959
|
var _this = this;
|
|
@@ -3194,30 +2033,6 @@ var UsermavenClientImpl = /** @class */ (function () {
|
|
|
3194
2033
|
this.propsPersistance.save(this.permanentProperties);
|
|
3195
2034
|
}
|
|
3196
2035
|
};
|
|
3197
|
-
/**
|
|
3198
|
-
* Manage session capability
|
|
3199
|
-
* @param options
|
|
3200
|
-
*/
|
|
3201
|
-
UsermavenClientImpl.prototype.manageSession = function (options) {
|
|
3202
|
-
getLogger().debug('Options', options);
|
|
3203
|
-
options = options || {};
|
|
3204
|
-
getLogger().debug('Options', options);
|
|
3205
|
-
// cross_subdomain_cookie: whether to keep cookie across domains and subdomains
|
|
3206
|
-
var defaultConfig = {
|
|
3207
|
-
persistence: options.persistence || 'cookie',
|
|
3208
|
-
persistence_name: options.persistence_name || 'session',
|
|
3209
|
-
cross_subdomain_cookie: options.cross_subdomain_cookie || true
|
|
3210
|
-
};
|
|
3211
|
-
// TODO: Default session name would be session_
|
|
3212
|
-
this.config = _.extend(defaultConfig, this.config || {}, {
|
|
3213
|
-
token: this.apiKey,
|
|
3214
|
-
});
|
|
3215
|
-
getLogger().debug('Default Configuration', this.config);
|
|
3216
|
-
this.persistence = new UserMavenPersistence(this.config);
|
|
3217
|
-
getLogger().debug('Persistence Configuration', this.persistence);
|
|
3218
|
-
this.sessionManager = new SessionIdManager(this.config, this.persistence);
|
|
3219
|
-
getLogger().debug('Session Configuration', this.sessionManager);
|
|
3220
|
-
};
|
|
3221
2036
|
/**
|
|
3222
2037
|
* Manage auto-capturing
|
|
3223
2038
|
* @param options
|
|
@@ -3232,14 +2047,17 @@ var UsermavenClientImpl = /** @class */ (function () {
|
|
|
3232
2047
|
var num_enabled_buckets = 100;
|
|
3233
2048
|
if (!autocapture.enabledForProject(this.apiKey, num_buckets, num_enabled_buckets)) {
|
|
3234
2049
|
this.config['autocapture'] = false;
|
|
2050
|
+
this.__autocapture_enabled = false;
|
|
3235
2051
|
console.log('Not in active bucket: disabling Automatic Event Collection.');
|
|
3236
2052
|
}
|
|
3237
2053
|
else if (!autocapture.isBrowserSupported()) {
|
|
3238
2054
|
this.config['autocapture'] = false;
|
|
2055
|
+
this.__autocapture_enabled = false;
|
|
3239
2056
|
console.log('Disabling Automatic Event Collection because this browser is not supported');
|
|
3240
2057
|
}
|
|
3241
2058
|
else {
|
|
3242
|
-
|
|
2059
|
+
console.log('Autocapture enabled...');
|
|
2060
|
+
autocapture.init(this, options);
|
|
3243
2061
|
}
|
|
3244
2062
|
};
|
|
3245
2063
|
/**
|
|
@@ -3247,12 +2065,7 @@ var UsermavenClientImpl = /** @class */ (function () {
|
|
|
3247
2065
|
* frequently used usermaven function.
|
|
3248
2066
|
*
|
|
3249
2067
|
* ### Usage:
|
|
3250
|
-
*
|
|
3251
|
-
* // capture an event named 'Registered'
|
|
3252
|
-
* usermaven.capture('Registered', {'Gender': 'Male', 'Age': 21});
|
|
3253
|
-
*
|
|
3254
|
-
* // capture an event using navigator.sendBeacon
|
|
3255
|
-
* usermaven.capture('Left page', {'duration_seconds': 35}, {transport: 'sendBeacon'});
|
|
2068
|
+
* usermaven.capture('Registered', {'Gender': 'Male', 'Age': 21}, {});
|
|
3256
2069
|
*
|
|
3257
2070
|
* @param {String} event_name The name of the event. This can be anything the user does - 'Button Click', 'Sign Up', 'Item Purchased', etc.
|
|
3258
2071
|
* @param {Object} [properties] A set of properties to include with the event you're sending. These describe the user who did the event or details about the event itself.
|
|
@@ -3266,63 +2079,39 @@ var UsermavenClientImpl = /** @class */ (function () {
|
|
|
3266
2079
|
console.error('Trying to capture event before initialization');
|
|
3267
2080
|
return;
|
|
3268
2081
|
}
|
|
3269
|
-
|
|
3270
|
-
|
|
2082
|
+
console.log(properties);
|
|
2083
|
+
if (_isUndefined(event_name) || typeof event_name !== 'string') {
|
|
2084
|
+
console.error('No event name provided to usermaven.capture');
|
|
3271
2085
|
return;
|
|
3272
2086
|
}
|
|
3273
|
-
if (_.isBlockedUA(userAgent)) {
|
|
3274
|
-
|
|
3275
|
-
}
|
|
3276
|
-
var start_timestamp = this['persistence'].remove_event_timer(event_name);
|
|
3277
|
-
// update persistence
|
|
3278
|
-
this['persistence'].update_search_keyword(document.referrer);
|
|
3279
|
-
if (this.get_config('store_google')) {
|
|
3280
|
-
this['persistence'].update_campaign_params();
|
|
3281
|
-
}
|
|
3282
|
-
if (this.get_config('save_referrer')) {
|
|
3283
|
-
this['persistence'].update_referrer_info(document.referrer);
|
|
3284
|
-
}
|
|
2087
|
+
// if (_.isBlockedUA(userAgent)) {
|
|
2088
|
+
// return
|
|
2089
|
+
// }
|
|
3285
2090
|
var data = {
|
|
3286
2091
|
event: event_name + (properties['$event_type'] ? '_' + properties['$event_type'] : ''),
|
|
3287
|
-
properties: this._calculate_event_properties(event_name, properties
|
|
2092
|
+
properties: this._calculate_event_properties(event_name, properties),
|
|
3288
2093
|
};
|
|
3289
|
-
data =
|
|
3290
|
-
// send
|
|
2094
|
+
data = _copyAndTruncateStrings(data, this.get_config('properties_string_max_length'));
|
|
2095
|
+
// send event if there is a tagname available
|
|
3291
2096
|
if ((_b = (_a = data.properties) === null || _a === void 0 ? void 0 : _a.autocapture_attributes) === null || _b === void 0 ? void 0 : _b.tag_name) {
|
|
3292
2097
|
this.track("$autocapture", data.properties);
|
|
3293
2098
|
// this.track(data.event, data.properties)
|
|
3294
2099
|
}
|
|
3295
2100
|
};
|
|
3296
|
-
UsermavenClientImpl.prototype._calculate_event_properties = function (event_name, event_properties
|
|
2101
|
+
UsermavenClientImpl.prototype._calculate_event_properties = function (event_name, event_properties) {
|
|
3297
2102
|
var _a, _b;
|
|
3298
2103
|
// set defaults
|
|
3299
2104
|
var properties = event_properties || {};
|
|
3300
2105
|
if (event_name === '$snapshot') {
|
|
3301
2106
|
return properties;
|
|
3302
2107
|
}
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
var duration_in_ms = new Date().getTime() - start_timestamp;
|
|
3306
|
-
properties['$duration'] = parseFloat((duration_in_ms / 1000).toFixed(3));
|
|
3307
|
-
}
|
|
3308
|
-
// note: extend writes to the first object, so lets make sure we
|
|
3309
|
-
// don't write to the persistence properties object and info
|
|
3310
|
-
// properties object by passing in a new object
|
|
3311
|
-
// update properties with pageview info and super-properties
|
|
3312
|
-
// exlude , _.info.properties()
|
|
3313
|
-
properties = _.extend({}, this['persistence'].properties(), properties);
|
|
3314
|
-
var property_blacklist = this.get_config('property_blacklist');
|
|
3315
|
-
if (_.isArray(property_blacklist)) {
|
|
3316
|
-
_.each(property_blacklist, function (blacklisted_prop) {
|
|
2108
|
+
if (_isArray(this.propertyBlacklist)) {
|
|
2109
|
+
_each(this.propertyBlacklist, function (blacklisted_prop) {
|
|
3317
2110
|
delete properties[blacklisted_prop];
|
|
3318
2111
|
});
|
|
3319
2112
|
}
|
|
3320
2113
|
else {
|
|
3321
|
-
console.error('Invalid value for property_blacklist config: ' +
|
|
3322
|
-
}
|
|
3323
|
-
var sanitize_properties = this.get_config('sanitize_properties');
|
|
3324
|
-
if (sanitize_properties) {
|
|
3325
|
-
properties = sanitize_properties(properties, event_name);
|
|
2114
|
+
console.error('Invalid value for property_blacklist config: ' + this.propertyBlacklist);
|
|
3326
2115
|
}
|
|
3327
2116
|
// assign first element from $elements only
|
|
3328
2117
|
var attributes = {};
|
|
@@ -3333,24 +2122,15 @@ var UsermavenClientImpl = /** @class */ (function () {
|
|
|
3333
2122
|
properties['autocapture_attributes'] = attributes;
|
|
3334
2123
|
properties['autocapture_attributes']["el_text"] = (_a = properties['autocapture_attributes']["$el_text"]) !== null && _a !== void 0 ? _a : "";
|
|
3335
2124
|
properties['autocapture_attributes']["event_type"] = (_b = properties["$event_type"]) !== null && _b !== void 0 ? _b : "";
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
delete properties['$initial_referring_domain'];
|
|
3340
|
-
delete properties['$referrer'];
|
|
3341
|
-
delete properties['$referring_domain'];
|
|
3342
|
-
delete properties['$elements'];
|
|
2125
|
+
['$ce_version', "$event_type", "$initial_referrer", "$initial_referring_domain", "$referrer", "$referring_domain", "$elements"].forEach(function (key) {
|
|
2126
|
+
delete properties[key];
|
|
2127
|
+
});
|
|
3343
2128
|
// TODO: later remove this from the autotrack code.
|
|
3344
2129
|
delete properties['autocapture_attributes']["$el_text"];
|
|
3345
2130
|
delete properties['autocapture_attributes']["nth_child"];
|
|
3346
2131
|
delete properties['autocapture_attributes']["nth_of_type"];
|
|
3347
2132
|
return properties;
|
|
3348
2133
|
};
|
|
3349
|
-
UsermavenClientImpl.prototype._handle_unload = function () {
|
|
3350
|
-
if (this.get_config('capture_pageview')) {
|
|
3351
|
-
this.capture('$pageleave');
|
|
3352
|
-
}
|
|
3353
|
-
};
|
|
3354
2134
|
return UsermavenClientImpl;
|
|
3355
2135
|
}());
|
|
3356
2136
|
function interceptSegmentCalls(t) {
|