clarity-js 0.8.11 → 0.8.12

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.
@@ -10,73 +10,20 @@ var dom = /*#__PURE__*/Object.freeze({
10
10
  get iframe () { return iframe; },
11
11
  get iframeContent () { return iframeContent; },
12
12
  get lookup () { return lookup; },
13
- get parse () { return parse$1; },
13
+ get parse () { return parse; },
14
14
  get removeIFrame () { return removeIFrame; },
15
15
  get sameorigin () { return sameorigin; },
16
- get start () { return start$k; },
17
- get stop () { return stop$i; },
18
- get update () { return update$1; },
16
+ get start () { return start$j; },
17
+ get stop () { return stop$h; },
18
+ get update () { return update; },
19
19
  get updates () { return updates$1; }
20
20
  });
21
21
  var upload$1 = /*#__PURE__*/Object.freeze({
22
22
  __proto__: null,
23
23
  get queue () { return queue; },
24
- get start () { return start$e; },
25
- get stop () { return stop$d; },
26
- get track () { return track$1; }
27
- });
28
- var extract = /*#__PURE__*/Object.freeze({
29
- __proto__: null,
30
- get clone () { return clone; },
31
- get compute () { return compute$4; },
32
- get data () { return data$5; },
33
- get keys () { return keys; },
34
- get reset () { return reset$4; },
35
- get start () { return start$b; },
36
- get stop () { return stop$b; },
37
- get trigger () { return trigger$1; },
38
- get update () { return update; }
39
- });
40
- var limit = /*#__PURE__*/Object.freeze({
41
- __proto__: null,
42
- get check () { return check$2; },
43
- get compute () { return compute$3; },
44
- get data () { return data$4; },
45
- get start () { return start$a; },
46
- get stop () { return stop$a; },
47
- get trigger () { return trigger; }
48
- });
49
- var dimension = /*#__PURE__*/Object.freeze({
50
- __proto__: null,
51
- get compute () { return compute$2; },
52
- get data () { return data$3; },
53
- get log () { return log; },
54
- get reset () { return reset$3; },
55
24
  get start () { return start$9; },
56
- get stop () { return stop$9; },
57
- get updates () { return updates; }
58
- });
59
- var metadata$1 = /*#__PURE__*/Object.freeze({
60
- __proto__: null,
61
- get callback () { return callback; },
62
- get callbacks () { return callbacks; },
63
- get clear () { return clear; },
64
- get consent () { return consent; },
65
- get data () { return data$2; },
66
- get electron () { return electron; },
67
- get id () { return id; },
68
- get metadata () { return metadata; },
69
- get save () { return save; },
70
- get shortid () { return shortid; },
71
- get start () { return start$8; },
72
- get stop () { return stop$8; }
73
- });
74
- var envelope$1 = /*#__PURE__*/Object.freeze({
75
- __proto__: null,
76
- get data () { return data$1; },
77
- get envelope () { return envelope; },
78
- get start () { return start$7; },
79
- get stop () { return stop$7; }
25
+ get stop () { return stop$8; },
26
+ get track () { return track; }
80
27
  });
81
28
  var clarity = /*#__PURE__*/Object.freeze({
82
29
  __proto__: null,
@@ -121,11 +68,59 @@ var config$2 = {
121
68
  includeSubdomains: true,
122
69
  };
123
70
 
124
- function api(method) {
125
- // Zone.js, a popular package for Angular, overrides native browser APIs which can lead to inconsistent state for single page applications.
126
- // Example issue: https://github.com/angular/angular/issues/31712
127
- // As a work around, we ensuring Clarity access APIs outside of Zone (and use native implementation instead)
128
- return window["Zone" /* Constant.Zone */] && "__symbol__" /* Constant.Symbol */ in window["Zone" /* Constant.Zone */] ? window["Zone" /* Constant.Zone */]["__symbol__" /* Constant.Symbol */](method) : method;
71
+ /******************************************************************************
72
+ Copyright (c) Microsoft Corporation.
73
+
74
+ Permission to use, copy, modify, and/or distribute this software for any
75
+ purpose with or without fee is hereby granted.
76
+
77
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
78
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
79
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
80
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
81
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
82
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
83
+ PERFORMANCE OF THIS SOFTWARE.
84
+ ***************************************************************************** */
85
+ /* global Reflect, Promise */
86
+
87
+
88
+ function __awaiter(thisArg, _arguments, P, generator) {
89
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
90
+ return new (P || (P = Promise))(function (resolve, reject) {
91
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
92
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
93
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
94
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
95
+ });
96
+ }
97
+
98
+ function __generator(thisArg, body) {
99
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
100
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
101
+ function verb(n) { return function (v) { return step([n, v]); }; }
102
+ function step(op) {
103
+ if (f) throw new TypeError("Generator is already executing.");
104
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
105
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
106
+ if (y = 0, t) op = [op[0] & 2, t.value];
107
+ switch (op[0]) {
108
+ case 0: case 1: t = op; break;
109
+ case 4: _.label++; return { value: op[1], done: false };
110
+ case 5: _.label++; y = op[1]; op = [0]; continue;
111
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
112
+ default:
113
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
114
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
115
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
116
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
117
+ if (t[2]) _.ops.pop();
118
+ _.trys.pop(); continue;
119
+ }
120
+ op = body.call(thisArg, _);
121
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
122
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
123
+ }
129
124
  }
130
125
 
131
126
  var catchallRegex = /\S/gi;
@@ -340,7 +335,7 @@ function stop$F() {
340
335
  startTime = 0;
341
336
  }
342
337
 
343
- var version$1 = "0.8.11";
338
+ var version$1 = "0.8.12";
344
339
 
345
340
  function hash (input, precision) {
346
341
  if (precision === void 0) { precision = null; }
@@ -504,7 +499,7 @@ function visibility(t, visible) {
504
499
  }
505
500
  function compute$e() {
506
501
  if (update$2) {
507
- encode$1(4 /* Event.Baseline */);
502
+ encode$2(4 /* Event.Baseline */);
508
503
  }
509
504
  }
510
505
  function stop$E() {
@@ -534,191 +529,287 @@ function event(a, b) {
534
529
  else {
535
530
  data$j = { value: a };
536
531
  }
537
- encode$1(24 /* Event.Custom */);
532
+ encode$2(24 /* Event.Custom */);
538
533
  }
539
534
  }
540
535
 
541
- /******************************************************************************
542
- Copyright (c) Microsoft Corporation.
543
-
544
- Permission to use, copy, modify, and/or distribute this software for any
545
- purpose with or without fee is hereby granted.
546
-
547
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
548
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
549
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
550
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
551
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
552
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
553
- PERFORMANCE OF THIS SOFTWARE.
554
- ***************************************************************************** */
555
- /* global Reflect, Promise */
556
-
557
-
558
- function __awaiter(thisArg, _arguments, P, generator) {
559
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
560
- return new (P || (P = Promise))(function (resolve, reject) {
561
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
562
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
563
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
564
- step((generator = generator.apply(thisArg, _arguments || [])).next());
565
- });
566
- }
567
-
568
- function __generator(thisArg, body) {
569
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
570
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
571
- function verb(n) { return function (v) { return step([n, v]); }; }
572
- function step(op) {
573
- if (f) throw new TypeError("Generator is already executing.");
574
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
575
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
576
- if (y = 0, t) op = [op[0] & 2, t.value];
577
- switch (op[0]) {
578
- case 0: case 1: t = op; break;
579
- case 4: _.label++; return { value: op[1], done: false };
580
- case 5: _.label++; y = op[1]; op = [0]; continue;
581
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
582
- default:
583
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
584
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
585
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
586
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
587
- if (t[2]) _.ops.pop();
588
- _.trys.pop(); continue;
589
- }
590
- op = body.call(thisArg, _);
591
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
592
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
593
- }
594
- }
595
-
596
- function setTimeout$1(handler, timeout, event) {
597
- return window.setTimeout(measure(handler), timeout, event);
598
- }
599
- function clearTimeout(handle) {
600
- window.clearTimeout(handle);
536
+ var data$i = {};
537
+ var keys = new Set();
538
+ var variables = {};
539
+ var selectors = {};
540
+ var hashes = {};
541
+ var validation = {};
542
+ function start$G() {
543
+ reset$r();
601
544
  }
602
-
603
- var supported$1 = "CompressionStream" /* Constant.CompressionStream */ in window;
604
- function compress (input) {
605
- return __awaiter(this, void 0, void 0, function () {
606
- var stream, _a;
607
- return __generator(this, function (_c) {
608
- switch (_c.label) {
609
- case 0:
610
- _c.trys.push([0, 3, , 4]);
611
- if (!supported$1) return [3 /*break*/, 2];
612
- stream = new ReadableStream({ start: function (controller) {
613
- return __awaiter(this, void 0, void 0, function () {
614
- return __generator(this, function (_a) {
615
- controller.enqueue(input);
616
- controller.close();
617
- return [2 /*return*/];
618
- });
619
- });
620
- } }).pipeThrough(new TextEncoderStream()).pipeThrough(new window["CompressionStream" /* Constant.CompressionStream */]("gzip"));
621
- _a = Uint8Array.bind;
622
- return [4 /*yield*/, read(stream)];
623
- case 1: return [2 /*return*/, new (_a.apply(Uint8Array, [void 0, _c.sent()]))()];
624
- case 2: return [3 /*break*/, 4];
625
- case 3:
626
- _c.sent();
627
- return [3 /*break*/, 4];
628
- case 4: return [2 /*return*/, null];
545
+ // Input string is of the following form:
546
+ // EXTRACT 101|element { "1": ".class1", "2": "~window.a.b", "3": "!abc"}
547
+ // if element is present on the page it will set up event 101 to grab the contents of the class1 selector into component 1,
548
+ // the javascript evaluated contents of window.a.b into component 2,
549
+ // and the contents of Clarity's hash abc into component 3
550
+ function trigger$2(input) {
551
+ try {
552
+ var parts = input && input.length > 0 ? input.split(/ (.*)/) : ["" /* Constant.Empty */];
553
+ var keyparts = parts[0].split(/\|(.*)/);
554
+ var key = Number.parseInt(keyparts[0]);
555
+ var element = keyparts.length > 1 ? keyparts[1] : "" /* Constant.Empty */;
556
+ var values = parts.length > 1 ? JSON.parse(parts[1]) : {};
557
+ variables[key] = {};
558
+ selectors[key] = {};
559
+ hashes[key] = {};
560
+ validation[key] = element;
561
+ for (var v in values) {
562
+ // values is a set of strings for proper JSON parsing, but it's more efficient
563
+ // to interact with them as numbers
564
+ var id = Number.parseInt(v);
565
+ var value = values[v];
566
+ var source = 2 /* ExtractSource.Text */;
567
+ if (value.startsWith("~" /* Constant.Tilde */)) {
568
+ source = 0 /* ExtractSource.Javascript */;
629
569
  }
630
- });
631
- });
632
- }
633
- function read(stream) {
634
- return __awaiter(this, void 0, void 0, function () {
635
- var reader, chunks, done, value;
636
- var _a;
637
- return __generator(this, function (_b) {
638
- switch (_b.label) {
639
- case 0:
640
- reader = stream.getReader();
641
- chunks = [];
642
- done = false;
643
- value = [];
644
- _b.label = 1;
645
- case 1:
646
- if (!!done) return [3 /*break*/, 3];
647
- return [4 /*yield*/, reader.read()];
648
- case 2:
649
- (_a = _b.sent(), done = _a.done, value = _a.value);
650
- if (done) {
651
- return [2 /*return*/, chunks];
652
- }
653
- chunks.push.apply(chunks, value);
654
- return [3 /*break*/, 1];
655
- case 3: return [2 /*return*/, chunks];
570
+ else if (value.startsWith("!" /* Constant.Bang */)) {
571
+ source = 4 /* ExtractSource.Hash */;
656
572
  }
657
- });
658
- });
659
- }
660
-
661
- var data$i = null;
662
- var updates$3 = null;
663
- function start$G() {
664
- data$i = {};
665
- updates$3 = {};
666
- count$1(5 /* Metric.InvokeCount */);
667
- }
668
- function stop$D() {
669
- data$i = {};
670
- updates$3 = {};
671
- }
672
- function count$1(metric) {
673
- if (!(metric in data$i)) {
674
- data$i[metric] = 0;
573
+ switch (source) {
574
+ case 0 /* ExtractSource.Javascript */: {
575
+ var variable = value.slice(1);
576
+ variables[key][id] = parse$1(variable);
577
+ break;
578
+ }
579
+ case 2 /* ExtractSource.Text */:
580
+ selectors[key][id] = value;
581
+ break;
582
+ case 4 /* ExtractSource.Hash */: {
583
+ var hash_1 = value.slice(1);
584
+ hashes[key][id] = hash_1;
585
+ break;
586
+ }
587
+ }
588
+ }
675
589
  }
676
- if (!(metric in updates$3)) {
677
- updates$3[metric] = 0;
590
+ catch (e) {
591
+ log(8 /* Code.Config */, 1 /* Severity.Warning */, e ? e.name : null);
678
592
  }
679
- data$i[metric]++;
680
- updates$3[metric]++;
681
593
  }
682
- function sum(metric, value) {
683
- if (value !== null) {
684
- if (!(metric in data$i)) {
685
- data$i[metric] = 0;
686
- }
594
+ function clone$1(v) {
595
+ return JSON.parse(JSON.stringify(v));
596
+ }
597
+ function compute$d() {
598
+ try {
599
+ for (var v in variables) {
600
+ var key = Number.parseInt(v);
601
+ if (validation[key] === "" /* Constant.Empty */ || document.querySelector(validation[key])) {
602
+ var variableData = variables[key];
603
+ for (var v_1 in variableData) {
604
+ var variableKey = Number.parseInt(v_1);
605
+ var value = str$1(evaluate(clone$1(variableData[variableKey])));
606
+ if (value) {
607
+ update$1(key, variableKey, value);
608
+ }
609
+ }
610
+ var selectorData = selectors[key];
611
+ for (var s in selectorData) {
612
+ var shouldMask = false;
613
+ var selectorKey = Number.parseInt(s);
614
+ var selector = selectorData[selectorKey];
615
+ if (selector.startsWith("@" /* Constant.At */)) {
616
+ shouldMask = true;
617
+ selector = selector.slice(1);
618
+ }
619
+ var nodes = document.querySelectorAll(selector);
620
+ if (nodes) {
621
+ var text = Array.from(nodes)
622
+ .map(function (e) { return e.textContent; })
623
+ .join("<SEP>" /* Constant.Seperator */);
624
+ update$1(key, selectorKey, (shouldMask ? hash(text).trim() : text).slice(0, 10000 /* Setting.ExtractLimit */));
625
+ }
626
+ }
627
+ var hashData = hashes[key];
628
+ for (var h in hashData) {
629
+ var hashKey = Number.parseInt(h);
630
+ var content = hashText(hashData[hashKey]).trim().slice(0, 10000 /* Setting.ExtractLimit */);
631
+ update$1(key, hashKey, content);
632
+ }
633
+ }
634
+ }
635
+ if (keys.size > 0) {
636
+ encode$2(40 /* Event.Extract */);
637
+ }
638
+ }
639
+ catch (e) {
640
+ log(5 /* Code.Selector */, 1 /* Severity.Warning */, e ? e.name : null);
641
+ }
642
+ }
643
+ function reset$r() {
644
+ keys.clear();
645
+ }
646
+ function update$1(key, subkey, value) {
647
+ var update = false;
648
+ if (!(key in data$i)) {
649
+ data$i[key] = {};
650
+ update = true;
651
+ }
652
+ if (!isEmpty(hashes[key]) && (!(subkey in data$i[key]) || data$i[key][subkey] !== value)) {
653
+ update = true;
654
+ }
655
+ data$i[key][subkey] = value;
656
+ if (update) {
657
+ keys.add(key);
658
+ }
659
+ return;
660
+ }
661
+ function stop$D() {
662
+ reset$r();
663
+ }
664
+ function parse$1(variable) {
665
+ var syntax = [];
666
+ var parts = variable.split("." /* Constant.Dot */);
667
+ while (parts.length > 0) {
668
+ var part = parts.shift();
669
+ var arrayStart = part.indexOf("[" /* Constant.ArrayStart */);
670
+ var conditionStart = part.indexOf("{" /* Constant.ConditionStart */);
671
+ var conditionEnd = part.indexOf("}" /* Constant.ConditionEnd */);
672
+ syntax.push({
673
+ name: arrayStart > 0 ? part.slice(0, arrayStart) : conditionStart > 0 ? part.slice(0, conditionStart) : part,
674
+ type: arrayStart > 0 ? 1 /* Type.Array */ : conditionStart > 0 ? 2 /* Type.Object */ : 3 /* Type.Simple */,
675
+ condition: conditionStart > 0 ? part.slice(conditionStart + 1, conditionEnd) : null,
676
+ });
677
+ }
678
+ return syntax;
679
+ }
680
+ // The function below takes in a variable name in following format: "a.b.c" and safely evaluates its value in javascript context
681
+ // For instance, for a.b.c, it will first check window["a"]. If it exists, it will recursively look at: window["a"]["b"] and finally,
682
+ // return the value for window["a"]["b"]["c"].
683
+ // biome-ignore lint/complexity/noBannedTypes: type of base is intentionally generic
684
+ // biome-ignore lint/suspicious/noExplicitAny: type of return value isn't known
685
+ function evaluate(variable, base) {
686
+ if (base === void 0) { base = window; }
687
+ if (variable.length === 0) {
688
+ return base;
689
+ }
690
+ var part = variable.shift();
691
+ // biome-ignore lint/suspicious/noImplicitAnyLet: type of return value isn't known
692
+ var output;
693
+ if (base === null || base === void 0 ? void 0 : base[part.name]) {
694
+ var obj = base[part.name];
695
+ if (part.type !== 1 /* Type.Array */ && match(obj, part.condition)) {
696
+ output = evaluate(variable, obj);
697
+ }
698
+ else if (Array.isArray(obj)) {
699
+ var filtered = [];
700
+ for (var _i = 0, obj_1 = obj; _i < obj_1.length; _i++) {
701
+ var value = obj_1[_i];
702
+ if (match(value, part.condition)) {
703
+ var op = evaluate(variable, value);
704
+ if (op) {
705
+ filtered.push(op);
706
+ }
707
+ }
708
+ }
709
+ output = filtered;
710
+ }
711
+ return output;
712
+ }
713
+ return null;
714
+ }
715
+ function str$1(input) {
716
+ // Automatically trim string to max of Setting.ExtractLimit to avoid fetching long strings
717
+ return input ? JSON.stringify(input).slice(0, 10000 /* Setting.ExtractLimit */) : input;
718
+ }
719
+ // biome-ignore lint/complexity/noBannedTypes: type of base is intentionally generic
720
+ function match(base, condition) {
721
+ if (condition) {
722
+ var prop = condition.split(":");
723
+ return prop.length > 1 ? base[prop[0]] === prop[1] : base[prop[0]];
724
+ }
725
+ return true;
726
+ }
727
+ // biome-ignore lint/complexity/noBannedTypes: type of obj is intentionally generic
728
+ function isEmpty(obj) {
729
+ return Object.keys(obj).length === 0;
730
+ }
731
+
732
+ var extract = /*#__PURE__*/Object.freeze({
733
+ __proto__: null,
734
+ clone: clone$1,
735
+ compute: compute$d,
736
+ data: data$i,
737
+ keys: keys,
738
+ reset: reset$r,
739
+ start: start$G,
740
+ stop: stop$D,
741
+ trigger: trigger$2,
742
+ update: update$1
743
+ });
744
+
745
+ var data$h = null;
746
+ var updates$3 = null;
747
+ function start$F() {
748
+ data$h = {};
749
+ updates$3 = {};
750
+ count$1(5 /* Metric.InvokeCount */);
751
+ }
752
+ function stop$C() {
753
+ data$h = {};
754
+ updates$3 = {};
755
+ }
756
+ function count$1(metric) {
757
+ if (!(metric in data$h)) {
758
+ data$h[metric] = 0;
759
+ }
760
+ if (!(metric in updates$3)) {
761
+ updates$3[metric] = 0;
762
+ }
763
+ data$h[metric]++;
764
+ updates$3[metric]++;
765
+ }
766
+ function sum(metric, value) {
767
+ if (value !== null) {
768
+ if (!(metric in data$h)) {
769
+ data$h[metric] = 0;
770
+ }
687
771
  if (!(metric in updates$3)) {
688
772
  updates$3[metric] = 0;
689
773
  }
690
- data$i[metric] += value;
774
+ data$h[metric] += value;
691
775
  updates$3[metric] += value;
692
776
  }
693
777
  }
694
778
  function max(metric, value) {
695
779
  // Ensure that we do not process null or NaN values
696
780
  if (value !== null && Number.isNaN(value) === false) {
697
- if (!(metric in data$i)) {
698
- data$i[metric] = 0;
781
+ if (!(metric in data$h)) {
782
+ data$h[metric] = 0;
699
783
  }
700
- if (value > data$i[metric] || data$i[metric] === 0) {
784
+ if (value > data$h[metric] || data$h[metric] === 0) {
701
785
  updates$3[metric] = value;
702
- data$i[metric] = value;
786
+ data$h[metric] = value;
703
787
  }
704
788
  }
705
789
  }
706
- function compute$d() {
707
- encode$1(0 /* Event.Metric */);
790
+ function compute$c() {
791
+ encode$2(0 /* Event.Metric */);
708
792
  }
709
- function reset$r() {
793
+ function reset$q() {
710
794
  updates$3 = {};
711
795
  }
712
796
 
713
- var data$h;
797
+ function setTimeout$1(handler, timeout, event) {
798
+ return window.setTimeout(measure(handler), timeout, event);
799
+ }
800
+ function clearTimeout(handle) {
801
+ window.clearTimeout(handle);
802
+ }
803
+
804
+ var data$g;
714
805
  var last = 0;
715
806
  var interval = 0;
716
807
  var timeout$7 = null;
717
- function start$F() {
808
+ function start$E() {
718
809
  interval = 60000 /* Setting.PingInterval */;
719
810
  last = 0;
720
811
  }
721
- function reset$q() {
812
+ function reset$p() {
722
813
  if (timeout$7) {
723
814
  clearTimeout(timeout$7);
724
815
  }
@@ -727,16 +818,16 @@ function reset$q() {
727
818
  }
728
819
  function ping() {
729
820
  var now = time();
730
- data$h = { gap: now - last };
731
- encode$1(25 /* Event.Ping */);
732
- if (data$h.gap < 300000 /* Setting.PingTimeout */) {
821
+ data$g = { gap: now - last };
822
+ encode$2(25 /* Event.Ping */);
823
+ if (data$g.gap < 300000 /* Setting.PingTimeout */) {
733
824
  timeout$7 = setTimeout$1(ping, interval);
734
825
  }
735
826
  else {
736
827
  suspend();
737
828
  }
738
829
  }
739
- function stop$C() {
830
+ function stop$B() {
740
831
  clearTimeout(timeout$7);
741
832
  last = 0;
742
833
  interval = 0;
@@ -744,50 +835,50 @@ function stop$C() {
744
835
 
745
836
  var ping$1 = /*#__PURE__*/Object.freeze({
746
837
  __proto__: null,
747
- get data () { return data$h; },
748
- reset: reset$q,
749
- start: start$F,
750
- stop: stop$C
838
+ get data () { return data$g; },
839
+ reset: reset$p,
840
+ start: start$E,
841
+ stop: stop$B
751
842
  });
752
843
 
753
- var data$g = null;
754
- function start$E() {
755
- data$g = {};
844
+ var data$f = null;
845
+ function start$D() {
846
+ data$f = {};
756
847
  }
757
- function stop$B() {
758
- data$g = {};
848
+ function stop$A() {
849
+ data$f = {};
759
850
  }
760
851
  function track$7(event, time) {
761
- if (!(event in data$g)) {
762
- data$g[event] = [[time, 0]];
852
+ if (!(event in data$f)) {
853
+ data$f[event] = [[time, 0]];
763
854
  }
764
855
  else {
765
- var e = data$g[event];
856
+ var e = data$f[event];
766
857
  var last = e[e.length - 1];
767
858
  // Add a new entry only if the new event occurs after configured interval
768
859
  // Otherwise, extend the duration of the previous entry
769
860
  if (time - last[0] > 100 /* Setting.SummaryInterval */) {
770
- data$g[event].push([time, 0]);
861
+ data$f[event].push([time, 0]);
771
862
  }
772
863
  else {
773
864
  last[1] = time - last[0];
774
865
  }
775
866
  }
776
867
  }
777
- function compute$c() {
778
- encode$1(36 /* Event.Summary */);
868
+ function compute$b() {
869
+ encode$2(36 /* Event.Summary */);
779
870
  }
780
- function reset$p() {
781
- data$g = {};
871
+ function reset$o() {
872
+ data$f = {};
782
873
  }
783
874
 
784
875
  var summary = /*#__PURE__*/Object.freeze({
785
876
  __proto__: null,
786
- compute: compute$c,
787
- get data () { return data$g; },
788
- reset: reset$p,
789
- start: start$E,
790
- stop: stop$B,
877
+ compute: compute$b,
878
+ get data () { return data$f; },
879
+ reset: reset$o,
880
+ start: start$D,
881
+ stop: stop$A,
791
882
  track: track$7
792
883
  });
793
884
 
@@ -814,7 +905,7 @@ function resume$1() {
814
905
  }
815
906
  }
816
907
  }
817
- function reset$o() {
908
+ function reset$n() {
818
909
  tracker = {};
819
910
  queuedTasks = [];
820
911
  activeTask = null;
@@ -871,7 +962,7 @@ function run() {
871
962
  return;
872
963
  }
873
964
  if (error) {
874
- log$1(0 /* Code.RunTask */, 1 /* Severity.Warning */, error.name, error.message, error.stack);
965
+ log(0 /* Code.RunTask */, 1 /* Severity.Warning */, error.name, error.message, error.stack);
875
966
  }
876
967
  activeTask = null;
877
968
  run();
@@ -887,7 +978,7 @@ function state$a(timer) {
887
978
  // If this task is no longer being tracked, send stop message to the caller
888
979
  return 2 /* Task.Stop */;
889
980
  }
890
- function start$D(timer) {
981
+ function start$C(timer) {
891
982
  tracker[key(timer)] = { start: performance.now(), calls: 0, yield: 30 /* Setting.LongTask */ };
892
983
  }
893
984
  function restart$2(timer) {
@@ -895,12 +986,12 @@ function restart$2(timer) {
895
986
  if (tracker === null || tracker === void 0 ? void 0 : tracker[id]) {
896
987
  var c = tracker[id].calls;
897
988
  var y = tracker[id].yield;
898
- start$D(timer);
989
+ start$C(timer);
899
990
  tracker[id].calls = c + 1;
900
991
  tracker[id].yield = y;
901
992
  }
902
993
  }
903
- function stop$A(timer) {
994
+ function stop$z(timer) {
904
995
  var end = performance.now();
905
996
  var id = key(timer);
906
997
  var duration = end - tracker[id].start;
@@ -921,7 +1012,7 @@ function suspend$1(timer) {
921
1012
  case 0:
922
1013
  id = key(timer);
923
1014
  if (!(id in tracker)) return [3 /*break*/, 2];
924
- stop$A(timer);
1015
+ stop$z(timer);
925
1016
  // some customer polyfills for requestIdleCallback return null
926
1017
  _b = tracker[id];
927
1018
  return [4 /*yield*/, wait()];
@@ -1036,8 +1127,8 @@ function throttle(func, duration) {
1036
1127
  }
1037
1128
 
1038
1129
  var history$5 = [];
1039
- var data$f;
1040
- function start$C() {
1130
+ var data$e;
1131
+ function start$B() {
1041
1132
  history$5 = [];
1042
1133
  max(26 /* Metric.Automation */, navigator.webdriver ? 1 /* BooleanFlag.True */ : 0 /* BooleanFlag.False */);
1043
1134
  try {
@@ -1051,11 +1142,11 @@ function start$C() {
1051
1142
  function check$4(id, target, input) {
1052
1143
  // Compute hash for fraud detection, if enabled. Hash is computed only if input meets the minimum length criteria
1053
1144
  if (config$2.fraud && id !== null && input && input.length >= 5 /* Setting.WordLength */) {
1054
- data$f = { id: id, target: target, checksum: hash(input, 28 /* Setting.ChecksumPrecision */) };
1145
+ data$e = { id: id, target: target, checksum: hash(input, 28 /* Setting.ChecksumPrecision */) };
1055
1146
  // Only encode this event if we haven't already reported this hash
1056
- if (history$5.indexOf(data$f.checksum) < 0) {
1057
- history$5.push(data$f.checksum);
1058
- encode$2(41 /* Event.Fraud */);
1147
+ if (history$5.indexOf(data$e.checksum) < 0) {
1148
+ history$5.push(data$e.checksum);
1149
+ encode$1(41 /* Event.Fraud */);
1059
1150
  }
1060
1151
  }
1061
1152
  }
@@ -1113,14 +1204,14 @@ var animationFinish = null;
1113
1204
  var animationId = "clarityAnimationId";
1114
1205
  var operationCount = "clarityOperationCount";
1115
1206
  var maxOperations = 20;
1116
- function start$B() {
1207
+ function start$A() {
1117
1208
  var _a;
1118
1209
  if (((_a = window.Animation) === null || _a === void 0 ? void 0 : _a.prototype) &&
1119
1210
  window.KeyframeEffect &&
1120
1211
  window.KeyframeEffect.prototype &&
1121
1212
  window.KeyframeEffect.prototype.getKeyframes &&
1122
1213
  window.KeyframeEffect.prototype.getTiming) {
1123
- reset$n();
1214
+ reset$m();
1124
1215
  overrideAnimationHelper(animationPlay, "play");
1125
1216
  overrideAnimationHelper(animationPause, "pause");
1126
1217
  overrideAnimationHelper(animationCommitStyles, "commitStyles");
@@ -1154,7 +1245,7 @@ function start$B() {
1154
1245
  }
1155
1246
  }
1156
1247
  }
1157
- function reset$n() {
1248
+ function reset$m() {
1158
1249
  state$9 = [];
1159
1250
  }
1160
1251
  function track$6(time, id, operation, keyFrames, timing, targetId, timeline) {
@@ -1172,8 +1263,8 @@ function track$6(time, id, operation, keyFrames, timing, targetId, timeline) {
1172
1263
  });
1173
1264
  encode$4(44 /* Event.Animation */);
1174
1265
  }
1175
- function stop$z() {
1176
- reset$n();
1266
+ function stop$y() {
1267
+ reset$m();
1177
1268
  }
1178
1269
  function overrideAnimationHelper(functionToOverride, name) {
1179
1270
  if (functionToOverride === null) {
@@ -1234,8 +1325,8 @@ var regions = {};
1234
1325
  var queue$2 = [];
1235
1326
  var watch = false;
1236
1327
  var observer$1 = null;
1237
- function start$A() {
1238
- reset$m();
1328
+ function start$z() {
1329
+ reset$l();
1239
1330
  observer$1 = null;
1240
1331
  regionMap = new WeakMap();
1241
1332
  regions = {};
@@ -1284,8 +1375,8 @@ function track$5(id, event) {
1284
1375
  // Process updates to this region, if applicable
1285
1376
  process$8(node, data, interaction, data.visibility);
1286
1377
  }
1287
- function compute$b() {
1288
- compute$b.dn = 24 /* FunctionNames.RegionCompute */;
1378
+ function compute$a() {
1379
+ compute$a.dn = 24 /* FunctionNames.RegionCompute */;
1289
1380
  // Process any regions where we couldn't resolve an "id" for at the time of last intersection observer event
1290
1381
  // This could happen in cases where elements are not yet processed by Clarity's virtual DOM but browser reports a change, regardless.
1291
1382
  // For those cases we add them to the queue and re-process them below
@@ -1354,22 +1445,22 @@ function process$8(n, d, s, v) {
1354
1445
  if (d.id) {
1355
1446
  if ((d.id in regions && updated) || !(d.id in regions)) {
1356
1447
  regions[d.id] = d;
1357
- state$8.push(clone$1(d));
1448
+ state$8.push(clone(d));
1358
1449
  }
1359
1450
  }
1360
1451
  else {
1361
1452
  // Get the time before adding to queue to ensure accurate event time
1362
- queue$2.push({ node: n, state: clone$1(d) });
1453
+ queue$2.push({ node: n, state: clone(d) });
1363
1454
  }
1364
1455
  }
1365
- function clone$1(r) {
1456
+ function clone(r) {
1366
1457
  return { time: time(), data: { id: r.id, interaction: r.interaction, visibility: r.visibility, name: r.name } };
1367
1458
  }
1368
- function reset$m() {
1459
+ function reset$l() {
1369
1460
  state$8 = [];
1370
1461
  }
1371
- function stop$y() {
1372
- reset$m();
1462
+ function stop$x() {
1463
+ reset$l();
1373
1464
  regionMap = null;
1374
1465
  regions = {};
1375
1466
  queue$2 = [];
@@ -1433,7 +1524,7 @@ function proxyStyleRules$1(win) {
1433
1524
  }
1434
1525
  }
1435
1526
  }
1436
- function start$z() {
1527
+ function start$y() {
1437
1528
  proxyStyleRules$1(window);
1438
1529
  }
1439
1530
  function checkDocumentStyles(documentNode, cachedTimestamp) {
@@ -1477,7 +1568,7 @@ function checkDocumentStyles(documentNode, cachedTimestamp) {
1477
1568
  styleTimeMap[documentId] = timestamp;
1478
1569
  }
1479
1570
  }
1480
- function compute$a() {
1571
+ function compute$9() {
1481
1572
  for (var _i = 0, documentNodes_1 = documentNodes; _i < documentNodes_1.length; _i++) {
1482
1573
  var documentNode = documentNodes_1[_i];
1483
1574
  var docId = documentNode === document ? -1 : getId(documentNode);
@@ -1485,16 +1576,16 @@ function compute$a() {
1485
1576
  checkDocumentStyles(documentNode, ts);
1486
1577
  }
1487
1578
  }
1488
- function reset$l() {
1579
+ function reset$k() {
1489
1580
  sheetAdoptionState = [];
1490
1581
  sheetUpdateState = [];
1491
1582
  }
1492
- function stop$x() {
1583
+ function stop$w() {
1493
1584
  styleSheetMap = {};
1494
1585
  styleTimeMap = {};
1495
1586
  documentNodes = [];
1496
1587
  createdSheetIds = [];
1497
- reset$l();
1588
+ reset$k();
1498
1589
  }
1499
1590
  function trackStyleChange(time, id, operation, cssRules) {
1500
1591
  sheetUpdateState.push({
@@ -1550,7 +1641,7 @@ function encode$4 (type, timer, ts) {
1550
1641
  return [3 /*break*/, 12];
1551
1642
  case 1:
1552
1643
  {
1553
- d = data$e;
1644
+ d = data$d;
1554
1645
  tokens.push(d.width);
1555
1646
  tokens.push(d.height);
1556
1647
  track$8(type, d.width, d.height);
@@ -1567,7 +1658,7 @@ function encode$4 (type, timer, ts) {
1567
1658
  tokens.push(r.data.name);
1568
1659
  queue(tokens);
1569
1660
  }
1570
- reset$m();
1661
+ reset$l();
1571
1662
  return [3 /*break*/, 12];
1572
1663
  case 3:
1573
1664
  for (_c = 0, _d = sheetAdoptionState; _c < _d.length; _c++) {
@@ -1586,7 +1677,7 @@ function encode$4 (type, timer, ts) {
1586
1677
  tokens.push(entry.data.cssRules);
1587
1678
  queue(tokens);
1588
1679
  }
1589
- reset$l();
1680
+ reset$k();
1590
1681
  return [3 /*break*/, 12];
1591
1682
  case 4:
1592
1683
  for (_g = 0, _h = state$9; _g < _h.length; _g++) {
@@ -1600,7 +1691,7 @@ function encode$4 (type, timer, ts) {
1600
1691
  tokens.push(entry.data.targetId);
1601
1692
  queue(tokens);
1602
1693
  }
1603
- reset$n();
1694
+ reset$m();
1604
1695
  return [3 /*break*/, 12];
1605
1696
  case 5:
1606
1697
  // Check if we are operating within the context of the current page
@@ -1648,7 +1739,7 @@ function encode$4 (type, timer, ts) {
1648
1739
  }
1649
1740
  tokens.push(suspend ? "*M" /* Constant.SuspendMutationTag */ : data[key]);
1650
1741
  if (box && box.length === 2) {
1651
- tokens.push("".concat("#" /* Constant.Hash */).concat(str$1(box[0]), ".").concat(str$1(box[1])));
1742
+ tokens.push("".concat("#" /* Constant.Hash */).concat(str(box[0]), ".").concat(str(box[1])));
1652
1743
  }
1653
1744
  break;
1654
1745
  }
@@ -1695,23 +1786,23 @@ function size(value) {
1695
1786
  }
1696
1787
  return value.metadata.size;
1697
1788
  }
1698
- function str$1(input) {
1789
+ function str(input) {
1699
1790
  return input.toString(36);
1700
1791
  }
1701
1792
  function attribute(key, value, privacy) {
1702
1793
  return "".concat(key, "=").concat(text$1(value, key.indexOf("data-" /* Constant.DataAttribute */) === 0 ? "data-" /* Constant.DataAttribute */ : key, privacy));
1703
1794
  }
1704
1795
 
1705
- var data$e;
1706
- function reset$k() {
1707
- data$e = null;
1796
+ var data$d;
1797
+ function reset$j() {
1798
+ data$d = null;
1708
1799
  }
1709
- function start$y() {
1710
- reset$k();
1711
- compute$9();
1800
+ function start$x() {
1801
+ reset$j();
1802
+ compute$8();
1712
1803
  }
1713
- function compute$9() {
1714
- compute$9.dn = 19 /* FunctionNames.DocumentCompute */;
1804
+ function compute$8() {
1805
+ compute$8.dn = 19 /* FunctionNames.DocumentCompute */;
1715
1806
  var body = document.body;
1716
1807
  var d = document.documentElement;
1717
1808
  var bodyClientWidth = body ? body.clientWidth : null;
@@ -1729,13 +1820,13 @@ function compute$9() {
1729
1820
  var documentOffsetHeight = d ? d.offsetHeight : null;
1730
1821
  var height = Math.max(bodyClientHeight, bodyScrollHeight, bodyOffsetHeight, documentClientHeight, documentScrollHeight, documentOffsetHeight);
1731
1822
  // Check that width or height has changed from before, and also that width & height are not null values
1732
- if ((data$e === null || width !== data$e.width || height !== data$e.height) && width !== null && height !== null) {
1733
- data$e = { width: width, height: height };
1823
+ if ((data$d === null || width !== data$d.width || height !== data$d.height) && width !== null && height !== null) {
1824
+ data$d = { width: width, height: height };
1734
1825
  encode$4(8 /* Event.Document */);
1735
1826
  }
1736
1827
  }
1737
- function stop$w() {
1738
- reset$k();
1828
+ function stop$v() {
1829
+ reset$j();
1739
1830
  }
1740
1831
 
1741
1832
  function traverse (root, timer, source, timestamp) {
@@ -1786,8 +1877,8 @@ var history$4 = {};
1786
1877
  var observedNodes = new WeakMap();
1787
1878
  // We ignore mutations if these attributes are updated
1788
1879
  var IGNORED_ATTRIBUTES = ["data-google-query-id", "data-load-complete", "data-google-container-id"];
1789
- function start$x() {
1790
- start$x.dn = 21 /* FunctionNames.MutationStart */;
1880
+ function start$w() {
1881
+ start$w.dn = 21 /* FunctionNames.MutationStart */;
1791
1882
  observers = new Set();
1792
1883
  queue$1 = [];
1793
1884
  timeout$6 = null;
@@ -1814,7 +1905,7 @@ function observe$b(node) {
1814
1905
  }
1815
1906
  }
1816
1907
  catch (e) {
1817
- log$1(2 /* Code.MutationObserver */, 0 /* Severity.Info */, e ? e.name : null);
1908
+ log(2 /* Code.MutationObserver */, 0 /* Severity.Info */, e ? e.name : null);
1818
1909
  }
1819
1910
  }
1820
1911
  function monitor(frame) {
@@ -1825,7 +1916,7 @@ function monitor(frame) {
1825
1916
  bind(frame, "load" /* Constant.LoadEvent */, generate.bind(this, frame, "childList" /* Constant.ChildList */), true);
1826
1917
  }
1827
1918
  }
1828
- function stop$v() {
1919
+ function stop$u() {
1829
1920
  for (var _i = 0, _a = Array.from(observers); _i < _a.length; _i++) {
1830
1921
  var observer = _a[_i];
1831
1922
  if (observer) {
@@ -1859,8 +1950,8 @@ function handle$1(m) {
1859
1950
  track$7(6 /* Event.Mutation */, now);
1860
1951
  mutations.push({ time: now, mutations: m });
1861
1952
  schedule$1(process$7, 1 /* Priority.High */).then(function () {
1862
- setTimeout$1(compute$9);
1863
- measure(compute$b)();
1953
+ setTimeout$1(compute$8);
1954
+ measure(compute$a)();
1864
1955
  });
1865
1956
  }
1866
1957
  function processMutation(timer, mutation, instance, timestamp) {
@@ -1882,10 +1973,10 @@ function processMutation(timer, mutation, instance, timestamp) {
1882
1973
  target = mutation.target;
1883
1974
  type = config$2.throttleDom ? track$4(mutation, timer, instance, timestamp) : mutation.type;
1884
1975
  if (type && target && target.ownerDocument) {
1885
- parse$1(target.ownerDocument);
1976
+ parse(target.ownerDocument);
1886
1977
  }
1887
1978
  if (type && target && target.nodeType === Node.DOCUMENT_FRAGMENT_NODE && target.host) {
1888
- parse$1(target);
1979
+ parse(target);
1889
1980
  }
1890
1981
  switch (type) {
1891
1982
  case "attributes" /* Constant.Attributes */:
@@ -1913,7 +2004,7 @@ function process$7() {
1913
2004
  switch (_d.label) {
1914
2005
  case 0:
1915
2006
  timer = { id: id(), cost: 3 /* Metric.LayoutCost */ };
1916
- start$D(timer);
2007
+ start$C(timer);
1917
2008
  _d.label = 1;
1918
2009
  case 1:
1919
2010
  if (!(mutations.length > 0)) return [3 /*break*/, 7];
@@ -1963,7 +2054,7 @@ function process$7() {
1963
2054
  _d.label = 13;
1964
2055
  case 13:
1965
2056
  cleanHistory();
1966
- stop$A(timer);
2057
+ stop$z(timer);
1967
2058
  return [2 /*return*/];
1968
2059
  }
1969
2060
  });
@@ -2087,11 +2178,11 @@ function schedule(node) {
2087
2178
  clearTimeout(timeout$6);
2088
2179
  }
2089
2180
  timeout$6 = setTimeout$1(function () {
2090
- trigger$2();
2181
+ trigger$1();
2091
2182
  }, 33 /* Setting.LookAhead */);
2092
2183
  return node;
2093
2184
  }
2094
- function trigger$2() {
2185
+ function trigger$1() {
2095
2186
  for (var _i = 0, queue_1 = queue$1; _i < queue_1.length; _i++) {
2096
2187
  var node = queue_1[_i];
2097
2188
  // Generate a mutation for this node only if it still exists
@@ -2253,8 +2344,8 @@ function offset(inputElement) {
2253
2344
 
2254
2345
  var UserInputTags = ["input", "textarea", "radio", "button", "canvas", "select"];
2255
2346
  var state$7 = [];
2256
- function start$w() {
2257
- reset$j();
2347
+ function start$v() {
2348
+ reset$i();
2258
2349
  }
2259
2350
  function observe$a(root) {
2260
2351
  bind(root, "click", handler$2.bind(this, 9 /* Event.Click */, root), true);
@@ -2384,16 +2475,16 @@ function context(a) {
2384
2475
  }
2385
2476
  return 0 /* BrowsingContext.Self */;
2386
2477
  }
2387
- function reset$j() {
2478
+ function reset$i() {
2388
2479
  state$7 = [];
2389
2480
  }
2390
- function stop$u() {
2391
- reset$j();
2481
+ function stop$t() {
2482
+ reset$i();
2392
2483
  }
2393
2484
 
2394
2485
  var state$6 = [];
2395
- function start$v() {
2396
- reset$i();
2486
+ function start$u() {
2487
+ reset$h();
2397
2488
  }
2398
2489
  function observe$9(root) {
2399
2490
  bind(root, "cut", recompute$8.bind(this, 0 /* Clipboard.Cut */), true);
@@ -2405,18 +2496,18 @@ function recompute$8(action, evt) {
2405
2496
  state$6.push({ time: time(evt), event: 38 /* Event.Clipboard */, data: { target: target(evt), action: action } });
2406
2497
  schedule$1(encode$3.bind(this, 38 /* Event.Clipboard */));
2407
2498
  }
2408
- function reset$i() {
2499
+ function reset$h() {
2409
2500
  state$6 = [];
2410
2501
  }
2411
- function stop$t() {
2412
- reset$i();
2502
+ function stop$s() {
2503
+ reset$h();
2413
2504
  }
2414
2505
 
2415
2506
  var timeout$5 = null;
2416
2507
  var state$5 = [];
2417
- function start$u() {
2418
- reset$h();
2419
- }
2508
+ function start$t() {
2509
+ reset$g();
2510
+ }
2420
2511
  function observe$8(root) {
2421
2512
  bind(root, "input", recompute$7, true);
2422
2513
  }
@@ -2446,12 +2537,12 @@ function recompute$7(evt) {
2446
2537
  function process$6(event) {
2447
2538
  schedule$1(encode$3.bind(this, event));
2448
2539
  }
2449
- function reset$h() {
2540
+ function reset$g() {
2450
2541
  state$5 = [];
2451
2542
  }
2452
- function stop$s() {
2543
+ function stop$r() {
2453
2544
  clearTimeout(timeout$5);
2454
- reset$h();
2545
+ reset$g();
2455
2546
  }
2456
2547
 
2457
2548
  var state$4 = [];
@@ -2459,8 +2550,8 @@ var timeout$4 = null;
2459
2550
  var hasPrimaryTouch = false;
2460
2551
  var primaryTouchId = 0;
2461
2552
  var activeTouchPointIds = new Set();
2462
- function start$t() {
2463
- reset$g();
2553
+ function start$s() {
2554
+ reset$f();
2464
2555
  }
2465
2556
  function observe$7(root) {
2466
2557
  bind(root, "mousedown", mouse.bind(this, 13 /* Event.MouseDown */, root), true);
@@ -2558,7 +2649,7 @@ function handler$1(current) {
2558
2649
  function process$5(event) {
2559
2650
  schedule$1(encode$3.bind(this, event));
2560
2651
  }
2561
- function reset$g() {
2652
+ function reset$f() {
2562
2653
  state$4 = [];
2563
2654
  }
2564
2655
  function similar$1(last, current) {
@@ -2570,7 +2661,7 @@ function similar$1(last, current) {
2570
2661
  var sameId = current.data.id !== undefined ? current.data.id === last.data.id : true;
2571
2662
  return current.event === last.event && match && distance < 20 /* Setting.Distance */ && gap < 25 /* Setting.PointerInterval */ && sameId;
2572
2663
  }
2573
- function stop$r() {
2664
+ function stop$q() {
2574
2665
  clearTimeout(timeout$4);
2575
2666
  // Send out any pending pointer events in the pipeline
2576
2667
  if (state$4.length > 0) {
@@ -2578,10 +2669,10 @@ function stop$r() {
2578
2669
  }
2579
2670
  }
2580
2671
 
2581
- var data$d;
2672
+ var data$c;
2582
2673
  var timeout$3 = null;
2583
2674
  var initialStateLogged = false;
2584
- function start$s() {
2675
+ function start$r() {
2585
2676
  initialStateLogged = false;
2586
2677
  bind(window, "resize", recompute$6);
2587
2678
  recompute$6();
@@ -2591,7 +2682,7 @@ function recompute$6() {
2591
2682
  var de = document.documentElement;
2592
2683
  // window.innerWidth includes width of the scrollbar and is not a true representation of the viewport width.
2593
2684
  // Therefore, when possible, use documentElement's clientWidth property.
2594
- data$d = {
2685
+ data$c = {
2595
2686
  width: de && "clientWidth" in de ? Math.min(de.clientWidth, window.innerWidth) : window.innerWidth,
2596
2687
  height: de && "clientHeight" in de ? Math.min(de.clientHeight, window.innerHeight) : window.innerHeight,
2597
2688
  };
@@ -2607,19 +2698,19 @@ function recompute$6() {
2607
2698
  function process$4(event) {
2608
2699
  schedule$1(encode$3.bind(this, event));
2609
2700
  }
2610
- function reset$f() {
2611
- data$d = null;
2701
+ function reset$e() {
2702
+ data$c = null;
2612
2703
  clearTimeout(timeout$3);
2613
2704
  }
2614
- function stop$q() {
2615
- reset$f();
2705
+ function stop$p() {
2706
+ reset$e();
2616
2707
  }
2617
2708
 
2618
- var data$c = null;
2709
+ var data$b = null;
2619
2710
  var previous = null;
2620
2711
  var timeout$2 = null;
2621
- function start$r() {
2622
- reset$e();
2712
+ function start$q() {
2713
+ reset$d();
2623
2714
  }
2624
2715
  function observe$6(root) {
2625
2716
  bind(root, "selectstart", recompute$5.bind(this, root), true);
@@ -2641,12 +2732,12 @@ function recompute$5(root) {
2641
2732
  (current.anchorNode === current.focusNode && current.anchorOffset === current.focusOffset)) {
2642
2733
  return;
2643
2734
  }
2644
- var startNode = data$c.start ? data$c.start : null;
2645
- if (previous !== null && data$c.start !== null && startNode !== current.anchorNode) {
2735
+ var startNode = data$b.start ? data$b.start : null;
2736
+ if (previous !== null && data$b.start !== null && startNode !== current.anchorNode) {
2646
2737
  clearTimeout(timeout$2);
2647
2738
  process$3(21 /* Event.Selection */);
2648
2739
  }
2649
- data$c = {
2740
+ data$b = {
2650
2741
  start: current.anchorNode,
2651
2742
  startOffset: current.anchorOffset,
2652
2743
  end: current.focusNode,
@@ -2659,18 +2750,18 @@ function recompute$5(root) {
2659
2750
  function process$3(event) {
2660
2751
  schedule$1(encode$3.bind(this, event));
2661
2752
  }
2662
- function reset$e() {
2753
+ function reset$d() {
2663
2754
  previous = null;
2664
- data$c = { start: 0, startOffset: 0, end: 0, endOffset: 0 };
2755
+ data$b = { start: 0, startOffset: 0, end: 0, endOffset: 0 };
2665
2756
  }
2666
- function stop$p() {
2667
- reset$e();
2757
+ function stop$o() {
2758
+ reset$d();
2668
2759
  clearTimeout(timeout$2);
2669
2760
  }
2670
2761
 
2671
2762
  var state$3 = [];
2672
- function start$q() {
2673
- reset$d();
2763
+ function start$p() {
2764
+ reset$c();
2674
2765
  }
2675
2766
  function observe$5(root) {
2676
2767
  bind(root, "submit", recompute$4, true);
@@ -2680,20 +2771,20 @@ function recompute$4(evt) {
2680
2771
  state$3.push({ time: time(evt), event: 39 /* Event.Submit */, data: { target: target(evt) } });
2681
2772
  schedule$1(encode$3.bind(this, 39 /* Event.Submit */));
2682
2773
  }
2683
- function reset$d() {
2774
+ function reset$c() {
2684
2775
  state$3 = [];
2685
2776
  }
2686
- function stop$o() {
2687
- reset$d();
2777
+ function stop$n() {
2778
+ reset$c();
2688
2779
  }
2689
2780
 
2690
2781
  var state$2 = [];
2691
2782
  var updates$2 = [];
2692
- function start$p() {
2783
+ function start$o() {
2693
2784
  state$2 = [];
2694
- reset$c();
2785
+ reset$b();
2695
2786
  }
2696
- function reset$c() {
2787
+ function reset$b() {
2697
2788
  updates$2 = [];
2698
2789
  }
2699
2790
  function track$3(time, event, hash, x, y, reaction, context) {
@@ -2716,10 +2807,10 @@ function track$3(time, event, hash, x, y, reaction, context) {
2716
2807
  // We would still need to capture the last scroll position as part of the baseline event, even when timeline will be empty.
2717
2808
  track$8(event, x, y, time);
2718
2809
  }
2719
- function compute$8() {
2810
+ function compute$7() {
2720
2811
  var temp = [];
2721
2812
  updates$2 = [];
2722
- var max = data$1.start + data$1.duration;
2813
+ var max = data$3.start + data$3.duration;
2723
2814
  var min = Math.max(max - 2000 /* Setting.TimelineSpan */, 0);
2724
2815
  for (var _i = 0, state_1 = state$2; _i < state_1.length; _i++) {
2725
2816
  var s = state_1[_i];
@@ -2733,44 +2824,44 @@ function compute$8() {
2733
2824
  state$2 = temp; // Drop events less than the min time
2734
2825
  encode$3(22 /* Event.Timeline */);
2735
2826
  }
2736
- function stop$n() {
2827
+ function stop$m() {
2737
2828
  state$2 = [];
2738
- reset$c();
2829
+ reset$b();
2739
2830
  }
2740
2831
 
2741
- var data$b;
2742
- function start$o() {
2832
+ var data$a;
2833
+ function start$n() {
2743
2834
  bind(window, "pagehide", recompute$3);
2744
2835
  }
2745
2836
  function recompute$3(evt) {
2746
2837
  recompute$3.dn = 17 /* FunctionNames.UnloadRecompute */;
2747
- data$b = { name: evt.type, persisted: evt.persisted ? 1 /* BooleanFlag.True */ : 0 /* BooleanFlag.False */ };
2838
+ data$a = { name: evt.type, persisted: evt.persisted ? 1 /* BooleanFlag.True */ : 0 /* BooleanFlag.False */ };
2748
2839
  encode$3(26 /* Event.Unload */, time(evt));
2749
2840
  stop();
2750
2841
  }
2751
- function reset$b() {
2752
- data$b = null;
2842
+ function reset$a() {
2843
+ data$a = null;
2753
2844
  }
2754
- function stop$m() {
2755
- reset$b();
2845
+ function stop$l() {
2846
+ reset$a();
2756
2847
  }
2757
2848
 
2758
- var data$a;
2759
- function start$n() {
2849
+ var data$9;
2850
+ function start$m() {
2760
2851
  bind(document, "visibilitychange", recompute$2);
2761
2852
  recompute$2();
2762
2853
  }
2763
2854
  function recompute$2(evt) {
2764
2855
  if (evt === void 0) { evt = null; }
2765
2856
  recompute$2.dn = 18 /* FunctionNames.VisibilityRecompute */;
2766
- data$a = { visible: "visibilityState" in document ? document.visibilityState : "default" };
2857
+ data$9 = { visible: "visibilityState" in document ? document.visibilityState : "default" };
2767
2858
  encode$3(28 /* Event.Visibility */, time(evt));
2768
2859
  }
2769
- function reset$a() {
2770
- data$a = null;
2860
+ function reset$9() {
2861
+ data$9 = null;
2771
2862
  }
2772
- function stop$l() {
2773
- reset$a();
2863
+ function stop$k() {
2864
+ reset$9();
2774
2865
  }
2775
2866
 
2776
2867
  function encode$3 (type, ts) {
@@ -2810,7 +2901,7 @@ function encode$3 (type, ts) {
2810
2901
  }
2811
2902
  }
2812
2903
  }
2813
- reset$g();
2904
+ reset$f();
2814
2905
  break;
2815
2906
  case 9 /* Event.Click */:
2816
2907
  for (_b = 0, _c = state$7; _b < _c.length; _b++) {
@@ -2834,7 +2925,7 @@ function encode$3 (type, ts) {
2834
2925
  queue(tokens);
2835
2926
  track$3(entry.time, entry.event, cHash, entry.data.x, entry.data.y, entry.data.reaction, entry.data.context);
2836
2927
  }
2837
- reset$j();
2928
+ reset$i();
2838
2929
  break;
2839
2930
  case 38 /* Event.Clipboard */:
2840
2931
  for (_d = 0, _e = state$6; _d < _e.length; _d++) {
@@ -2847,22 +2938,22 @@ function encode$3 (type, ts) {
2847
2938
  queue(tokens);
2848
2939
  }
2849
2940
  }
2850
- reset$i();
2941
+ reset$h();
2851
2942
  break;
2852
2943
  case 11 /* Event.Resize */: {
2853
- r = data$d;
2944
+ r = data$c;
2854
2945
  tokens.push(r.width);
2855
2946
  tokens.push(r.height);
2856
2947
  track$8(type, r.width, r.height);
2857
- reset$f();
2948
+ reset$e();
2858
2949
  queue(tokens);
2859
2950
  break;
2860
2951
  }
2861
2952
  case 26 /* Event.Unload */: {
2862
- u = data$b;
2953
+ u = data$a;
2863
2954
  tokens.push(u.name);
2864
2955
  tokens.push(u.persisted);
2865
- reset$b();
2956
+ reset$a();
2866
2957
  queue(tokens);
2867
2958
  break;
2868
2959
  }
@@ -2875,10 +2966,10 @@ function encode$3 (type, ts) {
2875
2966
  tokens.push(text$1(entry.data.value, "input", iTarget.privacy, false, entry.data.type));
2876
2967
  queue(tokens);
2877
2968
  }
2878
- reset$h();
2969
+ reset$g();
2879
2970
  break;
2880
2971
  case 21 /* Event.Selection */: {
2881
- s = data$c;
2972
+ s = data$b;
2882
2973
  if (s) {
2883
2974
  startTarget = metadata$2(s.start, type);
2884
2975
  endTarget = metadata$2(s.end, type);
@@ -2886,7 +2977,7 @@ function encode$3 (type, ts) {
2886
2977
  tokens.push(s.startOffset);
2887
2978
  tokens.push(endTarget.id);
2888
2979
  tokens.push(s.endOffset);
2889
- reset$e();
2980
+ reset$d();
2890
2981
  queue(tokens);
2891
2982
  }
2892
2983
  break;
@@ -2910,7 +3001,7 @@ function encode$3 (type, ts) {
2910
3001
  track$8(entry.event, entry.data.x, entry.data.y, entry.time);
2911
3002
  }
2912
3003
  }
2913
- reset$6();
3004
+ reset$5();
2914
3005
  break;
2915
3006
  case 42 /* Event.Change */:
2916
3007
  for (_k = 0, _l = state$1; _k < _l.length; _k++) {
@@ -2926,7 +3017,7 @@ function encode$3 (type, ts) {
2926
3017
  queue(tokens);
2927
3018
  }
2928
3019
  }
2929
- reset$9();
3020
+ reset$8();
2930
3021
  break;
2931
3022
  case 39 /* Event.Submit */:
2932
3023
  for (_m = 0, _o = state$3; _m < _o.length; _m++) {
@@ -2938,7 +3029,7 @@ function encode$3 (type, ts) {
2938
3029
  queue(tokens);
2939
3030
  }
2940
3031
  }
2941
- reset$d();
3032
+ reset$c();
2942
3033
  break;
2943
3034
  case 22 /* Event.Timeline */:
2944
3035
  for (_p = 0, _q = updates$2; _p < _q.length; _p++) {
@@ -2952,14 +3043,14 @@ function encode$3 (type, ts) {
2952
3043
  tokens.push(entry.data.context);
2953
3044
  queue(tokens, false);
2954
3045
  }
2955
- reset$c();
3046
+ reset$b();
2956
3047
  break;
2957
3048
  case 28 /* Event.Visibility */: {
2958
- v = data$a;
3049
+ v = data$9;
2959
3050
  tokens.push(v.visible);
2960
3051
  queue(tokens);
2961
3052
  visibility(t, v.visible);
2962
- reset$a();
3053
+ reset$9();
2963
3054
  break;
2964
3055
  }
2965
3056
  }
@@ -2969,8 +3060,8 @@ function encode$3 (type, ts) {
2969
3060
  }
2970
3061
 
2971
3062
  var state$1 = [];
2972
- function start$m() {
2973
- reset$9();
3063
+ function start$l() {
3064
+ reset$8();
2974
3065
  }
2975
3066
  function observe$4(root) {
2976
3067
  bind(root, "change", recompute$1, true);
@@ -2987,41 +3078,41 @@ function recompute$1(evt) {
2987
3078
  schedule$1(encode$3.bind(this, 42 /* Event.Change */));
2988
3079
  }
2989
3080
  }
2990
- function reset$9() {
3081
+ function reset$8() {
2991
3082
  state$1 = [];
2992
3083
  }
2993
- function stop$k() {
2994
- reset$9();
3084
+ function stop$j() {
3085
+ reset$8();
2995
3086
  }
2996
3087
 
2997
- function start$l() {
2998
- start$l.dn = 8 /* FunctionNames.InteractionStart */;
2999
- start$p();
3000
- start$w();
3088
+ function start$k() {
3089
+ start$k.dn = 8 /* FunctionNames.InteractionStart */;
3090
+ start$o();
3001
3091
  start$v();
3002
- start$t();
3003
3092
  start$u();
3004
3093
  start$s();
3005
- start$n();
3006
- start$j();
3094
+ start$t();
3007
3095
  start$r();
3008
3096
  start$m();
3097
+ start$i();
3009
3098
  start$q();
3010
- start$o();
3099
+ start$l();
3100
+ start$p();
3101
+ start$n();
3011
3102
  }
3012
- function stop$j() {
3013
- stop$n();
3014
- stop$u();
3103
+ function stop$i() {
3104
+ stop$m();
3015
3105
  stop$t();
3016
- stop$r();
3017
3106
  stop$s();
3018
3107
  stop$q();
3019
- stop$l();
3020
- stop$h();
3108
+ stop$r();
3021
3109
  stop$p();
3022
3110
  stop$k();
3111
+ stop$g();
3023
3112
  stop$o();
3024
- stop$m();
3113
+ stop$j();
3114
+ stop$n();
3115
+ stop$l();
3025
3116
  }
3026
3117
  function observe$3(root) {
3027
3118
  observe$1(root);
@@ -3041,8 +3132,8 @@ function observe$3(root) {
3041
3132
  var interaction = /*#__PURE__*/Object.freeze({
3042
3133
  __proto__: null,
3043
3134
  observe: observe$3,
3044
- start: start$l,
3045
- stop: stop$j
3135
+ start: start$k,
3136
+ stop: stop$i
3046
3137
  });
3047
3138
 
3048
3139
  var digitsRegex = /[^0-9\.]/g;
@@ -3059,16 +3150,16 @@ function ld(json) {
3059
3150
  switch (value) {
3060
3151
  case "article" /* JsonLD.Article */:
3061
3152
  case "recipe" /* JsonLD.Recipe */:
3062
- log(5 /* Dimension.SchemaType */, json[key]);
3063
- log(8 /* Dimension.AuthorName */, json["creator" /* JsonLD.Creator */]);
3064
- log(18 /* Dimension.Headline */, json["headline" /* JsonLD.Headline */]);
3153
+ log$1(5 /* Dimension.SchemaType */, json[key]);
3154
+ log$1(8 /* Dimension.AuthorName */, json["creator" /* JsonLD.Creator */]);
3155
+ log$1(18 /* Dimension.Headline */, json["headline" /* JsonLD.Headline */]);
3065
3156
  break;
3066
3157
  case "product" /* JsonLD.Product */:
3067
- log(5 /* Dimension.SchemaType */, json[key]);
3068
- log(10 /* Dimension.ProductName */, json["name" /* JsonLD.Name */]);
3069
- log(12 /* Dimension.ProductSku */, json["sku" /* JsonLD.Sku */]);
3158
+ log$1(5 /* Dimension.SchemaType */, json[key]);
3159
+ log$1(10 /* Dimension.ProductName */, json["name" /* JsonLD.Name */]);
3160
+ log$1(12 /* Dimension.ProductSku */, json["sku" /* JsonLD.Sku */]);
3070
3161
  if (json["brand" /* JsonLD.Brand */]) {
3071
- log(6 /* Dimension.ProductBrand */, json["brand" /* JsonLD.Brand */]["name" /* JsonLD.Name */]);
3162
+ log$1(6 /* Dimension.ProductBrand */, json["brand" /* JsonLD.Brand */]["name" /* JsonLD.Name */]);
3072
3163
  }
3073
3164
  break;
3074
3165
  case "aggregaterating" /* JsonLD.AggregateRating */:
@@ -3081,14 +3172,14 @@ function ld(json) {
3081
3172
  max(17 /* Metric.ReviewCount */, num$1(json["reviewCount" /* JsonLD.ReviewCount */]));
3082
3173
  break;
3083
3174
  case "offer" /* JsonLD.Offer */:
3084
- log(7 /* Dimension.ProductAvailability */, json["availability" /* JsonLD.Availability */]);
3085
- log(14 /* Dimension.ProductCondition */, json["itemCondition" /* JsonLD.ItemCondition */]);
3086
- log(13 /* Dimension.ProductCurrency */, json["priceCurrency" /* JsonLD.PriceCurrency */]);
3087
- log(12 /* Dimension.ProductSku */, json["sku" /* JsonLD.Sku */]);
3175
+ log$1(7 /* Dimension.ProductAvailability */, json["availability" /* JsonLD.Availability */]);
3176
+ log$1(14 /* Dimension.ProductCondition */, json["itemCondition" /* JsonLD.ItemCondition */]);
3177
+ log$1(13 /* Dimension.ProductCurrency */, json["priceCurrency" /* JsonLD.PriceCurrency */]);
3178
+ log$1(12 /* Dimension.ProductSku */, json["sku" /* JsonLD.Sku */]);
3088
3179
  max(13 /* Metric.ProductPrice */, num$1(json["price" /* JsonLD.Price */]));
3089
3180
  break;
3090
3181
  case "brand" /* JsonLD.Brand */:
3091
- log(6 /* Dimension.ProductBrand */, json["name" /* JsonLD.Name */]);
3182
+ log$1(6 /* Dimension.ProductBrand */, json["name" /* JsonLD.Name */]);
3092
3183
  break;
3093
3184
  }
3094
3185
  }
@@ -3144,7 +3235,7 @@ function processNode (inputNode, source, timestamp) {
3144
3235
  // We check for regions in the beginning when discovering document and
3145
3236
  // later whenever there are new additions or modifications to DOM (mutations)
3146
3237
  if (node === document) {
3147
- parse$1(document);
3238
+ parse(document);
3148
3239
  }
3149
3240
  checkDocumentStyles(node, timestamp);
3150
3241
  observe$2(node);
@@ -3152,7 +3243,7 @@ function processNode (inputNode, source, timestamp) {
3152
3243
  case Node.DOCUMENT_FRAGMENT_NODE: {
3153
3244
  var shadowRoot = node;
3154
3245
  if (shadowRoot.host) {
3155
- parse$1(shadowRoot);
3246
+ parse(shadowRoot);
3156
3247
  var type = typeof shadowRoot.constructor;
3157
3248
  if (type === "function" /* Constant.Function */ && shadowRoot.constructor.toString().indexOf("[native code]" /* Constant.NativeCode */) >= 0) {
3158
3249
  observe$2(shadowRoot);
@@ -3229,13 +3320,13 @@ function processNode (inputNode, source, timestamp) {
3229
3320
  var content = attributes["content" /* Constant.Content */];
3230
3321
  switch (attributes[key]) {
3231
3322
  case "og:title" /* Constant.ogTitle */:
3232
- log(20 /* Dimension.MetaTitle */, content);
3323
+ log$1(20 /* Dimension.MetaTitle */, content);
3233
3324
  break;
3234
3325
  case "og:type" /* Constant.ogType */:
3235
- log(19 /* Dimension.MetaType */, content);
3326
+ log$1(19 /* Dimension.MetaType */, content);
3236
3327
  break;
3237
3328
  case "generator" /* Constant.Generator */:
3238
- log(21 /* Dimension.Generator */, content);
3329
+ log$1(21 /* Dimension.Generator */, content);
3239
3330
  break;
3240
3331
  }
3241
3332
  }
@@ -3369,7 +3460,7 @@ function getCssRules(sheet) {
3369
3460
  cssRules = sheet ? sheet.cssRules : [];
3370
3461
  }
3371
3462
  catch (e) {
3372
- log$1(1 /* Code.CssRules */, 1 /* Severity.Warning */, e ? e.name : null);
3463
+ log(1 /* Code.CssRules */, 1 /* Severity.Warning */, e ? e.name : null);
3373
3464
  if (e && e.name !== "SecurityError") {
3374
3465
  throw e;
3375
3466
  }
@@ -3401,7 +3492,7 @@ function getAttributes(element) {
3401
3492
 
3402
3493
  var excludeClassNames = "load,active,fixed,visible,focus,show,collaps,animat" /* Constant.ExcludeClassNames */.split("," /* Constant.Comma */);
3403
3494
  var selectorMap = {};
3404
- function reset$8() {
3495
+ function reset$7() {
3405
3496
  selectorMap = {};
3406
3497
  }
3407
3498
  function get$1(input, type) {
@@ -3497,7 +3588,7 @@ function filter(value) {
3497
3588
  var selector = /*#__PURE__*/Object.freeze({
3498
3589
  __proto__: null,
3499
3590
  get: get$1,
3500
- reset: reset$8
3591
+ reset: reset$7
3501
3592
  });
3502
3593
 
3503
3594
  var index = 1;
@@ -3517,14 +3608,14 @@ var iframeMap = null; // Maps iframe's contentDocument => parent iframe element
3517
3608
  var iframeContentMap = null; // Maps parent iframe element => iframe's contentDocument & contentWindow
3518
3609
  var privacyMap = null; // Maps node => Privacy (enum)
3519
3610
  var fraudMap = null; // Maps node => FraudId (number)
3520
- function start$k() {
3521
- reset$7();
3522
- parse$1(document, true);
3611
+ function start$j() {
3612
+ reset$6();
3613
+ parse(document, true);
3523
3614
  }
3524
- function stop$i() {
3525
- reset$7();
3615
+ function stop$h() {
3616
+ reset$6();
3526
3617
  }
3527
- function reset$7() {
3618
+ function reset$6() {
3528
3619
  index = 1;
3529
3620
  values = [];
3530
3621
  updateMap = [];
@@ -3541,11 +3632,11 @@ function reset$7() {
3541
3632
  iframeContentMap = new WeakMap();
3542
3633
  privacyMap = new WeakMap();
3543
3634
  fraudMap = new WeakMap();
3544
- reset$8();
3635
+ reset$7();
3545
3636
  }
3546
3637
  // We parse new root nodes for any regions or masked nodes in the beginning (document) and
3547
3638
  // later whenever there are new additions or modifications to DOM (mutations)
3548
- function parse$1(root, init) {
3639
+ function parse(root, init) {
3549
3640
  if (init === void 0) { init = false; }
3550
3641
  // Wrap selectors in a try / catch block.
3551
3642
  // It's possible for script to receive invalid selectors, e.g. "'#id'" with extra quotes, and cause the code below to fail
@@ -3596,7 +3687,7 @@ function parse$1(root, init) {
3596
3687
  }
3597
3688
  }
3598
3689
  catch (e) {
3599
- log$1(5 /* Code.Selector */, 1 /* Severity.Warning */, e ? e.name : null);
3690
+ log(5 /* Code.Selector */, 1 /* Severity.Warning */, e ? e.name : null);
3600
3691
  }
3601
3692
  }
3602
3693
  function getId(node, autogen) {
@@ -3652,7 +3743,7 @@ function add(node, parent, data, source) {
3652
3743
  updateImageSize(values[id]);
3653
3744
  track$2(id, source);
3654
3745
  }
3655
- function update$1(node, parent, data, source) {
3746
+ function update(node, parent, data, source) {
3656
3747
  var id = getId(node);
3657
3748
  var parentId = parent ? getId(parent) : null;
3658
3749
  var previousId = getPreviousId(node);
@@ -3956,7 +4047,7 @@ var state = [];
3956
4047
  var initialTop = null;
3957
4048
  var initialBottom = null;
3958
4049
  var timeout$1 = null;
3959
- function start$j() {
4050
+ function start$i() {
3960
4051
  state = [];
3961
4052
  recompute();
3962
4053
  }
@@ -4025,7 +4116,7 @@ function getPositionNode(x, y) {
4025
4116
  }
4026
4117
  return node;
4027
4118
  }
4028
- function reset$6() {
4119
+ function reset$5() {
4029
4120
  state = [];
4030
4121
  initialTop = null;
4031
4122
  initialBottom = null;
@@ -4038,30 +4129,30 @@ function similar(last, current) {
4038
4129
  var dy = last.data.y - current.data.y;
4039
4130
  return dx * dx + dy * dy < 20 /* Setting.Distance */ * 20 /* Setting.Distance */ && current.time - last.time < 50 /* Setting.ScrollInterval */;
4040
4131
  }
4041
- function compute$7() {
4132
+ function compute$6() {
4042
4133
  var _a, _b;
4043
- compute$7.dn = 14 /* FunctionNames.ScrollCompute */;
4134
+ compute$6.dn = 14 /* FunctionNames.ScrollCompute */;
4044
4135
  if (initialTop) {
4045
4136
  var top_1 = metadata$2(initialTop, null);
4046
- log(31 /* Dimension.InitialScrollTop */, (_a = top_1 === null || top_1 === void 0 ? void 0 : top_1.hash) === null || _a === void 0 ? void 0 : _a.join("." /* Constant.Dot */));
4137
+ log$1(31 /* Dimension.InitialScrollTop */, (_a = top_1 === null || top_1 === void 0 ? void 0 : top_1.hash) === null || _a === void 0 ? void 0 : _a.join("." /* Constant.Dot */));
4047
4138
  }
4048
4139
  if (initialBottom) {
4049
4140
  var bottom = metadata$2(initialBottom, null);
4050
- log(32 /* Dimension.InitialScrollBottom */, (_b = bottom === null || bottom === void 0 ? void 0 : bottom.hash) === null || _b === void 0 ? void 0 : _b.join("." /* Constant.Dot */));
4141
+ log$1(32 /* Dimension.InitialScrollBottom */, (_b = bottom === null || bottom === void 0 ? void 0 : bottom.hash) === null || _b === void 0 ? void 0 : _b.join("." /* Constant.Dot */));
4051
4142
  }
4052
4143
  }
4053
- function stop$h() {
4144
+ function stop$g() {
4054
4145
  clearTimeout(timeout$1);
4055
4146
  state = [];
4056
4147
  initialTop = null;
4057
4148
  initialBottom = null;
4058
4149
  }
4059
4150
 
4060
- function start$i() {
4151
+ function start$h() {
4061
4152
  schedule$1(discover, 1 /* Priority.High */).then(function () {
4062
- measure(compute$9)();
4063
- measure(compute$b)();
4064
- measure(compute$7)();
4153
+ measure(compute$8)();
4154
+ measure(compute$a)();
4155
+ measure(compute$6)();
4065
4156
  });
4066
4157
  }
4067
4158
  function discover() {
@@ -4072,7 +4163,7 @@ function discover() {
4072
4163
  case 0:
4073
4164
  ts = time();
4074
4165
  timer = { id: id(), cost: 3 /* Metric.LayoutCost */ };
4075
- start$D(timer);
4166
+ start$C(timer);
4076
4167
  return [4 /*yield*/, traverse(document, timer, 0 /* Source.Discover */, ts)];
4077
4168
  case 1:
4078
4169
  _a.sent();
@@ -4080,19 +4171,19 @@ function discover() {
4080
4171
  return [4 /*yield*/, encode$4(5 /* Event.Discover */, timer, ts)];
4081
4172
  case 2:
4082
4173
  _a.sent();
4083
- stop$A(timer);
4174
+ stop$z(timer);
4084
4175
  return [2 /*return*/];
4085
4176
  }
4086
4177
  });
4087
4178
  });
4088
4179
  }
4089
4180
 
4090
- var data$9 = null;
4091
- function start$h() {
4181
+ var data$8 = null;
4182
+ function start$g() {
4092
4183
  if (!config$2.lean && config$2.upgrade) {
4093
4184
  config$2.upgrade("Config" /* Constant.Config */);
4094
4185
  }
4095
- data$9 = null;
4186
+ data$8 = null;
4096
4187
  }
4097
4188
  // Following call will upgrade the session from lean mode into the full mode retroactively from the start of the page.
4098
4189
  // As part of the lean mode, we do not send back any layout information - including discovery of DOM and mutations.
@@ -4102,7 +4193,7 @@ function upgrade(key) {
4102
4193
  // Upgrade only if Clarity was successfully activated on the page
4103
4194
  if (active() && config$2.lean) {
4104
4195
  config$2.lean = false;
4105
- data$9 = { key: key };
4196
+ data$8 = { key: key };
4106
4197
  // Update metadata to track we have upgraded this session
4107
4198
  callback();
4108
4199
  save();
@@ -4110,28 +4201,28 @@ function upgrade(key) {
4110
4201
  if (config$2.upgrade) {
4111
4202
  config$2.upgrade(key);
4112
4203
  }
4113
- encode$1(3 /* Event.Upgrade */);
4204
+ encode$2(3 /* Event.Upgrade */);
4114
4205
  if (config$2.lite) {
4115
- start$i();
4116
- start$z();
4206
+ start$h();
4207
+ start$y();
4117
4208
  }
4118
4209
  }
4119
4210
  }
4120
- function stop$g() {
4121
- data$9 = null;
4211
+ function stop$f() {
4212
+ data$8 = null;
4122
4213
  }
4123
4214
 
4124
4215
  var upgrade$1 = /*#__PURE__*/Object.freeze({
4125
4216
  __proto__: null,
4126
- get data () { return data$9; },
4127
- start: start$h,
4128
- stop: stop$g,
4217
+ get data () { return data$8; },
4218
+ start: start$g,
4219
+ stop: stop$f,
4129
4220
  upgrade: upgrade
4130
4221
  });
4131
4222
 
4132
- var data$8 = null;
4133
- function start$g() {
4134
- reset$5();
4223
+ var data$7 = null;
4224
+ function start$f() {
4225
+ reset$4();
4135
4226
  }
4136
4227
  function set(variable, value) {
4137
4228
  var values = typeof value === "string" ? [value] : value;
@@ -4173,23 +4264,23 @@ function identify(userId, sessionId, pageId, userHint) {
4173
4264
  }
4174
4265
  function log$2(variable, value) {
4175
4266
  if (active() && variable && value && typeof variable === "string" && variable.length < 255) {
4176
- var validValues = variable in data$8 ? data$8[variable] : [];
4267
+ var validValues = variable in data$7 ? data$7[variable] : [];
4177
4268
  for (var i = 0; i < value.length; i++) {
4178
4269
  if (typeof value[i] === "string" && value[i].length < 255) {
4179
4270
  validValues.push(value[i]);
4180
4271
  }
4181
4272
  }
4182
- data$8[variable] = validValues;
4273
+ data$7[variable] = validValues;
4183
4274
  }
4184
4275
  }
4185
- function compute$6() {
4186
- encode$1(34 /* Event.Variable */);
4276
+ function compute$5() {
4277
+ encode$2(34 /* Event.Variable */);
4187
4278
  }
4188
- function reset$5() {
4189
- data$8 = {};
4279
+ function reset$4() {
4280
+ data$7 = {};
4190
4281
  }
4191
- function stop$f() {
4192
- reset$5();
4282
+ function stop$e() {
4283
+ reset$4();
4193
4284
  }
4194
4285
  function redact(input) {
4195
4286
  return input && input.length >= 5 /* Setting.WordLength */
@@ -4223,1337 +4314,1256 @@ function detect(input) {
4223
4314
 
4224
4315
  var variable = /*#__PURE__*/Object.freeze({
4225
4316
  __proto__: null,
4226
- compute: compute$6,
4227
- get data () { return data$8; },
4317
+ compute: compute$5,
4318
+ get data () { return data$7; },
4228
4319
  identify: identify,
4229
- reset: reset$5,
4320
+ reset: reset$4,
4230
4321
  set: set,
4231
- start: start$g,
4232
- stop: stop$f
4322
+ start: start$f,
4323
+ stop: stop$e
4233
4324
  });
4234
4325
 
4235
- var signalCallback = null;
4236
- function signal(cb) {
4237
- signalCallback = cb;
4238
- }
4239
- function parseSignals(signalsPayload) {
4240
- try {
4241
- var parsedSignals = JSON.parse(signalsPayload);
4242
- return parsedSignals;
4243
- }
4244
- catch (_a) {
4245
- return [];
4246
- }
4247
- }
4248
- function signalsEvent(signalsPayload) {
4249
- try {
4250
- if (!signalCallback) {
4251
- return;
4252
- }
4253
- var signals = parseSignals(signalsPayload);
4254
- for (var _i = 0, signals_1 = signals; _i < signals_1.length; _i++) {
4255
- var signal_1 = signals_1[_i];
4256
- signalCallback(signal_1);
4326
+ function encode$2 (event) {
4327
+ var t = time();
4328
+ var tokens = [t, event];
4329
+ switch (event) {
4330
+ case 4 /* Event.Baseline */: {
4331
+ var b = state$b;
4332
+ if (b) {
4333
+ tokens = [b.time, b.event];
4334
+ tokens.push(b.data.visible);
4335
+ tokens.push(b.data.docWidth);
4336
+ tokens.push(b.data.docHeight);
4337
+ tokens.push(b.data.screenWidth);
4338
+ tokens.push(b.data.screenHeight);
4339
+ tokens.push(b.data.scrollX);
4340
+ tokens.push(b.data.scrollY);
4341
+ tokens.push(b.data.pointerX);
4342
+ tokens.push(b.data.pointerY);
4343
+ tokens.push(b.data.activityTime);
4344
+ tokens.push(b.data.scrollTime);
4345
+ tokens.push(b.data.pointerTime);
4346
+ tokens.push(b.data.moveX);
4347
+ tokens.push(b.data.moveY);
4348
+ tokens.push(b.data.moveTime);
4349
+ tokens.push(b.data.downX);
4350
+ tokens.push(b.data.downY);
4351
+ tokens.push(b.data.downTime);
4352
+ tokens.push(b.data.upX);
4353
+ tokens.push(b.data.upY);
4354
+ tokens.push(b.data.upTime);
4355
+ tokens.push(b.data.pointerPrevX);
4356
+ tokens.push(b.data.pointerPrevY);
4357
+ tokens.push(b.data.pointerPrevTime);
4358
+ queue(tokens, false);
4359
+ }
4360
+ reset$s();
4361
+ break;
4257
4362
  }
4258
- }
4259
- catch (_a) {
4260
- //do nothing
4261
- }
4262
- }
4263
-
4264
- var modules$1 = [baseline, dimension, variable, limit, summary, metadata$1, envelope$1, upload$1, ping$1, upgrade$1, extract];
4265
- function start$f() {
4266
- // Metric needs to be initialized before we can start measuring. so metric is not wrapped in measure
4267
- start$G();
4268
- for (var _i = 0, modules_1 = modules$1; _i < modules_1.length; _i++) {
4269
- var x = modules_1[_i];
4270
- measure(x.start)();
4271
- }
4272
- }
4273
- function stop$e() {
4274
- // Stop modules in the reverse order of their initialization
4275
- // The ordering below should respect inter-module dependency.
4276
- // E.g. if upgrade depends on upload, then upgrade needs to end before upload.
4277
- // Similarly, if upload depends on metadata, upload needs to end before metadata.
4278
- for (var _i = 0, _a = modules$1.slice().reverse(); _i < _a.length; _i++) {
4279
- var x = _a[_i];
4280
- measure(x.stop)();
4281
- }
4282
- stop$D();
4283
- }
4284
- function compute$5() {
4285
- compute$6();
4286
- compute$e();
4287
- compute$2();
4288
- compute$d();
4289
- compute$c();
4290
- compute$3();
4291
- compute$4();
4292
- }
4293
-
4294
- var discoverBytes = 0;
4295
- var playbackBytes = 0;
4296
- var playback;
4297
- var analysis;
4298
- var timeout = null;
4299
- var transit;
4300
- var active$1;
4301
- var queuedTime = 0;
4302
- var leanLimit = false;
4303
- var track$1;
4304
- function start$e() {
4305
- active$1 = true;
4306
- discoverBytes = 0;
4307
- playbackBytes = 0;
4308
- leanLimit = false;
4309
- queuedTime = 0;
4310
- playback = [];
4311
- analysis = [];
4312
- transit = {};
4313
- track$1 = null;
4314
- }
4315
- function queue(tokens, transmit) {
4316
- if (transmit === void 0) { transmit = true; }
4317
- if (active$1) {
4318
- var now = time();
4319
- var type = tokens.length > 1 ? tokens[1] : null;
4320
- var event_1 = JSON.stringify(tokens);
4321
- if (!config$2.lean) {
4322
- leanLimit = false;
4323
- }
4324
- else if (!leanLimit && playbackBytes + event_1.length > 10485760 /* Setting.PlaybackBytesLimit */) {
4325
- log$1(10 /* Code.LeanLimit */, 0 /* Severity.Info */);
4326
- leanLimit = true;
4363
+ case 25 /* Event.Ping */:
4364
+ tokens.push(data$g.gap);
4365
+ queue(tokens);
4366
+ break;
4367
+ case 35 /* Event.Limit */:
4368
+ tokens.push(data$6.check);
4369
+ queue(tokens, false);
4370
+ break;
4371
+ case 3 /* Event.Upgrade */:
4372
+ tokens.push(data$8.key);
4373
+ queue(tokens);
4374
+ break;
4375
+ case 2 /* Event.Upload */:
4376
+ tokens.push(track.sequence);
4377
+ tokens.push(track.attempts);
4378
+ tokens.push(track.status);
4379
+ queue(tokens, false);
4380
+ break;
4381
+ case 24 /* Event.Custom */:
4382
+ // not all custom events have a key - if it wasn't passed server handles just value
4383
+ data$j.key && tokens.push(data$j.key);
4384
+ tokens.push(data$j.value);
4385
+ queue(tokens);
4386
+ break;
4387
+ case 34 /* Event.Variable */: {
4388
+ var variableKeys = Object.keys(data$7);
4389
+ if (variableKeys.length > 0) {
4390
+ for (var _i = 0, variableKeys_1 = variableKeys; _i < variableKeys_1.length; _i++) {
4391
+ var v = variableKeys_1[_i];
4392
+ tokens.push(v);
4393
+ tokens.push(data$7[v]);
4394
+ }
4395
+ reset$4();
4396
+ queue(tokens, false);
4397
+ }
4398
+ break;
4327
4399
  }
4328
- switch (type) {
4329
- // biome-ignore lint/suspicious/noFallthroughSwitchClause: we want discover bytes to also count as playback bytes
4330
- case 5 /* Event.Discover */:
4331
- if (leanLimit) {
4332
- break;
4400
+ case 0 /* Event.Metric */: {
4401
+ var metricKeys = Object.keys(updates$3);
4402
+ if (metricKeys.length > 0) {
4403
+ for (var _a = 0, metricKeys_1 = metricKeys; _a < metricKeys_1.length; _a++) {
4404
+ var m = metricKeys_1[_a];
4405
+ var key = Number.parseInt(m, 10);
4406
+ tokens.push(key);
4407
+ // For computation, we need microseconds precision that performance.now() API offers
4408
+ // However, for data over the wire, we round it off to milliseconds precision.
4409
+ tokens.push(Math.round(updates$3[m]));
4333
4410
  }
4334
- discoverBytes += event_1.length;
4335
- case 37 /* Event.Box */:
4336
- case 6 /* Event.Mutation */:
4337
- case 43 /* Event.Snapshot */:
4338
- case 45 /* Event.StyleSheetAdoption */:
4339
- case 46 /* Event.StyleSheetUpdate */:
4340
- if (leanLimit) {
4341
- break;
4411
+ reset$q();
4412
+ queue(tokens, false);
4413
+ }
4414
+ break;
4415
+ }
4416
+ case 1 /* Event.Dimension */: {
4417
+ var dimensionKeys = Object.keys(updates);
4418
+ if (dimensionKeys.length > 0) {
4419
+ for (var _b = 0, dimensionKeys_1 = dimensionKeys; _b < dimensionKeys_1.length; _b++) {
4420
+ var d = dimensionKeys_1[_b];
4421
+ var key = Number.parseInt(d, 10);
4422
+ tokens.push(key);
4423
+ tokens.push(updates[d]);
4342
4424
  }
4343
- playbackBytes += event_1.length;
4344
- playback.push(event_1);
4345
- break;
4346
- default:
4347
- analysis.push(event_1);
4348
- break;
4425
+ reset$3();
4426
+ queue(tokens, false);
4427
+ }
4428
+ break;
4349
4429
  }
4350
- // Increment event count metric
4351
- count$1(25 /* Metric.EventCount */);
4352
- // Following two checks are precautionary and act as a fail safe mechanism to get out of unexpected situations.
4353
- // Check 1: If for any reason the upload hasn't happened after waiting for 2x the config.delay time,
4354
- // reset the timer. This allows Clarity to attempt an upload again.
4355
- var gap = delay();
4356
- if (now - queuedTime > gap * 2) {
4357
- clearTimeout(timeout);
4358
- timeout = null;
4430
+ case 36 /* Event.Summary */: {
4431
+ var eventKeys = Object.keys(data$f);
4432
+ if (eventKeys.length > 0) {
4433
+ for (var _c = 0, eventKeys_1 = eventKeys; _c < eventKeys_1.length; _c++) {
4434
+ var e = eventKeys_1[_c];
4435
+ var key = Number.parseInt(e, 10);
4436
+ tokens.push(key);
4437
+ tokens.push([].concat.apply([], data$f[e]));
4438
+ }
4439
+ reset$o();
4440
+ queue(tokens, false);
4441
+ }
4442
+ break;
4359
4443
  }
4360
- // Transmit Check: When transmit is set to true (default), it indicates that we should schedule an upload
4361
- // However, in certain scenarios - like metric calculation - which are triggered as part of an existing upload
4362
- // We enrich the data going out with the existing upload. In these cases, call to upload comes with 'transmit' set to false.
4363
- if (transmit && timeout === null) {
4364
- if (type !== 25 /* Event.Ping */) {
4365
- reset$q();
4444
+ case 40 /* Event.Extract */: {
4445
+ var extractKeys = keys;
4446
+ for (var _d = 0, _e = Array.from(extractKeys); _d < _e.length; _d++) {
4447
+ var e = _e[_d];
4448
+ tokens.push(e);
4449
+ var token = [];
4450
+ for (var d in data$i[e]) {
4451
+ var key = Number.parseInt(d, 10);
4452
+ token.push(key);
4453
+ token.push(data$i[e][d]);
4454
+ }
4455
+ tokens.push(token);
4366
4456
  }
4367
- timeout = setTimeout$1(upload, gap);
4368
- queuedTime = now;
4369
- check$2(playbackBytes);
4457
+ reset$r();
4458
+ queue(tokens, false);
4459
+ }
4460
+ }
4461
+ }
4462
+
4463
+ var data$6;
4464
+ function start$e() {
4465
+ data$6 = { check: 0 /* Check.None */ };
4466
+ }
4467
+ function check$3(bytes) {
4468
+ if (data$6.check === 0 /* Check.None */) {
4469
+ var reason = data$6.check;
4470
+ reason = data$3.sequence >= 128 /* Setting.PayloadLimit */ ? 1 /* Check.Payload */ : reason;
4471
+ reason = data$3.pageNum >= 128 /* Setting.PageLimit */ ? 7 /* Check.Page */ : reason;
4472
+ reason = time() > 7200000 /* Setting.ShutdownLimit */ ? 2 /* Check.Shutdown */ : reason;
4473
+ reason = bytes > 10485760 /* Setting.PlaybackBytesLimit */ ? 2 /* Check.Shutdown */ : reason;
4474
+ if (reason !== data$6.check) {
4475
+ trigger(reason);
4370
4476
  }
4371
4477
  }
4372
4478
  }
4479
+ function trigger(reason) {
4480
+ data$6.check = reason;
4481
+ // limit the dimensions we collect, but we don't need to stop Clarity entirely if we hit the limit
4482
+ if (reason !== 5 /* Check.Collection */) {
4483
+ clear();
4484
+ stop();
4485
+ }
4486
+ }
4487
+ function compute$4() {
4488
+ if (data$6.check !== 0 /* Check.None */) {
4489
+ encode$2(35 /* Event.Limit */);
4490
+ }
4491
+ }
4373
4492
  function stop$d() {
4374
- clearTimeout(timeout);
4375
- upload(true);
4376
- discoverBytes = 0;
4377
- playbackBytes = 0;
4378
- leanLimit = false;
4379
- queuedTime = 0;
4380
- playback = [];
4381
- analysis = [];
4382
- transit = {};
4383
- track$1 = null;
4384
- active$1 = false;
4493
+ data$6 = null;
4385
4494
  }
4386
- function upload(final) {
4387
- if (final === void 0) { final = false; }
4388
- return __awaiter(this, void 0, void 0, function () {
4389
- var sendPlaybackBytes, last, e, a, p, encoded, payload, zipped, _a;
4390
- return __generator(this, function (_b) {
4391
- switch (_b.label) {
4392
- case 0:
4393
- timeout = null;
4394
- sendPlaybackBytes = config$2.lean === false && playbackBytes > 0 && (playbackBytes < 1048576 /* Setting.MaxFirstPayloadBytes */ || data$1.sequence > 0);
4395
- if (sendPlaybackBytes) {
4396
- max(1 /* Metric.Playback */, 1 /* BooleanFlag.True */);
4397
- }
4398
- // CAUTION: Ensure "transmit" is set to false in the queue function for following events
4399
- // Otherwise you run a risk of infinite loop.
4400
- compute$b();
4401
- compute$8();
4402
- compute$5();
4403
- compute$a();
4404
- last = final === true;
4405
- e = JSON.stringify(envelope(last));
4406
- a = "[".concat(analysis.join(), "]");
4407
- p = sendPlaybackBytes ? "[".concat(playback.join(), "]") : "" /* Constant.Empty */;
4408
- encoded = { e: e, a: a, p: p };
4409
- payload = stringify(encoded);
4410
- if (!last) return [3 /*break*/, 1];
4411
- _a = null;
4412
- return [3 /*break*/, 3];
4413
- case 1: return [4 /*yield*/, compress(payload)];
4414
- case 2:
4415
- _a = _b.sent();
4416
- _b.label = 3;
4417
- case 3:
4418
- zipped = _a;
4419
- sum(2 /* Metric.TotalBytes */, zipped ? zipped.length : payload.length);
4420
- send(payload, zipped, data$1.sequence, last);
4421
- // Clear out events now that payload has been dispatched
4422
- analysis = [];
4423
- if (sendPlaybackBytes) {
4424
- playback = [];
4425
- playbackBytes = 0;
4426
- discoverBytes = 0;
4427
- leanLimit = false;
4428
- }
4429
- return [2 /*return*/];
4430
- }
4431
- });
4432
- });
4495
+
4496
+ var limit = /*#__PURE__*/Object.freeze({
4497
+ __proto__: null,
4498
+ check: check$3,
4499
+ compute: compute$4,
4500
+ get data () { return data$6; },
4501
+ start: start$e,
4502
+ stop: stop$d,
4503
+ trigger: trigger
4504
+ });
4505
+
4506
+ var data$5 = null;
4507
+ var updates = null;
4508
+ var limited = false;
4509
+ function start$d() {
4510
+ data$5 = {};
4511
+ updates = {};
4512
+ limited = false;
4433
4513
  }
4434
- function stringify(encoded) {
4435
- return encoded.p.length > 0 ? "{\"e\":".concat(encoded.e, ",\"a\":").concat(encoded.a, ",\"p\":").concat(encoded.p, "}") : "{\"e\":".concat(encoded.e, ",\"a\":").concat(encoded.a, "}");
4514
+ function stop$c() {
4515
+ data$5 = {};
4516
+ updates = {};
4517
+ limited = false;
4436
4518
  }
4437
- function send(payload, zipped, sequence, beacon) {
4438
- if (beacon === void 0) { beacon = false; }
4439
- // Upload data if a valid URL is defined in the config
4440
- if (typeof config$2.upload === "string") {
4441
- var url_1 = config$2.upload;
4442
- var dispatched = false;
4443
- // If it's the last payload, attempt to upload using sendBeacon first.
4444
- // The advantage to using sendBeacon is that browser can decide to upload asynchronously, improving chances of success
4445
- // However, we don't want to rely on it for every payload, since we have no ability to retry if the upload failed.
4446
- // Also, in case of sendBeacon, we do not have a way to alter HTTP headers and therefore can't send compressed payload
4447
- if (beacon && "sendBeacon" in navigator) {
4448
- try {
4449
- // Navigator needs to be bound to sendBeacon before it is used to avoid errors in some browsers
4450
- dispatched = navigator.sendBeacon.bind(navigator)(url_1, payload);
4451
- if (dispatched) {
4452
- done(sequence);
4453
- }
4454
- }
4455
- catch (_a) {
4456
- /* do nothing - and we will automatically fallback to XHR below */
4457
- }
4458
- }
4459
- // Before initiating XHR upload, we check if the data has already been uploaded using sendBeacon
4460
- // There are two cases when dispatched could still be false:
4461
- // a) It's not the last payload, and therefore we didn't attempt sending sendBeacon
4462
- // b) It's the last payload, however, we failed to queue sendBeacon call and need to now fall back to XHR.
4463
- // E.g. if data is over 64KB, several user agents (like Chrome) will reject to queue the sendBeacon call.
4464
- if (dispatched === false) {
4465
- // While tracking payload for retry, we only track string value of the payload to err on the safe side
4466
- // Not all browsers support compression API and the support for it in supported browsers is still experimental
4467
- if (sequence in transit) {
4468
- transit[sequence].attempts++;
4469
- }
4470
- else {
4471
- transit[sequence] = { data: payload, attempts: 1 };
4472
- }
4473
- var xhr_1 = new XMLHttpRequest();
4474
- xhr_1.open("POST", url_1, true);
4475
- xhr_1.timeout = 15000 /* Setting.UploadTimeout */;
4476
- xhr_1.ontimeout = function () {
4477
- report(new Error("".concat("Timeout" /* Constant.Timeout */, " : ").concat(url_1)));
4478
- };
4479
- if (sequence !== null) {
4480
- xhr_1.onreadystatechange = function () {
4481
- measure(check$3)(xhr_1, sequence);
4482
- };
4483
- }
4484
- xhr_1.withCredentials = true;
4485
- if (zipped) {
4486
- // If we do have valid compressed array, send it with appropriate HTTP headers so server can decode it appropriately
4487
- xhr_1.setRequestHeader("Accept" /* Constant.Accept */, "application/x-clarity-gzip" /* Constant.ClarityGzip */);
4488
- xhr_1.send(zipped);
4489
- }
4490
- else {
4491
- // In all other cases, continue sending string back to the server
4492
- xhr_1.send(payload);
4493
- }
4519
+ function log$1(dimension, inputValue) {
4520
+ // Check valid value before moving ahead
4521
+ if (inputValue) {
4522
+ // Ensure received value is casted into a string if it wasn't a string to begin with
4523
+ var value = "".concat(inputValue);
4524
+ if (!(dimension in data$5)) {
4525
+ data$5[dimension] = [];
4494
4526
  }
4495
- }
4496
- else if (config$2.upload) {
4497
- var callback = config$2.upload;
4498
- callback(payload);
4499
- done(sequence);
4500
- }
4501
- }
4502
- function check$3(xhr, sequence) {
4503
- var transitData = transit[sequence];
4504
- if (xhr && xhr.readyState === 4 /* XMLReadyState.Done */ && transitData) {
4505
- // Attempt send payload again (as configured in settings) if we do not receive a success (2XX) response code back from the server
4506
- if ((xhr.status < 200 || xhr.status > 208) && transitData.attempts <= 1 /* Setting.RetryLimit */) {
4507
- // We re-attempt in all cases except when server explicitly rejects our request with 4XX error
4508
- if (xhr.status >= 400 && xhr.status < 500) {
4509
- // In case of a 4XX response from the server, we bail out instead of trying again
4510
- trigger(6 /* Check.Server */);
4511
- }
4512
- else {
4513
- // Browser will send status = 0 when it refuses to put network request over the wire
4514
- // This could happen for several reasons, couple of known ones are:
4515
- // 1: Browsers block upload because of content security policy violation
4516
- // 2: Safari will terminate pending XHR requests with status code 0 if the user navigates away from the page
4517
- // In any case, we switch the upload URL to fallback configuration (if available) before re-trying one more time
4518
- if (xhr.status === 0) {
4519
- config$2.upload = config$2.fallback ? config$2.fallback : config$2.upload;
4527
+ if (data$5[dimension].indexOf(value) < 0) {
4528
+ // Limit check to ensure we have a cap on number of dimensions we can collect
4529
+ if (data$5[dimension].length > 128 /* Setting.CollectionLimit */) {
4530
+ if (!limited) {
4531
+ limited = true;
4532
+ trigger(5 /* Check.Collection */);
4520
4533
  }
4521
- // In all other cases, re-attempt sending the same data
4522
- // For retry we always fallback to string payload, even though we may have attempted
4523
- // sending zipped payload earlier
4524
- send(transitData.data, null, sequence);
4525
- }
4526
- }
4527
- else {
4528
- track$1 = { sequence: sequence, attempts: transitData.attempts, status: xhr.status };
4529
- // Send back an event only if we were not successful in our first attempt
4530
- if (transitData.attempts > 1) {
4531
- encode$1(2 /* Event.Upload */);
4532
- }
4533
- // Handle response if it was a 200 response with a valid body
4534
- if (xhr.status === 200 && xhr.responseText) {
4535
- response(xhr.responseText);
4536
- }
4537
- // If we exhausted our retries then trigger Clarity's shutdown for this page since the data will be incomplete
4538
- if (xhr.status === 0) {
4539
- // And, right before we terminate the session, we will attempt one last time to see if we can use
4540
- // different transport option (sendBeacon vs. XHR) to get this data to the server for analysis purposes
4541
- send(transitData.data, null, sequence, true);
4542
- trigger(3 /* Check.Retry */);
4534
+ return;
4543
4535
  }
4544
- // Signal that this request completed successfully
4545
- if (xhr.status >= 200 && xhr.status <= 208) {
4546
- done(sequence);
4536
+ data$5[dimension].push(value);
4537
+ // If this is a new value, track it as part of updates object
4538
+ // This allows us to only send back new values in subsequent payloads
4539
+ if (!(dimension in updates)) {
4540
+ updates[dimension] = [];
4547
4541
  }
4548
- // Stop tracking this payload now that it's all done
4549
- delete transit[sequence];
4542
+ updates[dimension].push(value);
4550
4543
  }
4551
4544
  }
4552
4545
  }
4553
- function done(sequence) {
4554
- // If we everything went successfully, and it is the first sequence, save this session for future reference
4555
- if (sequence === 1) {
4556
- save();
4557
- callback();
4558
- }
4559
- }
4560
- function delay() {
4561
- // Progressively increase delay as we continue to send more payloads from the client to the server
4562
- // If we are not uploading data to a server, and instead invoking UploadCallback, in that case keep returning configured value
4563
- var gap = config$2.lean === false && discoverBytes > 0 ? 100 /* Setting.MinUploadDelay */ : data$1.sequence * config$2.delay;
4564
- return typeof config$2.upload === "string" ? Math.max(Math.min(gap, 30000 /* Setting.MaxUploadDelay */), 100 /* Setting.MinUploadDelay */) : config$2.delay;
4546
+ function compute$3() {
4547
+ encode$2(1 /* Event.Dimension */);
4565
4548
  }
4566
- function response(payload) {
4567
- var lines = payload && payload.length > 0 ? payload.split("\n") : [];
4568
- for (var _i = 0, lines_1 = lines; _i < lines_1.length; _i++) {
4569
- var line = lines_1[_i];
4570
- var parts = line && line.length > 0 ? line.split(/ (.*)/) : ["" /* Constant.Empty */];
4571
- switch (parts[0]) {
4572
- case "END" /* Constant.End */:
4573
- // Clear out session storage and end the session so we can start fresh the next time
4574
- trigger(6 /* Check.Server */);
4575
- break;
4576
- case "UPGRADE" /* Constant.Upgrade */:
4577
- // Upgrade current session to send back playback information
4578
- upgrade("Auto" /* Constant.Auto */);
4579
- break;
4580
- case "ACTION" /* Constant.Action */:
4581
- // Invoke action callback, if configured and has a valid value
4582
- if (config$2.action && parts.length > 1) {
4583
- config$2.action(parts[1]);
4584
- }
4585
- break;
4586
- case "EXTRACT" /* Constant.Extract */:
4587
- if (parts.length > 1) {
4588
- trigger$1(parts[1]);
4589
- }
4590
- break;
4591
- case "SIGNAL" /* Constant.Signal */:
4592
- if (parts.length > 1) {
4593
- signalsEvent(parts[1]);
4594
- }
4595
- break;
4596
- }
4597
- }
4549
+ function reset$3() {
4550
+ updates = {};
4551
+ limited = false;
4598
4552
  }
4599
4553
 
4600
- var history$3 = {};
4601
- var data$7;
4602
- function start$d() {
4603
- bind(window, "error", handler);
4604
- history$3 = {};
4554
+ var dimension = /*#__PURE__*/Object.freeze({
4555
+ __proto__: null,
4556
+ compute: compute$3,
4557
+ get data () { return data$5; },
4558
+ log: log$1,
4559
+ reset: reset$3,
4560
+ start: start$d,
4561
+ stop: stop$c,
4562
+ get updates () { return updates; }
4563
+ });
4564
+
4565
+ function config$1(track) {
4566
+ trackConsent(track ? 1 /* ConsentType.Implicit */ : 0 /* ConsentType.None */);
4605
4567
  }
4606
- function handler(error) {
4607
- handler.dn = 4 /* FunctionNames.ScriptHandler */;
4608
- var e = error.error || error;
4609
- // While rare, it's possible for code to fail repeatedly during the lifetime of the same page
4610
- // In those cases, we only want to log the failure first few times and not spam logs with redundant information.
4611
- if (!(e.message in history$3)) {
4612
- history$3[e.message] = 0;
4613
- }
4614
- if (history$3[e.message]++ >= 5 /* Setting.ScriptErrorLimit */) {
4615
- return true;
4616
- }
4617
- // Send back information only if the handled error has valid information
4618
- if (e === null || e === void 0 ? void 0 : e.message) {
4619
- data$7 = {
4620
- message: e.message,
4621
- line: error.lineno,
4622
- column: error.colno,
4623
- stack: e.stack,
4624
- source: error.filename,
4625
- };
4626
- encode$2(31 /* Event.ScriptError */);
4627
- }
4628
- return true;
4568
+ // When we get consent signal as false, we restart the service and track config as false.
4569
+ function consent$1() {
4570
+ trackConsent(2 /* ConsentType.General */);
4629
4571
  }
4630
-
4631
- function encode$2 (type) {
4632
- return __awaiter(this, void 0, void 0, function () {
4633
- var tokens;
4634
- return __generator(this, function (_a) {
4635
- tokens = [time(), type];
4636
- switch (type) {
4637
- case 31 /* Event.ScriptError */:
4638
- tokens.push(data$7.message);
4639
- tokens.push(data$7.line);
4640
- tokens.push(data$7.column);
4641
- tokens.push(data$7.stack);
4642
- tokens.push(url$1(data$7.source));
4643
- queue(tokens);
4644
- break;
4645
- case 33 /* Event.Log */:
4646
- if (data$6) {
4647
- tokens.push(data$6.code);
4648
- tokens.push(data$6.name);
4649
- tokens.push(data$6.message);
4650
- tokens.push(data$6.stack);
4651
- tokens.push(data$6.severity);
4652
- queue(tokens, false);
4653
- }
4654
- break;
4655
- case 41 /* Event.Fraud */:
4656
- if (data$f) {
4657
- tokens.push(data$f.id);
4658
- tokens.push(data$f.target);
4659
- tokens.push(data$f.checksum);
4660
- queue(tokens, false);
4661
- }
4662
- break;
4663
- }
4664
- return [2 /*return*/];
4665
- });
4666
- });
4572
+ function trackConsent(consent) {
4573
+ log$1(36 /* Dimension.Consent */, consent.toString());
4667
4574
  }
4668
4575
 
4669
- var history$2 = {};
4670
- var data$6;
4576
+ var data$4 = null;
4577
+ var callbacks = [];
4578
+ var electron = 0 /* BooleanFlag.False */;
4579
+ var rootDomain = null;
4671
4580
  function start$c() {
4672
- history$2 = {};
4673
- }
4674
- function log$1(code, severity, name, message, stack) {
4675
- if (name === void 0) { name = null; }
4676
- if (message === void 0) { message = null; }
4677
- if (stack === void 0) { stack = null; }
4678
- var key = name ? "".concat(name, "|").concat(message) : "";
4679
- // While rare, it's possible for code to fail repeatedly during the lifetime of the same page
4680
- // In those cases, we only want to log the failure once and not spam logs with redundant information.
4681
- if (code in history$2 && history$2[code].indexOf(key) >= 0) {
4682
- return;
4581
+ var _a, _b, _c;
4582
+ rootDomain = null;
4583
+ var ua = navigator && "userAgent" in navigator ? navigator.userAgent : "" /* Constant.Empty */;
4584
+ var timezone = (_c = (_b = (_a = Intl === null || Intl === void 0 ? void 0 : Intl.DateTimeFormat()) === null || _a === void 0 ? void 0 : _a.resolvedOptions()) === null || _b === void 0 ? void 0 : _b.timeZone) !== null && _c !== void 0 ? _c : "";
4585
+ var timezoneOffset = new Date().getTimezoneOffset().toString();
4586
+ var ancestorOrigins = window.location.ancestorOrigins ? Array.from(window.location.ancestorOrigins).toString() : "";
4587
+ var title = (document === null || document === void 0 ? void 0 : document.title) ? document.title : "" /* Constant.Empty */;
4588
+ electron = ua.indexOf("Electron" /* Constant.Electron */) > 0 ? 1 /* BooleanFlag.True */ : 0 /* BooleanFlag.False */;
4589
+ // Populate ids for this page
4590
+ var s = session();
4591
+ var u = user();
4592
+ var projectId = config$2.projectId || hash(location.host);
4593
+ data$4 = { projectId: projectId, userId: u.id, sessionId: s.session, pageNum: s.count };
4594
+ // Override configuration based on what's in the session storage, unless it is blank (e.g. using upload callback, like in devtools)
4595
+ config$2.lean = config$2.track && s.upgrade !== null ? s.upgrade === 0 /* BooleanFlag.False */ : config$2.lean;
4596
+ config$2.upload =
4597
+ config$2.track && typeof config$2.upload === "string" && s.upload && s.upload.length > "https://" /* Constant.HTTPS */.length ? s.upload : config$2.upload;
4598
+ // Log page metadata as dimensions
4599
+ log$1(0 /* Dimension.UserAgent */, ua);
4600
+ log$1(3 /* Dimension.PageTitle */, title);
4601
+ log$1(1 /* Dimension.Url */, url$1(location.href, !!electron));
4602
+ log$1(2 /* Dimension.Referrer */, document.referrer);
4603
+ log$1(15 /* Dimension.TabId */, tab());
4604
+ log$1(16 /* Dimension.PageLanguage */, document.documentElement.lang);
4605
+ log$1(17 /* Dimension.DocumentDirection */, document.dir);
4606
+ log$1(26 /* Dimension.DevicePixelRatio */, "".concat(window.devicePixelRatio));
4607
+ log$1(28 /* Dimension.Dob */, u.dob.toString());
4608
+ log$1(29 /* Dimension.CookieVersion */, u.version.toString());
4609
+ log$1(33 /* Dimension.AncestorOrigins */, ancestorOrigins);
4610
+ log$1(34 /* Dimension.Timezone */, timezone);
4611
+ log$1(35 /* Dimension.TimezoneOffset */, timezoneOffset);
4612
+ // Capture additional metadata as metrics
4613
+ max(0 /* Metric.ClientTimestamp */, s.ts);
4614
+ max(1 /* Metric.Playback */, 0 /* BooleanFlag.False */);
4615
+ max(35 /* Metric.Electron */, electron);
4616
+ // Capture navigator specific dimensions
4617
+ if (navigator) {
4618
+ log$1(9 /* Dimension.Language */, navigator.language);
4619
+ max(33 /* Metric.HardwareConcurrency */, navigator.hardwareConcurrency);
4620
+ max(32 /* Metric.MaxTouchPoints */, navigator.maxTouchPoints);
4621
+ // biome-ignore lint/suspicious/noExplicitAny: not all browsers support navigator.deviceMemory
4622
+ max(34 /* Metric.DeviceMemory */, Math.round(navigator.deviceMemory));
4623
+ userAgentData();
4683
4624
  }
4684
- data$6 = { code: code, name: name, message: message, stack: stack, severity: severity };
4685
- // Maintain history of errors in memory to avoid sending redundant information
4686
- if (code in history$2) {
4687
- history$2[code].push(key);
4625
+ if (screen) {
4626
+ max(14 /* Metric.ScreenWidth */, Math.round(screen.width));
4627
+ max(15 /* Metric.ScreenHeight */, Math.round(screen.height));
4628
+ max(16 /* Metric.ColorDepth */, Math.round(screen.colorDepth));
4688
4629
  }
4689
- else {
4690
- history$2[code] = [key];
4630
+ // Read cookies specified in configuration
4631
+ for (var _i = 0, _d = config$2.cookies; _i < _d.length; _i++) {
4632
+ var key = _d[_i];
4633
+ var value = getCookie(key);
4634
+ if (value) {
4635
+ set(key, value);
4636
+ }
4691
4637
  }
4692
- encode$2(33 /* Event.Log */);
4693
- }
4694
- function stop$c() {
4695
- history$2 = {};
4696
- }
4697
-
4698
- var data$5 = {};
4699
- var keys = new Set();
4700
- var variables = {};
4701
- var selectors = {};
4702
- var hashes = {};
4703
- var validation = {};
4704
- function start$b() {
4705
- reset$4();
4638
+ // Track consent config
4639
+ config$1(config$2.track);
4640
+ // Track ids using a cookie if configuration allows it
4641
+ track$1(u);
4706
4642
  }
4707
- // Input string is of the following form:
4708
- // EXTRACT 101|element { "1": ".class1", "2": "~window.a.b", "3": "!abc"}
4709
- // if element is present on the page it will set up event 101 to grab the contents of the class1 selector into component 1,
4710
- // the javascript evaluated contents of window.a.b into component 2,
4711
- // and the contents of Clarity's hash abc into component 3
4712
- function trigger$1(input) {
4713
- try {
4714
- var parts = input && input.length > 0 ? input.split(/ (.*)/) : ["" /* Constant.Empty */];
4715
- var keyparts = parts[0].split(/\|(.*)/);
4716
- var key = Number.parseInt(keyparts[0]);
4717
- var element = keyparts.length > 1 ? keyparts[1] : "" /* Constant.Empty */;
4718
- var values = parts.length > 1 ? JSON.parse(parts[1]) : {};
4719
- variables[key] = {};
4720
- selectors[key] = {};
4721
- hashes[key] = {};
4722
- validation[key] = element;
4723
- for (var v in values) {
4724
- // values is a set of strings for proper JSON parsing, but it's more efficient
4725
- // to interact with them as numbers
4726
- var id = Number.parseInt(v);
4727
- var value = values[v];
4728
- var source = 2 /* ExtractSource.Text */;
4729
- if (value.startsWith("~" /* Constant.Tilde */)) {
4730
- source = 0 /* ExtractSource.Javascript */;
4731
- }
4732
- else if (value.startsWith("!" /* Constant.Bang */)) {
4733
- source = 4 /* ExtractSource.Hash */;
4734
- }
4735
- switch (source) {
4736
- case 0 /* ExtractSource.Javascript */: {
4737
- var variable = value.slice(1);
4738
- variables[key][id] = parse(variable);
4739
- break;
4740
- }
4741
- case 2 /* ExtractSource.Text */:
4742
- selectors[key][id] = value;
4743
- break;
4744
- case 4 /* ExtractSource.Hash */: {
4745
- var hash_1 = value.slice(1);
4746
- hashes[key][id] = hash_1;
4747
- break;
4643
+ function userAgentData() {
4644
+ // biome-ignore lint/suspicious/noExplicitAny: not all browsers support navigator.userAgentData
4645
+ var uaData = navigator.userAgentData;
4646
+ if (uaData === null || uaData === void 0 ? void 0 : uaData.getHighEntropyValues) {
4647
+ uaData.getHighEntropyValues(["model", "platform", "platformVersion", "uaFullVersion"]).then(function (ua) {
4648
+ log$1(22 /* Dimension.Platform */, ua.platform);
4649
+ log$1(23 /* Dimension.PlatformVersion */, ua.platformVersion);
4650
+ if (ua.brands) {
4651
+ for (var _i = 0, _a = ua.brands; _i < _a.length; _i++) {
4652
+ var brand = _a[_i];
4653
+ log$1(24 /* Dimension.Brand */, brand.name + "~" /* Constant.Tilde */ + brand.version);
4748
4654
  }
4749
4655
  }
4750
- }
4656
+ log$1(25 /* Dimension.Model */, ua.model);
4657
+ max(27 /* Metric.Mobile */, ua.mobile ? 1 /* BooleanFlag.True */ : 0 /* BooleanFlag.False */);
4658
+ });
4751
4659
  }
4752
- catch (e) {
4753
- log$1(8 /* Code.Config */, 1 /* Severity.Warning */, e ? e.name : null);
4660
+ else {
4661
+ log$1(22 /* Dimension.Platform */, navigator.platform);
4754
4662
  }
4755
4663
  }
4756
- function clone(v) {
4757
- return JSON.parse(JSON.stringify(v));
4664
+ function stop$b() {
4665
+ rootDomain = null;
4666
+ data$4 = null;
4667
+ for (var _i = 0, callbacks_1 = callbacks; _i < callbacks_1.length; _i++) {
4668
+ var cb = callbacks_1[_i];
4669
+ cb.called = false;
4670
+ }
4758
4671
  }
4759
- function compute$4() {
4760
- try {
4761
- for (var v in variables) {
4762
- var key = Number.parseInt(v);
4763
- if (validation[key] === "" /* Constant.Empty */ || document.querySelector(validation[key])) {
4764
- var variableData = variables[key];
4765
- for (var v_1 in variableData) {
4766
- var variableKey = Number.parseInt(v_1);
4767
- var value = str(evaluate(clone(variableData[variableKey])));
4768
- if (value) {
4769
- update(key, variableKey, value);
4770
- }
4771
- }
4772
- var selectorData = selectors[key];
4773
- for (var s in selectorData) {
4774
- var shouldMask = false;
4775
- var selectorKey = Number.parseInt(s);
4776
- var selector = selectorData[selectorKey];
4777
- if (selector.startsWith("@" /* Constant.At */)) {
4778
- shouldMask = true;
4779
- selector = selector.slice(1);
4780
- }
4781
- var nodes = document.querySelectorAll(selector);
4782
- if (nodes) {
4783
- var text = Array.from(nodes)
4784
- .map(function (e) { return e.textContent; })
4785
- .join("<SEP>" /* Constant.Seperator */);
4786
- update(key, selectorKey, (shouldMask ? hash(text).trim() : text).slice(0, 10000 /* Setting.ExtractLimit */));
4787
- }
4788
- }
4789
- var hashData = hashes[key];
4790
- for (var h in hashData) {
4791
- var hashKey = Number.parseInt(h);
4792
- var content = hashText(hashData[hashKey]).trim().slice(0, 10000 /* Setting.ExtractLimit */);
4793
- update(key, hashKey, content);
4794
- }
4795
- }
4796
- }
4797
- if (keys.size > 0) {
4798
- encode$1(40 /* Event.Extract */);
4799
- }
4672
+ function metadata(cb, wait, recall) {
4673
+ if (wait === void 0) { wait = true; }
4674
+ if (recall === void 0) { recall = false; }
4675
+ var upgraded = config$2.lean ? 0 /* BooleanFlag.False */ : 1 /* BooleanFlag.True */;
4676
+ var called = false;
4677
+ // if caller hasn't specified that they want to skip waiting for upgrade but we've already upgraded, we need to
4678
+ // directly execute the callback in addition to adding to our list as we only process callbacks at the moment
4679
+ // we go through the upgrading flow.
4680
+ if (data$4 && (upgraded || wait === false)) {
4681
+ // Immediately invoke the callback if the caller explicitly doesn't want to wait for the upgrade confirmation
4682
+ cb(data$4, !config$2.lean);
4683
+ called = true;
4800
4684
  }
4801
- catch (e) {
4802
- log$1(5 /* Code.Selector */, 1 /* Severity.Warning */, e ? e.name : null);
4685
+ if (recall || !called) {
4686
+ callbacks.push({ callback: cb, wait: wait, recall: recall, called: called });
4803
4687
  }
4804
4688
  }
4805
- function reset$4() {
4806
- keys.clear();
4689
+ function id() {
4690
+ return data$4 ? [data$4.userId, data$4.sessionId, data$4.pageNum].join("." /* Constant.Dot */) : "" /* Constant.Empty */;
4807
4691
  }
4808
- function update(key, subkey, value) {
4809
- var update = false;
4810
- if (!(key in data$5)) {
4811
- data$5[key] = {};
4812
- update = true;
4813
- }
4814
- if (!isEmpty(hashes[key]) && (!(subkey in data$5[key]) || data$5[key][subkey] !== value)) {
4815
- update = true;
4692
+ function consent(status) {
4693
+ if (status === void 0) { status = true; }
4694
+ if (!status) {
4695
+ config$2.track = false;
4696
+ setCookie("_clsk" /* Constant.SessionKey */, "" /* Constant.Empty */, -Number.MAX_VALUE);
4697
+ setCookie("_clck" /* Constant.CookieKey */, "" /* Constant.Empty */, -Number.MAX_VALUE);
4698
+ stop();
4699
+ window.setTimeout(start, 250 /* Setting.RestartDelay */);
4700
+ return;
4816
4701
  }
4817
- data$5[key][subkey] = value;
4818
- if (update) {
4819
- keys.add(key);
4702
+ if (active()) {
4703
+ config$2.track = true;
4704
+ track$1(user(), 1 /* BooleanFlag.True */);
4705
+ save();
4706
+ consent$1();
4820
4707
  }
4821
- return;
4822
4708
  }
4823
- function stop$b() {
4824
- reset$4();
4709
+ function clear() {
4710
+ // Clear any stored information in the cookie that tracks session information so we can restart fresh the next time
4711
+ setCookie("_clsk" /* Constant.SessionKey */, "" /* Constant.Empty */, 0);
4825
4712
  }
4826
- function parse(variable) {
4827
- var syntax = [];
4828
- var parts = variable.split("." /* Constant.Dot */);
4829
- while (parts.length > 0) {
4830
- var part = parts.shift();
4831
- var arrayStart = part.indexOf("[" /* Constant.ArrayStart */);
4832
- var conditionStart = part.indexOf("{" /* Constant.ConditionStart */);
4833
- var conditionEnd = part.indexOf("}" /* Constant.ConditionEnd */);
4834
- syntax.push({
4835
- name: arrayStart > 0 ? part.slice(0, arrayStart) : conditionStart > 0 ? part.slice(0, conditionStart) : part,
4836
- type: arrayStart > 0 ? 1 /* Type.Array */ : conditionStart > 0 ? 2 /* Type.Object */ : 3 /* Type.Simple */,
4837
- condition: conditionStart > 0 ? part.slice(conditionStart + 1, conditionEnd) : null,
4838
- });
4713
+ function tab() {
4714
+ var id = shortid();
4715
+ if (config$2.track && supported$1(window, "sessionStorage" /* Constant.SessionStorage */)) {
4716
+ var value = sessionStorage.getItem("_cltk" /* Constant.TabKey */);
4717
+ id = value ? value : id;
4718
+ sessionStorage.setItem("_cltk" /* Constant.TabKey */, id);
4839
4719
  }
4840
- return syntax;
4720
+ return id;
4841
4721
  }
4842
- // The function below takes in a variable name in following format: "a.b.c" and safely evaluates its value in javascript context
4843
- // For instance, for a.b.c, it will first check window["a"]. If it exists, it will recursively look at: window["a"]["b"] and finally,
4844
- // return the value for window["a"]["b"]["c"].
4845
- // biome-ignore lint/complexity/noBannedTypes: type of base is intentionally generic
4846
- // biome-ignore lint/suspicious/noExplicitAny: type of return value isn't known
4847
- function evaluate(variable, base) {
4848
- if (base === void 0) { base = window; }
4849
- if (variable.length === 0) {
4850
- return base;
4851
- }
4852
- var part = variable.shift();
4853
- // biome-ignore lint/suspicious/noImplicitAnyLet: type of return value isn't known
4854
- var output;
4855
- if (base === null || base === void 0 ? void 0 : base[part.name]) {
4856
- var obj = base[part.name];
4857
- if (part.type !== 1 /* Type.Array */ && match(obj, part.condition)) {
4858
- output = evaluate(variable, obj);
4859
- }
4860
- else if (Array.isArray(obj)) {
4861
- var filtered = [];
4862
- for (var _i = 0, obj_1 = obj; _i < obj_1.length; _i++) {
4863
- var value = obj_1[_i];
4864
- if (match(value, part.condition)) {
4865
- var op = evaluate(variable, value);
4866
- if (op) {
4867
- filtered.push(op);
4868
- }
4722
+ function callback() {
4723
+ var upgrade = config$2.lean ? 0 /* BooleanFlag.False */ : 1 /* BooleanFlag.True */;
4724
+ processCallback(upgrade);
4725
+ }
4726
+ function save() {
4727
+ if (!data$4 || !config$2.track)
4728
+ return;
4729
+ var ts = Math.round(Date.now());
4730
+ var upload = config$2.upload && typeof config$2.upload === "string"
4731
+ ? config$2.upload.replace("https://" /* Constant.HTTPS */, "" /* Constant.Empty */)
4732
+ : "" /* Constant.Empty */;
4733
+ var upgrade = config$2.lean ? 0 /* BooleanFlag.False */ : 1 /* BooleanFlag.True */;
4734
+ setCookie("_clsk" /* Constant.SessionKey */, [data$4.sessionId, ts, data$4.pageNum, upgrade, upload].join("|" /* Constant.Pipe */), 1 /* Setting.SessionExpire */);
4735
+ }
4736
+ function processCallback(upgrade) {
4737
+ if (callbacks.length > 0) {
4738
+ for (var i = 0; i < callbacks.length; i++) {
4739
+ var cb = callbacks[i];
4740
+ if (cb.callback && !cb.called && (!cb.wait || upgrade)) {
4741
+ cb.callback(data$4, !config$2.lean);
4742
+ cb.called = true;
4743
+ if (!cb.recall) {
4744
+ callbacks.splice(i, 1);
4745
+ i--;
4869
4746
  }
4870
4747
  }
4871
- output = filtered;
4872
4748
  }
4873
- return output;
4874
4749
  }
4875
- return null;
4876
4750
  }
4877
- function str(input) {
4878
- // Automatically trim string to max of Setting.ExtractLimit to avoid fetching long strings
4879
- return input ? JSON.stringify(input).slice(0, 10000 /* Setting.ExtractLimit */) : input;
4751
+ function supported$1(target, api) {
4752
+ try {
4753
+ return !!target[api];
4754
+ }
4755
+ catch (_a) {
4756
+ return false;
4757
+ }
4880
4758
  }
4881
- // biome-ignore lint/complexity/noBannedTypes: type of base is intentionally generic
4882
- function match(base, condition) {
4883
- if (condition) {
4884
- var prop = condition.split(":");
4885
- return prop.length > 1 ? base[prop[0]] === prop[1] : base[prop[0]];
4759
+ function track$1(u, consentInput) {
4760
+ if (consentInput === void 0) { consentInput = null; }
4761
+ // If consent is not explicitly specified, infer it from the user object
4762
+ var consent = consentInput === null ? u.consent : consentInput;
4763
+ // Convert time precision into days to reduce number of bytes we have to write in a cookie
4764
+ // E.g. Math.ceil(1628735962643 / (24*60*60*1000)) => 18852 (days) => ejo in base36 (13 bytes => 3 bytes)
4765
+ var end = Math.ceil((Date.now() + 365 /* Setting.Expire */ * 86400000 /* Time.Day */) / 86400000 /* Time.Day */);
4766
+ // If DOB is not set in the user object, use the date set in the config as a DOB
4767
+ var dob = u.dob === 0 ? (config$2.dob === null ? 0 : config$2.dob) : u.dob;
4768
+ // To avoid cookie churn, write user id cookie only once every day
4769
+ if (u.expiry === null || Math.abs(end - u.expiry) >= 1 /* Setting.CookieInterval */ || u.consent !== consent || u.dob !== dob) {
4770
+ var cookieParts = [data$4.userId, 2 /* Setting.CookieVersion */, end.toString(36), consent, dob];
4771
+ setCookie("_clck" /* Constant.CookieKey */, cookieParts.join("|" /* Constant.Pipe */), 365 /* Setting.Expire */);
4886
4772
  }
4887
- return true;
4888
4773
  }
4889
- // biome-ignore lint/complexity/noBannedTypes: type of obj is intentionally generic
4890
- function isEmpty(obj) {
4891
- return Object.keys(obj).length === 0;
4774
+ function shortid() {
4775
+ var _a;
4776
+ var id = Math.floor(Math.random() * Math.pow(2, 32));
4777
+ if (((_a = window === null || window === void 0 ? void 0 : window.crypto) === null || _a === void 0 ? void 0 : _a.getRandomValues) && Uint32Array) {
4778
+ id = window.crypto.getRandomValues(new Uint32Array(1))[0];
4779
+ }
4780
+ return id.toString(36);
4892
4781
  }
4893
-
4894
- function encode$1 (event) {
4895
- var t = time();
4896
- var tokens = [t, event];
4897
- switch (event) {
4898
- case 4 /* Event.Baseline */: {
4899
- var b = state$b;
4900
- if (b) {
4901
- tokens = [b.time, b.event];
4902
- tokens.push(b.data.visible);
4903
- tokens.push(b.data.docWidth);
4904
- tokens.push(b.data.docHeight);
4905
- tokens.push(b.data.screenWidth);
4906
- tokens.push(b.data.screenHeight);
4907
- tokens.push(b.data.scrollX);
4908
- tokens.push(b.data.scrollY);
4909
- tokens.push(b.data.pointerX);
4910
- tokens.push(b.data.pointerY);
4911
- tokens.push(b.data.activityTime);
4912
- tokens.push(b.data.scrollTime);
4913
- tokens.push(b.data.pointerTime);
4914
- tokens.push(b.data.moveX);
4915
- tokens.push(b.data.moveY);
4916
- tokens.push(b.data.moveTime);
4917
- tokens.push(b.data.downX);
4918
- tokens.push(b.data.downY);
4919
- tokens.push(b.data.downTime);
4920
- tokens.push(b.data.upX);
4921
- tokens.push(b.data.upY);
4922
- tokens.push(b.data.upTime);
4923
- tokens.push(b.data.pointerPrevX);
4924
- tokens.push(b.data.pointerPrevY);
4925
- tokens.push(b.data.pointerPrevTime);
4926
- queue(tokens, false);
4927
- }
4928
- reset$s();
4929
- break;
4782
+ function session() {
4783
+ var output = { session: shortid(), ts: Math.round(Date.now()), count: 1, upgrade: null, upload: "" /* Constant.Empty */ };
4784
+ var value = getCookie("_clsk" /* Constant.SessionKey */, !config$2.includeSubdomains);
4785
+ if (value) {
4786
+ // Maintaining support for pipe separator for backward compatibility, this can be removed in future releases
4787
+ var parts = value.includes("^" /* Constant.Caret */) ? value.split("^" /* Constant.Caret */) : value.split("|" /* Constant.Pipe */);
4788
+ // Making it backward & forward compatible by using greater than comparison (v0.6.21)
4789
+ // In future version, we can reduce the parts length to be 5 where the last part contains the full upload URL
4790
+ if (parts.length >= 5 && output.ts - num(parts[1]) < 1800000 /* Setting.SessionTimeout */) {
4791
+ output.session = parts[0];
4792
+ output.count = num(parts[2]) + 1;
4793
+ output.upgrade = num(parts[3]);
4794
+ output.upload = parts.length >= 6 ? "".concat("https://" /* Constant.HTTPS */).concat(parts[5], "/").concat(parts[4]) : "".concat("https://" /* Constant.HTTPS */).concat(parts[4]);
4930
4795
  }
4931
- case 25 /* Event.Ping */:
4932
- tokens.push(data$h.gap);
4933
- queue(tokens);
4934
- break;
4935
- case 35 /* Event.Limit */:
4936
- tokens.push(data$4.check);
4937
- queue(tokens, false);
4938
- break;
4939
- case 3 /* Event.Upgrade */:
4940
- tokens.push(data$9.key);
4941
- queue(tokens);
4942
- break;
4943
- case 2 /* Event.Upload */:
4944
- tokens.push(track$1.sequence);
4945
- tokens.push(track$1.attempts);
4946
- tokens.push(track$1.status);
4947
- queue(tokens, false);
4948
- break;
4949
- case 24 /* Event.Custom */:
4950
- // not all custom events have a key - if it wasn't passed server handles just value
4951
- data$j.key && tokens.push(data$j.key);
4952
- tokens.push(data$j.value);
4953
- queue(tokens);
4954
- break;
4955
- case 34 /* Event.Variable */: {
4956
- var variableKeys = Object.keys(data$8);
4957
- if (variableKeys.length > 0) {
4958
- for (var _i = 0, variableKeys_1 = variableKeys; _i < variableKeys_1.length; _i++) {
4959
- var v = variableKeys_1[_i];
4960
- tokens.push(v);
4961
- tokens.push(data$8[v]);
4962
- }
4963
- reset$5();
4964
- queue(tokens, false);
4965
- }
4966
- break;
4796
+ }
4797
+ return output;
4798
+ }
4799
+ function num(string, base) {
4800
+ if (base === void 0) { base = 10; }
4801
+ return Number.parseInt(string, base);
4802
+ }
4803
+ function user() {
4804
+ var output = { id: shortid(), version: 0, expiry: null, consent: 0 /* BooleanFlag.False */, dob: 0 };
4805
+ var cookie = getCookie("_clck" /* Constant.CookieKey */, !config$2.includeSubdomains);
4806
+ if (cookie && cookie.length > 0) {
4807
+ // Splitting and looking up first part for forward compatibility, in case we wish to store additional information in a cookie
4808
+ // Maintaining support for pipe separator for backward compatibility, this can be removed in future releases
4809
+ var parts = cookie.includes("^" /* Constant.Caret */) ? cookie.split("^" /* Constant.Caret */) : cookie.split("|" /* Constant.Pipe */);
4810
+ // Read version information and timestamp from cookie, if available
4811
+ if (parts.length > 1) {
4812
+ output.version = num(parts[1]);
4967
4813
  }
4968
- case 0 /* Event.Metric */: {
4969
- var metricKeys = Object.keys(updates$3);
4970
- if (metricKeys.length > 0) {
4971
- for (var _a = 0, metricKeys_1 = metricKeys; _a < metricKeys_1.length; _a++) {
4972
- var m = metricKeys_1[_a];
4973
- var key = Number.parseInt(m, 10);
4974
- tokens.push(key);
4975
- // For computation, we need microseconds precision that performance.now() API offers
4976
- // However, for data over the wire, we round it off to milliseconds precision.
4977
- tokens.push(Math.round(updates$3[m]));
4978
- }
4979
- reset$r();
4980
- queue(tokens, false);
4981
- }
4982
- break;
4814
+ if (parts.length > 2) {
4815
+ output.expiry = num(parts[2], 36);
4983
4816
  }
4984
- case 1 /* Event.Dimension */: {
4985
- var dimensionKeys = Object.keys(updates);
4986
- if (dimensionKeys.length > 0) {
4987
- for (var _b = 0, dimensionKeys_1 = dimensionKeys; _b < dimensionKeys_1.length; _b++) {
4988
- var d = dimensionKeys_1[_b];
4989
- var key = Number.parseInt(d, 10);
4990
- tokens.push(key);
4991
- tokens.push(updates[d]);
4992
- }
4993
- reset$3();
4994
- queue(tokens, false);
4995
- }
4996
- break;
4817
+ // Check if we have explicit consent to track this user
4818
+ if (parts.length > 3 && num(parts[3]) === 1) {
4819
+ output.consent = 1 /* BooleanFlag.True */;
4997
4820
  }
4998
- case 36 /* Event.Summary */: {
4999
- var eventKeys = Object.keys(data$g);
5000
- if (eventKeys.length > 0) {
5001
- for (var _c = 0, eventKeys_1 = eventKeys; _c < eventKeys_1.length; _c++) {
5002
- var e = eventKeys_1[_c];
5003
- var key = Number.parseInt(e, 10);
5004
- tokens.push(key);
5005
- tokens.push([].concat.apply([], data$g[e]));
5006
- }
5007
- reset$p();
5008
- queue(tokens, false);
5009
- }
5010
- break;
4821
+ if (parts.length > 4 && num(parts[1]) > 1) {
4822
+ output.dob = num(parts[4]);
5011
4823
  }
5012
- case 40 /* Event.Extract */: {
5013
- var extractKeys = keys;
5014
- for (var _d = 0, _e = Array.from(extractKeys); _d < _e.length; _d++) {
5015
- var e = _e[_d];
5016
- tokens.push(e);
5017
- var token = [];
5018
- for (var d in data$5[e]) {
5019
- var key = Number.parseInt(d, 10);
5020
- token.push(key);
5021
- token.push(data$5[e][d]);
4824
+ // Set track configuration to true for this user if we have explicit consent, regardless of project setting
4825
+ config$2.track = config$2.track || output.consent === 1 /* BooleanFlag.True */;
4826
+ // Get user id from cookie only if we tracking is enabled, otherwise fallback to a random id
4827
+ output.id = config$2.track ? parts[0] : output.id;
4828
+ }
4829
+ return output;
4830
+ }
4831
+ function getCookie(key, limit) {
4832
+ var _a;
4833
+ if (limit === void 0) { limit = false; }
4834
+ if (supported$1(document, "cookie" /* Constant.Cookie */)) {
4835
+ var cookies = document.cookie.split(";" /* Constant.Semicolon */);
4836
+ if (cookies) {
4837
+ for (var i = 0; i < cookies.length; i++) {
4838
+ var pair = cookies[i].split("=" /* Constant.Equals */);
4839
+ if (pair.length > 1 && pair[0] && pair[0].trim() === key) {
4840
+ // Some browsers automatically url encode cookie values if they are not url encoded.
4841
+ // We therefore encode and decode cookie values ourselves.
4842
+ // For backwards compatability we need to consider 3 cases:
4843
+ // * Cookie was previously not encoded by Clarity and browser did not encode it
4844
+ // * Cookie was previously not encoded by Clarity and browser encoded it once or more
4845
+ // * Cookie was previously encoded by Clarity and browser did not encode it
4846
+ var _b = decodeCookieValue(pair[1]), isEncoded = _b[0], decodedValue = _b[1];
4847
+ while (isEncoded) {
4848
+ _a = decodeCookieValue(decodedValue), isEncoded = _a[0], decodedValue = _a[1];
4849
+ }
4850
+ // If we are limiting cookies, check if the cookie value is limited
4851
+ if (limit) {
4852
+ return decodedValue.endsWith("".concat("~" /* Constant.Tilde */, "1")) ? decodedValue.substring(0, decodedValue.length - 2) : null;
4853
+ }
4854
+ return decodedValue;
5022
4855
  }
5023
- tokens.push(token);
5024
4856
  }
5025
- reset$4();
5026
- queue(tokens, false);
5027
4857
  }
5028
4858
  }
4859
+ return null;
5029
4860
  }
5030
-
5031
- var data$4;
5032
- function start$a() {
5033
- data$4 = { check: 0 /* Check.None */ };
5034
- }
5035
- function check$2(bytes) {
5036
- if (data$4.check === 0 /* Check.None */) {
5037
- var reason = data$4.check;
5038
- reason = data$1.sequence >= 128 /* Setting.PayloadLimit */ ? 1 /* Check.Payload */ : reason;
5039
- reason = data$1.pageNum >= 128 /* Setting.PageLimit */ ? 7 /* Check.Page */ : reason;
5040
- reason = time() > 7200000 /* Setting.ShutdownLimit */ ? 2 /* Check.Shutdown */ : reason;
5041
- reason = bytes > 10485760 /* Setting.PlaybackBytesLimit */ ? 2 /* Check.Shutdown */ : reason;
5042
- if (reason !== data$4.check) {
5043
- trigger(reason);
5044
- }
4861
+ function decodeCookieValue(value) {
4862
+ try {
4863
+ var decodedValue = decodeURIComponent(value);
4864
+ return [decodedValue !== value, decodedValue];
5045
4865
  }
4866
+ catch (_a) { }
4867
+ return [false, value];
5046
4868
  }
5047
- function trigger(reason) {
5048
- data$4.check = reason;
5049
- // limit the dimensions we collect, but we don't need to stop Clarity entirely if we hit the limit
5050
- if (reason !== 5 /* Check.Collection */) {
5051
- clear();
5052
- stop();
5053
- }
4869
+ function encodeCookieValue(value) {
4870
+ return encodeURIComponent(value);
5054
4871
  }
5055
- function compute$3() {
5056
- if (data$4.check !== 0 /* Check.None */) {
5057
- encode$1(35 /* Event.Limit */);
4872
+ function setCookie(key, value, time) {
4873
+ // only write cookies if we are currently in a cookie writing mode (and they are supported)
4874
+ // OR if we are trying to write an empty cookie (i.e. clear the cookie value out)
4875
+ if ((config$2.track || value === "" /* Constant.Empty */) && ((navigator === null || navigator === void 0 ? void 0 : navigator.cookieEnabled) || supported$1(document, "cookie" /* Constant.Cookie */))) {
4876
+ // Some browsers automatically url encode cookie values if they are not url encoded.
4877
+ // We therefore encode and decode cookie values ourselves.
4878
+ var encodedValue = encodeCookieValue(value);
4879
+ var expiry = new Date();
4880
+ expiry.setDate(expiry.getDate() + time);
4881
+ var expires = expiry ? "expires=" /* Constant.Expires */ + expiry.toUTCString() : "" /* Constant.Empty */;
4882
+ var cookie = "".concat(key, "=").concat(encodedValue).concat(";" /* Constant.Semicolon */).concat(expires).concat(";path=/" /* Constant.Path */);
4883
+ try {
4884
+ // Attempt to get the root domain only once and fall back to writing cookie on the current domain.
4885
+ if (rootDomain === null) {
4886
+ var hostname = location.hostname ? location.hostname.split("." /* Constant.Dot */) : [];
4887
+ // Walk backwards on a domain and attempt to set a cookie, until successful
4888
+ for (var i = hostname.length - 1; i >= 0; i--) {
4889
+ rootDomain = ".".concat(hostname[i]).concat(rootDomain ? rootDomain : "" /* Constant.Empty */);
4890
+ // We do not wish to attempt writing a cookie on the absolute last part of the domain, e.g. .com or .net.
4891
+ // So we start attempting after second-last part, e.g. .domain.com (PASS) or .co.uk (FAIL)
4892
+ if (i < hostname.length - 1) {
4893
+ // Write the cookie on the current computed top level domain
4894
+ document.cookie = "".concat(cookie).concat(";" /* Constant.Semicolon */).concat("domain=" /* Constant.Domain */).concat(rootDomain);
4895
+ // Once written, check if the cookie exists and its value matches exactly with what we intended to set
4896
+ // Checking for exact value match helps us eliminate a corner case where the cookie may already be present with a different value
4897
+ // If the check is successful, no more action is required and we can return from the function since rootDomain cookie is already set
4898
+ // If the check fails, continue with the for loop until we can successfully set and verify the cookie
4899
+ if (getCookie(key) === value) {
4900
+ return;
4901
+ }
4902
+ }
4903
+ }
4904
+ // Finally, if we were not successful and gone through all the options, play it safe and reset rootDomain to be empty
4905
+ // This forces our code to fall back to always writing cookie to the current domain
4906
+ rootDomain = "" /* Constant.Empty */;
4907
+ }
4908
+ }
4909
+ catch (_a) {
4910
+ rootDomain = "" /* Constant.Empty */;
4911
+ }
4912
+ document.cookie = rootDomain ? "".concat(cookie).concat(";" /* Constant.Semicolon */).concat("domain=" /* Constant.Domain */).concat(rootDomain) : cookie;
5058
4913
  }
5059
4914
  }
5060
- function stop$a() {
5061
- data$4 = null;
5062
- }
4915
+
4916
+ var metadata$1 = /*#__PURE__*/Object.freeze({
4917
+ __proto__: null,
4918
+ callback: callback,
4919
+ callbacks: callbacks,
4920
+ clear: clear,
4921
+ consent: consent,
4922
+ get data () { return data$4; },
4923
+ get electron () { return electron; },
4924
+ id: id,
4925
+ metadata: metadata,
4926
+ save: save,
4927
+ shortid: shortid,
4928
+ start: start$c,
4929
+ stop: stop$b
4930
+ });
5063
4931
 
5064
4932
  var data$3 = null;
5065
- var updates = null;
5066
- var limited = false;
5067
- function start$9() {
5068
- data$3 = {};
5069
- updates = {};
5070
- limited = false;
5071
- }
5072
- function stop$9() {
5073
- data$3 = {};
5074
- updates = {};
5075
- limited = false;
4933
+ function start$b() {
4934
+ var m = data$4;
4935
+ data$3 = {
4936
+ version: version$1,
4937
+ sequence: 0,
4938
+ start: 0,
4939
+ duration: 0,
4940
+ projectId: m.projectId,
4941
+ userId: m.userId,
4942
+ sessionId: m.sessionId,
4943
+ pageNum: m.pageNum,
4944
+ upload: 0 /* Upload.Async */,
4945
+ end: 0 /* BooleanFlag.False */,
4946
+ applicationPlatform: 0 /* ApplicationPlatform.WebApp */,
4947
+ url: "",
4948
+ };
5076
4949
  }
5077
- function log(dimension, inputValue) {
5078
- // Check valid value before moving ahead
5079
- if (inputValue) {
5080
- // Ensure received value is casted into a string if it wasn't a string to begin with
5081
- var value = "".concat(inputValue);
5082
- if (!(dimension in data$3)) {
5083
- data$3[dimension] = [];
5084
- }
5085
- if (data$3[dimension].indexOf(value) < 0) {
5086
- // Limit check to ensure we have a cap on number of dimensions we can collect
5087
- if (data$3[dimension].length > 128 /* Setting.CollectionLimit */) {
5088
- if (!limited) {
5089
- limited = true;
5090
- trigger(5 /* Check.Collection */);
5091
- }
5092
- return;
4950
+ function stop$a() {
4951
+ data$3 = null;
4952
+ }
4953
+ function envelope(last) {
4954
+ data$3.start = data$3.start + data$3.duration;
4955
+ data$3.duration = time() - data$3.start;
4956
+ data$3.sequence++;
4957
+ data$3.upload = last && "sendBeacon" in navigator ? 1 /* Upload.Beacon */ : 0 /* Upload.Async */;
4958
+ data$3.end = last ? 1 /* BooleanFlag.True */ : 0 /* BooleanFlag.False */;
4959
+ data$3.applicationPlatform = 0 /* ApplicationPlatform.WebApp */;
4960
+ data$3.url = url$1(location.href, false, true);
4961
+ return [
4962
+ data$3.version,
4963
+ data$3.sequence,
4964
+ data$3.start,
4965
+ data$3.duration,
4966
+ data$3.projectId,
4967
+ data$3.userId,
4968
+ data$3.sessionId,
4969
+ data$3.pageNum,
4970
+ data$3.upload,
4971
+ data$3.end,
4972
+ data$3.applicationPlatform,
4973
+ data$3.url,
4974
+ ];
4975
+ }
4976
+
4977
+ var envelope$1 = /*#__PURE__*/Object.freeze({
4978
+ __proto__: null,
4979
+ get data () { return data$3; },
4980
+ envelope: envelope,
4981
+ start: start$b,
4982
+ stop: stop$a
4983
+ });
4984
+
4985
+ var history$3;
4986
+ function reset$2() {
4987
+ history$3 = [];
4988
+ }
4989
+ function report(e) {
4990
+ // Do not report the same message twice for the same page
4991
+ if (history$3 && history$3.indexOf(e.message) === -1) {
4992
+ var url = config$2.report;
4993
+ if (url && url.length > 0) {
4994
+ var payload = { v: data$3.version, p: data$3.projectId, u: data$3.userId, s: data$3.sessionId, n: data$3.pageNum };
4995
+ if (e.message) {
4996
+ payload.m = e.message;
5093
4997
  }
5094
- data$3[dimension].push(value);
5095
- // If this is a new value, track it as part of updates object
5096
- // This allows us to only send back new values in subsequent payloads
5097
- if (!(dimension in updates)) {
5098
- updates[dimension] = [];
4998
+ if (e.stack) {
4999
+ payload.e = e.stack;
5099
5000
  }
5100
- updates[dimension].push(value);
5001
+ // Using POST request instead of a GET request (img-src) to not violate existing CSP rules
5002
+ // Since, Clarity already uses XHR to upload data, we stick with similar POST mechanism for reporting too
5003
+ var xhr = new XMLHttpRequest();
5004
+ xhr.open("POST", url, true);
5005
+ xhr.send(JSON.stringify(payload));
5006
+ history$3.push(e.message);
5101
5007
  }
5102
5008
  }
5103
- }
5104
- function compute$2() {
5105
- encode$1(1 /* Event.Dimension */);
5106
- }
5107
- function reset$3() {
5108
- updates = {};
5109
- limited = false;
5009
+ return e;
5110
5010
  }
5111
5011
 
5112
- function config$1(track) {
5113
- trackConsent(track ? 1 /* ConsentType.Implicit */ : 0 /* ConsentType.None */);
5012
+ // biome-ignore lint/complexity/noBannedTypes: specifically looking to instrument function calls
5013
+ function measure (method) {
5014
+ return function () {
5015
+ var args = [];
5016
+ for (var _i = 0; _i < arguments.length; _i++) {
5017
+ args[_i] = arguments[_i];
5018
+ }
5019
+ var start = performance.now();
5020
+ try {
5021
+ method.apply(this, args);
5022
+ }
5023
+ catch (ex) {
5024
+ throw report(ex);
5025
+ }
5026
+ var duration = performance.now() - start;
5027
+ sum(4 /* Metric.TotalCost */, duration);
5028
+ if (duration > 30 /* Setting.LongTask */) {
5029
+ count$1(7 /* Metric.LongTaskCount */);
5030
+ max(6 /* Metric.ThreadBlockedTime */, duration);
5031
+ log(9 /* Code.FunctionExecutionTime */, 0 /* Severity.Info */, "".concat(method.dn || method.name, "-").concat(duration));
5032
+ }
5033
+ };
5114
5034
  }
5115
- // When we get consent signal as false, we restart the service and track config as false.
5116
- function consent$1() {
5117
- trackConsent(2 /* ConsentType.General */);
5035
+
5036
+ var supported = "CompressionStream" /* Constant.CompressionStream */ in window;
5037
+ function compress (input) {
5038
+ return __awaiter(this, void 0, void 0, function () {
5039
+ var stream, _a;
5040
+ return __generator(this, function (_c) {
5041
+ switch (_c.label) {
5042
+ case 0:
5043
+ _c.trys.push([0, 3, , 4]);
5044
+ if (!supported) return [3 /*break*/, 2];
5045
+ stream = new ReadableStream({ start: function (controller) {
5046
+ return __awaiter(this, void 0, void 0, function () {
5047
+ return __generator(this, function (_a) {
5048
+ controller.enqueue(input);
5049
+ controller.close();
5050
+ return [2 /*return*/];
5051
+ });
5052
+ });
5053
+ } }).pipeThrough(new TextEncoderStream()).pipeThrough(new window["CompressionStream" /* Constant.CompressionStream */]("gzip"));
5054
+ _a = Uint8Array.bind;
5055
+ return [4 /*yield*/, read(stream)];
5056
+ case 1: return [2 /*return*/, new (_a.apply(Uint8Array, [void 0, _c.sent()]))()];
5057
+ case 2: return [3 /*break*/, 4];
5058
+ case 3:
5059
+ _c.sent();
5060
+ return [3 /*break*/, 4];
5061
+ case 4: return [2 /*return*/, null];
5062
+ }
5063
+ });
5064
+ });
5118
5065
  }
5119
- function trackConsent(consent) {
5120
- log(36 /* Dimension.Consent */, consent.toString());
5066
+ function read(stream) {
5067
+ return __awaiter(this, void 0, void 0, function () {
5068
+ var reader, chunks, done, value;
5069
+ var _a;
5070
+ return __generator(this, function (_b) {
5071
+ switch (_b.label) {
5072
+ case 0:
5073
+ reader = stream.getReader();
5074
+ chunks = [];
5075
+ done = false;
5076
+ value = [];
5077
+ _b.label = 1;
5078
+ case 1:
5079
+ if (!!done) return [3 /*break*/, 3];
5080
+ return [4 /*yield*/, reader.read()];
5081
+ case 2:
5082
+ (_a = _b.sent(), done = _a.done, value = _a.value);
5083
+ if (done) {
5084
+ return [2 /*return*/, chunks];
5085
+ }
5086
+ chunks.push.apply(chunks, value);
5087
+ return [3 /*break*/, 1];
5088
+ case 3: return [2 /*return*/, chunks];
5089
+ }
5090
+ });
5091
+ });
5121
5092
  }
5122
5093
 
5123
- var data$2 = null;
5124
- var callbacks = [];
5125
- var electron = 0 /* BooleanFlag.False */;
5126
- var rootDomain = null;
5127
- function start$8() {
5128
- var _a, _b, _c;
5129
- rootDomain = null;
5130
- var ua = navigator && "userAgent" in navigator ? navigator.userAgent : "" /* Constant.Empty */;
5131
- var timezone = (_c = (_b = (_a = Intl === null || Intl === void 0 ? void 0 : Intl.DateTimeFormat()) === null || _a === void 0 ? void 0 : _a.resolvedOptions()) === null || _b === void 0 ? void 0 : _b.timeZone) !== null && _c !== void 0 ? _c : "";
5132
- var timezoneOffset = new Date().getTimezoneOffset().toString();
5133
- var ancestorOrigins = window.location.ancestorOrigins ? Array.from(window.location.ancestorOrigins).toString() : "";
5134
- var title = (document === null || document === void 0 ? void 0 : document.title) ? document.title : "" /* Constant.Empty */;
5135
- electron = ua.indexOf("Electron" /* Constant.Electron */) > 0 ? 1 /* BooleanFlag.True */ : 0 /* BooleanFlag.False */;
5136
- // Populate ids for this page
5137
- var s = session();
5138
- var u = user();
5139
- var projectId = config$2.projectId || hash(location.host);
5140
- data$2 = { projectId: projectId, userId: u.id, sessionId: s.session, pageNum: s.count };
5141
- // Override configuration based on what's in the session storage, unless it is blank (e.g. using upload callback, like in devtools)
5142
- config$2.lean = config$2.track && s.upgrade !== null ? s.upgrade === 0 /* BooleanFlag.False */ : config$2.lean;
5143
- config$2.upload =
5144
- config$2.track && typeof config$2.upload === "string" && s.upload && s.upload.length > "https://" /* Constant.HTTPS */.length ? s.upload : config$2.upload;
5145
- // Log page metadata as dimensions
5146
- log(0 /* Dimension.UserAgent */, ua);
5147
- log(3 /* Dimension.PageTitle */, title);
5148
- log(1 /* Dimension.Url */, url$1(location.href, !!electron));
5149
- log(2 /* Dimension.Referrer */, document.referrer);
5150
- log(15 /* Dimension.TabId */, tab());
5151
- log(16 /* Dimension.PageLanguage */, document.documentElement.lang);
5152
- log(17 /* Dimension.DocumentDirection */, document.dir);
5153
- log(26 /* Dimension.DevicePixelRatio */, "".concat(window.devicePixelRatio));
5154
- log(28 /* Dimension.Dob */, u.dob.toString());
5155
- log(29 /* Dimension.CookieVersion */, u.version.toString());
5156
- log(33 /* Dimension.AncestorOrigins */, ancestorOrigins);
5157
- log(34 /* Dimension.Timezone */, timezone);
5158
- log(35 /* Dimension.TimezoneOffset */, timezoneOffset);
5159
- // Capture additional metadata as metrics
5160
- max(0 /* Metric.ClientTimestamp */, s.ts);
5161
- max(1 /* Metric.Playback */, 0 /* BooleanFlag.False */);
5162
- max(35 /* Metric.Electron */, electron);
5163
- // Capture navigator specific dimensions
5164
- if (navigator) {
5165
- log(9 /* Dimension.Language */, navigator.language);
5166
- max(33 /* Metric.HardwareConcurrency */, navigator.hardwareConcurrency);
5167
- max(32 /* Metric.MaxTouchPoints */, navigator.maxTouchPoints);
5168
- // biome-ignore lint/suspicious/noExplicitAny: not all browsers support navigator.deviceMemory
5169
- max(34 /* Metric.DeviceMemory */, Math.round(navigator.deviceMemory));
5170
- userAgentData();
5094
+ var signalCallback = null;
5095
+ function signal(cb) {
5096
+ signalCallback = cb;
5097
+ }
5098
+ function parseSignals(signalsPayload) {
5099
+ try {
5100
+ var parsedSignals = JSON.parse(signalsPayload);
5101
+ return parsedSignals;
5171
5102
  }
5172
- if (screen) {
5173
- max(14 /* Metric.ScreenWidth */, Math.round(screen.width));
5174
- max(15 /* Metric.ScreenHeight */, Math.round(screen.height));
5175
- max(16 /* Metric.ColorDepth */, Math.round(screen.colorDepth));
5103
+ catch (_a) {
5104
+ return [];
5176
5105
  }
5177
- // Read cookies specified in configuration
5178
- for (var _i = 0, _d = config$2.cookies; _i < _d.length; _i++) {
5179
- var key = _d[_i];
5180
- var value = getCookie(key);
5181
- if (value) {
5182
- set(key, value);
5106
+ }
5107
+ function signalsEvent(signalsPayload) {
5108
+ try {
5109
+ if (!signalCallback) {
5110
+ return;
5111
+ }
5112
+ var signals = parseSignals(signalsPayload);
5113
+ for (var _i = 0, signals_1 = signals; _i < signals_1.length; _i++) {
5114
+ var signal_1 = signals_1[_i];
5115
+ signalCallback(signal_1);
5183
5116
  }
5184
5117
  }
5185
- // Track consent config
5186
- config$1(config$2.track);
5187
- // Track ids using a cookie if configuration allows it
5188
- track(u);
5189
- }
5190
- function userAgentData() {
5191
- // biome-ignore lint/suspicious/noExplicitAny: not all browsers support navigator.userAgentData
5192
- var uaData = navigator.userAgentData;
5193
- if (uaData === null || uaData === void 0 ? void 0 : uaData.getHighEntropyValues) {
5194
- uaData.getHighEntropyValues(["model", "platform", "platformVersion", "uaFullVersion"]).then(function (ua) {
5195
- log(22 /* Dimension.Platform */, ua.platform);
5196
- log(23 /* Dimension.PlatformVersion */, ua.platformVersion);
5197
- if (ua.brands) {
5198
- for (var _i = 0, _a = ua.brands; _i < _a.length; _i++) {
5199
- var brand = _a[_i];
5200
- log(24 /* Dimension.Brand */, brand.name + "~" /* Constant.Tilde */ + brand.version);
5201
- }
5202
- }
5203
- log(25 /* Dimension.Model */, ua.model);
5204
- max(27 /* Metric.Mobile */, ua.mobile ? 1 /* BooleanFlag.True */ : 0 /* BooleanFlag.False */);
5205
- });
5118
+ catch (_a) {
5119
+ //do nothing
5206
5120
  }
5207
- else {
5208
- log(22 /* Dimension.Platform */, navigator.platform);
5121
+ }
5122
+
5123
+ var modules$1 = [baseline, dimension, variable, limit, summary, metadata$1, envelope$1, upload$1, ping$1, upgrade$1, extract];
5124
+ function start$a() {
5125
+ // Metric needs to be initialized before we can start measuring. so metric is not wrapped in measure
5126
+ start$F();
5127
+ for (var _i = 0, modules_1 = modules$1; _i < modules_1.length; _i++) {
5128
+ var x = modules_1[_i];
5129
+ measure(x.start)();
5209
5130
  }
5210
5131
  }
5211
- function stop$8() {
5212
- rootDomain = null;
5213
- data$2 = null;
5214
- for (var _i = 0, callbacks_1 = callbacks; _i < callbacks_1.length; _i++) {
5215
- var cb = callbacks_1[_i];
5216
- cb.called = false;
5132
+ function stop$9() {
5133
+ // Stop modules in the reverse order of their initialization
5134
+ // The ordering below should respect inter-module dependency.
5135
+ // E.g. if upgrade depends on upload, then upgrade needs to end before upload.
5136
+ // Similarly, if upload depends on metadata, upload needs to end before metadata.
5137
+ for (var _i = 0, _a = modules$1.slice().reverse(); _i < _a.length; _i++) {
5138
+ var x = _a[_i];
5139
+ measure(x.stop)();
5217
5140
  }
5141
+ stop$C();
5218
5142
  }
5219
- function metadata(cb, wait, recall) {
5220
- if (wait === void 0) { wait = true; }
5221
- if (recall === void 0) { recall = false; }
5222
- var upgraded = config$2.lean ? 0 /* BooleanFlag.False */ : 1 /* BooleanFlag.True */;
5223
- var called = false;
5224
- // if caller hasn't specified that they want to skip waiting for upgrade but we've already upgraded, we need to
5225
- // directly execute the callback in addition to adding to our list as we only process callbacks at the moment
5226
- // we go through the upgrading flow.
5227
- if (data$2 && (upgraded || wait === false)) {
5228
- // Immediately invoke the callback if the caller explicitly doesn't want to wait for the upgrade confirmation
5229
- cb(data$2, !config$2.lean);
5230
- called = true;
5231
- }
5232
- if (recall || !called) {
5233
- callbacks.push({ callback: cb, wait: wait, recall: recall, called: called });
5234
- }
5235
- }
5236
- function id() {
5237
- return data$2 ? [data$2.userId, data$2.sessionId, data$2.pageNum].join("." /* Constant.Dot */) : "" /* Constant.Empty */;
5238
- }
5239
- function consent(status) {
5240
- if (status === void 0) { status = true; }
5241
- if (!status) {
5242
- config$2.track = false;
5243
- setCookie("_clsk" /* Constant.SessionKey */, "" /* Constant.Empty */, -Number.MAX_VALUE);
5244
- setCookie("_clck" /* Constant.CookieKey */, "" /* Constant.Empty */, -Number.MAX_VALUE);
5245
- stop();
5246
- window.setTimeout(start, 250 /* Setting.RestartDelay */);
5247
- return;
5248
- }
5249
- if (active()) {
5250
- config$2.track = true;
5251
- track(user(), 1 /* BooleanFlag.True */);
5252
- save();
5253
- consent$1();
5254
- }
5255
- }
5256
- function clear() {
5257
- // Clear any stored information in the cookie that tracks session information so we can restart fresh the next time
5258
- setCookie("_clsk" /* Constant.SessionKey */, "" /* Constant.Empty */, 0);
5259
- }
5260
- function tab() {
5261
- var id = shortid();
5262
- if (config$2.track && supported(window, "sessionStorage" /* Constant.SessionStorage */)) {
5263
- var value = sessionStorage.getItem("_cltk" /* Constant.TabKey */);
5264
- id = value ? value : id;
5265
- sessionStorage.setItem("_cltk" /* Constant.TabKey */, id);
5266
- }
5267
- return id;
5268
- }
5269
- function callback() {
5270
- var upgrade = config$2.lean ? 0 /* BooleanFlag.False */ : 1 /* BooleanFlag.True */;
5271
- processCallback(upgrade);
5143
+ function compute$2() {
5144
+ compute$5();
5145
+ compute$e();
5146
+ compute$3();
5147
+ compute$c();
5148
+ compute$b();
5149
+ compute$4();
5150
+ compute$d();
5272
5151
  }
5273
- function save() {
5274
- if (!data$2 || !config$2.track)
5275
- return;
5276
- var ts = Math.round(Date.now());
5277
- var upload = config$2.upload && typeof config$2.upload === "string"
5278
- ? config$2.upload.replace("https://" /* Constant.HTTPS */, "" /* Constant.Empty */)
5279
- : "" /* Constant.Empty */;
5280
- var upgrade = config$2.lean ? 0 /* BooleanFlag.False */ : 1 /* BooleanFlag.True */;
5281
- setCookie("_clsk" /* Constant.SessionKey */, [data$2.sessionId, ts, data$2.pageNum, upgrade, upload].join("|" /* Constant.Pipe */), 1 /* Setting.SessionExpire */);
5152
+
5153
+ var discoverBytes = 0;
5154
+ var playbackBytes = 0;
5155
+ var playback;
5156
+ var analysis;
5157
+ var timeout = null;
5158
+ var transit;
5159
+ var active$1;
5160
+ var queuedTime = 0;
5161
+ var leanLimit = false;
5162
+ var track;
5163
+ function start$9() {
5164
+ active$1 = true;
5165
+ discoverBytes = 0;
5166
+ playbackBytes = 0;
5167
+ leanLimit = false;
5168
+ queuedTime = 0;
5169
+ playback = [];
5170
+ analysis = [];
5171
+ transit = {};
5172
+ track = null;
5282
5173
  }
5283
- function processCallback(upgrade) {
5284
- if (callbacks.length > 0) {
5285
- for (var i = 0; i < callbacks.length; i++) {
5286
- var cb = callbacks[i];
5287
- if (cb.callback && !cb.called && (!cb.wait || upgrade)) {
5288
- cb.callback(data$2, !config$2.lean);
5289
- cb.called = true;
5290
- if (!cb.recall) {
5291
- callbacks.splice(i, 1);
5292
- i--;
5174
+ function queue(tokens, transmit) {
5175
+ if (transmit === void 0) { transmit = true; }
5176
+ if (active$1) {
5177
+ var now = time();
5178
+ var type = tokens.length > 1 ? tokens[1] : null;
5179
+ var event_1 = JSON.stringify(tokens);
5180
+ if (!config$2.lean) {
5181
+ leanLimit = false;
5182
+ }
5183
+ else if (!leanLimit && playbackBytes + event_1.length > 10485760 /* Setting.PlaybackBytesLimit */) {
5184
+ log(10 /* Code.LeanLimit */, 0 /* Severity.Info */);
5185
+ leanLimit = true;
5186
+ }
5187
+ switch (type) {
5188
+ // biome-ignore lint/suspicious/noFallthroughSwitchClause: we want discover bytes to also count as playback bytes
5189
+ case 5 /* Event.Discover */:
5190
+ if (leanLimit) {
5191
+ break;
5293
5192
  }
5193
+ discoverBytes += event_1.length;
5194
+ case 37 /* Event.Box */:
5195
+ case 6 /* Event.Mutation */:
5196
+ case 43 /* Event.Snapshot */:
5197
+ case 45 /* Event.StyleSheetAdoption */:
5198
+ case 46 /* Event.StyleSheetUpdate */:
5199
+ if (leanLimit) {
5200
+ break;
5201
+ }
5202
+ playbackBytes += event_1.length;
5203
+ playback.push(event_1);
5204
+ break;
5205
+ default:
5206
+ analysis.push(event_1);
5207
+ break;
5208
+ }
5209
+ // Increment event count metric
5210
+ count$1(25 /* Metric.EventCount */);
5211
+ // Following two checks are precautionary and act as a fail safe mechanism to get out of unexpected situations.
5212
+ // Check 1: If for any reason the upload hasn't happened after waiting for 2x the config.delay time,
5213
+ // reset the timer. This allows Clarity to attempt an upload again.
5214
+ var gap = delay();
5215
+ if (now - queuedTime > gap * 2) {
5216
+ clearTimeout(timeout);
5217
+ timeout = null;
5218
+ }
5219
+ // Transmit Check: When transmit is set to true (default), it indicates that we should schedule an upload
5220
+ // However, in certain scenarios - like metric calculation - which are triggered as part of an existing upload
5221
+ // We enrich the data going out with the existing upload. In these cases, call to upload comes with 'transmit' set to false.
5222
+ if (transmit && timeout === null) {
5223
+ if (type !== 25 /* Event.Ping */) {
5224
+ reset$p();
5294
5225
  }
5226
+ timeout = setTimeout$1(upload, gap);
5227
+ queuedTime = now;
5228
+ check$3(playbackBytes);
5295
5229
  }
5296
5230
  }
5297
5231
  }
5298
- function supported(target, api) {
5299
- try {
5300
- return !!target[api];
5301
- }
5302
- catch (_a) {
5303
- return false;
5304
- }
5305
- }
5306
- function track(u, consentInput) {
5307
- if (consentInput === void 0) { consentInput = null; }
5308
- // If consent is not explicitly specified, infer it from the user object
5309
- var consent = consentInput === null ? u.consent : consentInput;
5310
- // Convert time precision into days to reduce number of bytes we have to write in a cookie
5311
- // E.g. Math.ceil(1628735962643 / (24*60*60*1000)) => 18852 (days) => ejo in base36 (13 bytes => 3 bytes)
5312
- var end = Math.ceil((Date.now() + 365 /* Setting.Expire */ * 86400000 /* Time.Day */) / 86400000 /* Time.Day */);
5313
- // If DOB is not set in the user object, use the date set in the config as a DOB
5314
- var dob = u.dob === 0 ? (config$2.dob === null ? 0 : config$2.dob) : u.dob;
5315
- // To avoid cookie churn, write user id cookie only once every day
5316
- if (u.expiry === null || Math.abs(end - u.expiry) >= 1 /* Setting.CookieInterval */ || u.consent !== consent || u.dob !== dob) {
5317
- var cookieParts = [data$2.userId, 2 /* Setting.CookieVersion */, end.toString(36), consent, dob];
5318
- setCookie("_clck" /* Constant.CookieKey */, cookieParts.join("|" /* Constant.Pipe */), 365 /* Setting.Expire */);
5319
- }
5320
- }
5321
- function shortid() {
5322
- var _a;
5323
- var id = Math.floor(Math.random() * Math.pow(2, 32));
5324
- if (((_a = window === null || window === void 0 ? void 0 : window.crypto) === null || _a === void 0 ? void 0 : _a.getRandomValues) && Uint32Array) {
5325
- id = window.crypto.getRandomValues(new Uint32Array(1))[0];
5326
- }
5327
- return id.toString(36);
5232
+ function stop$8() {
5233
+ clearTimeout(timeout);
5234
+ upload(true);
5235
+ discoverBytes = 0;
5236
+ playbackBytes = 0;
5237
+ leanLimit = false;
5238
+ queuedTime = 0;
5239
+ playback = [];
5240
+ analysis = [];
5241
+ transit = {};
5242
+ track = null;
5243
+ active$1 = false;
5328
5244
  }
5329
- function session() {
5330
- var output = { session: shortid(), ts: Math.round(Date.now()), count: 1, upgrade: null, upload: "" /* Constant.Empty */ };
5331
- var value = getCookie("_clsk" /* Constant.SessionKey */, !config$2.includeSubdomains);
5332
- if (value) {
5333
- // Maintaining support for pipe separator for backward compatibility, this can be removed in future releases
5334
- var parts = value.includes("^" /* Constant.Caret */) ? value.split("^" /* Constant.Caret */) : value.split("|" /* Constant.Pipe */);
5335
- // Making it backward & forward compatible by using greater than comparison (v0.6.21)
5336
- // In future version, we can reduce the parts length to be 5 where the last part contains the full upload URL
5337
- if (parts.length >= 5 && output.ts - num(parts[1]) < 1800000 /* Setting.SessionTimeout */) {
5338
- output.session = parts[0];
5339
- output.count = num(parts[2]) + 1;
5340
- output.upgrade = num(parts[3]);
5341
- output.upload = parts.length >= 6 ? "".concat("https://" /* Constant.HTTPS */).concat(parts[5], "/").concat(parts[4]) : "".concat("https://" /* Constant.HTTPS */).concat(parts[4]);
5342
- }
5343
- }
5344
- return output;
5245
+ function upload(final) {
5246
+ if (final === void 0) { final = false; }
5247
+ return __awaiter(this, void 0, void 0, function () {
5248
+ var sendPlaybackBytes, last, e, a, p, encoded, payload, zipped, _a;
5249
+ return __generator(this, function (_b) {
5250
+ switch (_b.label) {
5251
+ case 0:
5252
+ timeout = null;
5253
+ sendPlaybackBytes = config$2.lean === false && playbackBytes > 0 && (playbackBytes < 1048576 /* Setting.MaxFirstPayloadBytes */ || data$3.sequence > 0);
5254
+ if (sendPlaybackBytes) {
5255
+ max(1 /* Metric.Playback */, 1 /* BooleanFlag.True */);
5256
+ }
5257
+ // CAUTION: Ensure "transmit" is set to false in the queue function for following events
5258
+ // Otherwise you run a risk of infinite loop.
5259
+ compute$a();
5260
+ compute$7();
5261
+ compute$2();
5262
+ compute$9();
5263
+ last = final === true;
5264
+ e = JSON.stringify(envelope(last));
5265
+ a = "[".concat(analysis.join(), "]");
5266
+ p = sendPlaybackBytes ? "[".concat(playback.join(), "]") : "" /* Constant.Empty */;
5267
+ encoded = { e: e, a: a, p: p };
5268
+ payload = stringify(encoded);
5269
+ if (!last) return [3 /*break*/, 1];
5270
+ _a = null;
5271
+ return [3 /*break*/, 3];
5272
+ case 1: return [4 /*yield*/, compress(payload)];
5273
+ case 2:
5274
+ _a = _b.sent();
5275
+ _b.label = 3;
5276
+ case 3:
5277
+ zipped = _a;
5278
+ sum(2 /* Metric.TotalBytes */, zipped ? zipped.length : payload.length);
5279
+ send(payload, zipped, data$3.sequence, last);
5280
+ // Clear out events now that payload has been dispatched
5281
+ analysis = [];
5282
+ if (sendPlaybackBytes) {
5283
+ playback = [];
5284
+ playbackBytes = 0;
5285
+ discoverBytes = 0;
5286
+ leanLimit = false;
5287
+ }
5288
+ return [2 /*return*/];
5289
+ }
5290
+ });
5291
+ });
5345
5292
  }
5346
- function num(string, base) {
5347
- if (base === void 0) { base = 10; }
5348
- return Number.parseInt(string, base);
5293
+ function stringify(encoded) {
5294
+ return encoded.p.length > 0 ? "{\"e\":".concat(encoded.e, ",\"a\":").concat(encoded.a, ",\"p\":").concat(encoded.p, "}") : "{\"e\":".concat(encoded.e, ",\"a\":").concat(encoded.a, "}");
5349
5295
  }
5350
- function user() {
5351
- var output = { id: shortid(), version: 0, expiry: null, consent: 0 /* BooleanFlag.False */, dob: 0 };
5352
- var cookie = getCookie("_clck" /* Constant.CookieKey */, !config$2.includeSubdomains);
5353
- if (cookie && cookie.length > 0) {
5354
- // Splitting and looking up first part for forward compatibility, in case we wish to store additional information in a cookie
5355
- // Maintaining support for pipe separator for backward compatibility, this can be removed in future releases
5356
- var parts = cookie.includes("^" /* Constant.Caret */) ? cookie.split("^" /* Constant.Caret */) : cookie.split("|" /* Constant.Pipe */);
5357
- // Read version information and timestamp from cookie, if available
5358
- if (parts.length > 1) {
5359
- output.version = num(parts[1]);
5360
- }
5361
- if (parts.length > 2) {
5362
- output.expiry = num(parts[2], 36);
5363
- }
5364
- // Check if we have explicit consent to track this user
5365
- if (parts.length > 3 && num(parts[3]) === 1) {
5366
- output.consent = 1 /* BooleanFlag.True */;
5296
+ function send(payload, zipped, sequence, beacon) {
5297
+ if (beacon === void 0) { beacon = false; }
5298
+ // Upload data if a valid URL is defined in the config
5299
+ if (typeof config$2.upload === "string") {
5300
+ var url_1 = config$2.upload;
5301
+ var dispatched = false;
5302
+ // If it's the last payload, attempt to upload using sendBeacon first.
5303
+ // The advantage to using sendBeacon is that browser can decide to upload asynchronously, improving chances of success
5304
+ // However, we don't want to rely on it for every payload, since we have no ability to retry if the upload failed.
5305
+ // Also, in case of sendBeacon, we do not have a way to alter HTTP headers and therefore can't send compressed payload
5306
+ if (beacon && "sendBeacon" in navigator) {
5307
+ try {
5308
+ // Navigator needs to be bound to sendBeacon before it is used to avoid errors in some browsers
5309
+ dispatched = navigator.sendBeacon.bind(navigator)(url_1, payload);
5310
+ if (dispatched) {
5311
+ done(sequence);
5312
+ }
5313
+ }
5314
+ catch (_a) {
5315
+ /* do nothing - and we will automatically fallback to XHR below */
5316
+ }
5367
5317
  }
5368
- if (parts.length > 4 && num(parts[1]) > 1) {
5369
- output.dob = num(parts[4]);
5318
+ // Before initiating XHR upload, we check if the data has already been uploaded using sendBeacon
5319
+ // There are two cases when dispatched could still be false:
5320
+ // a) It's not the last payload, and therefore we didn't attempt sending sendBeacon
5321
+ // b) It's the last payload, however, we failed to queue sendBeacon call and need to now fall back to XHR.
5322
+ // E.g. if data is over 64KB, several user agents (like Chrome) will reject to queue the sendBeacon call.
5323
+ if (dispatched === false) {
5324
+ // While tracking payload for retry, we only track string value of the payload to err on the safe side
5325
+ // Not all browsers support compression API and the support for it in supported browsers is still experimental
5326
+ if (sequence in transit) {
5327
+ transit[sequence].attempts++;
5328
+ }
5329
+ else {
5330
+ transit[sequence] = { data: payload, attempts: 1 };
5331
+ }
5332
+ var xhr_1 = new XMLHttpRequest();
5333
+ xhr_1.open("POST", url_1, true);
5334
+ xhr_1.timeout = 15000 /* Setting.UploadTimeout */;
5335
+ xhr_1.ontimeout = function () {
5336
+ report(new Error("".concat("Timeout" /* Constant.Timeout */, " : ").concat(url_1)));
5337
+ };
5338
+ if (sequence !== null) {
5339
+ xhr_1.onreadystatechange = function () {
5340
+ measure(check$2)(xhr_1, sequence);
5341
+ };
5342
+ }
5343
+ xhr_1.withCredentials = true;
5344
+ if (zipped) {
5345
+ // If we do have valid compressed array, send it with appropriate HTTP headers so server can decode it appropriately
5346
+ xhr_1.setRequestHeader("Accept" /* Constant.Accept */, "application/x-clarity-gzip" /* Constant.ClarityGzip */);
5347
+ xhr_1.send(zipped);
5348
+ }
5349
+ else {
5350
+ // In all other cases, continue sending string back to the server
5351
+ xhr_1.send(payload);
5352
+ }
5370
5353
  }
5371
- // Set track configuration to true for this user if we have explicit consent, regardless of project setting
5372
- config$2.track = config$2.track || output.consent === 1 /* BooleanFlag.True */;
5373
- // Get user id from cookie only if we tracking is enabled, otherwise fallback to a random id
5374
- output.id = config$2.track ? parts[0] : output.id;
5375
5354
  }
5376
- return output;
5355
+ else if (config$2.upload) {
5356
+ var callback = config$2.upload;
5357
+ callback(payload);
5358
+ done(sequence);
5359
+ }
5377
5360
  }
5378
- function getCookie(key, limit) {
5379
- var _a;
5380
- if (limit === void 0) { limit = false; }
5381
- if (supported(document, "cookie" /* Constant.Cookie */)) {
5382
- var cookies = document.cookie.split(";" /* Constant.Semicolon */);
5383
- if (cookies) {
5384
- for (var i = 0; i < cookies.length; i++) {
5385
- var pair = cookies[i].split("=" /* Constant.Equals */);
5386
- if (pair.length > 1 && pair[0] && pair[0].trim() === key) {
5387
- // Some browsers automatically url encode cookie values if they are not url encoded.
5388
- // We therefore encode and decode cookie values ourselves.
5389
- // For backwards compatability we need to consider 3 cases:
5390
- // * Cookie was previously not encoded by Clarity and browser did not encode it
5391
- // * Cookie was previously not encoded by Clarity and browser encoded it once or more
5392
- // * Cookie was previously encoded by Clarity and browser did not encode it
5393
- var _b = decodeCookieValue(pair[1]), isEncoded = _b[0], decodedValue = _b[1];
5394
- while (isEncoded) {
5395
- _a = decodeCookieValue(decodedValue), isEncoded = _a[0], decodedValue = _a[1];
5396
- }
5397
- // If we are limiting cookies, check if the cookie value is limited
5398
- if (limit) {
5399
- return decodedValue.endsWith("".concat("~" /* Constant.Tilde */, "1")) ? decodedValue.substring(0, decodedValue.length - 2) : null;
5400
- }
5401
- return decodedValue;
5361
+ function check$2(xhr, sequence) {
5362
+ var transitData = transit[sequence];
5363
+ if (xhr && xhr.readyState === 4 /* XMLReadyState.Done */ && transitData) {
5364
+ // Attempt send payload again (as configured in settings) if we do not receive a success (2XX) response code back from the server
5365
+ if ((xhr.status < 200 || xhr.status > 208) && transitData.attempts <= 1 /* Setting.RetryLimit */) {
5366
+ // We re-attempt in all cases except when server explicitly rejects our request with 4XX error
5367
+ if (xhr.status >= 400 && xhr.status < 500) {
5368
+ // In case of a 4XX response from the server, we bail out instead of trying again
5369
+ trigger(6 /* Check.Server */);
5370
+ }
5371
+ else {
5372
+ // Browser will send status = 0 when it refuses to put network request over the wire
5373
+ // This could happen for several reasons, couple of known ones are:
5374
+ // 1: Browsers block upload because of content security policy violation
5375
+ // 2: Safari will terminate pending XHR requests with status code 0 if the user navigates away from the page
5376
+ // In any case, we switch the upload URL to fallback configuration (if available) before re-trying one more time
5377
+ if (xhr.status === 0) {
5378
+ config$2.upload = config$2.fallback ? config$2.fallback : config$2.upload;
5402
5379
  }
5380
+ // In all other cases, re-attempt sending the same data
5381
+ // For retry we always fallback to string payload, even though we may have attempted
5382
+ // sending zipped payload earlier
5383
+ send(transitData.data, null, sequence);
5384
+ }
5385
+ }
5386
+ else {
5387
+ track = { sequence: sequence, attempts: transitData.attempts, status: xhr.status };
5388
+ // Send back an event only if we were not successful in our first attempt
5389
+ if (transitData.attempts > 1) {
5390
+ encode$2(2 /* Event.Upload */);
5391
+ }
5392
+ // Handle response if it was a 200 response with a valid body
5393
+ if (xhr.status === 200 && xhr.responseText) {
5394
+ response(xhr.responseText);
5395
+ }
5396
+ // If we exhausted our retries then trigger Clarity's shutdown for this page since the data will be incomplete
5397
+ if (xhr.status === 0) {
5398
+ // And, right before we terminate the session, we will attempt one last time to see if we can use
5399
+ // different transport option (sendBeacon vs. XHR) to get this data to the server for analysis purposes
5400
+ send(transitData.data, null, sequence, true);
5401
+ trigger(3 /* Check.Retry */);
5402
+ }
5403
+ // Signal that this request completed successfully
5404
+ if (xhr.status >= 200 && xhr.status <= 208) {
5405
+ done(sequence);
5403
5406
  }
5407
+ // Stop tracking this payload now that it's all done
5408
+ delete transit[sequence];
5404
5409
  }
5405
5410
  }
5406
- return null;
5407
5411
  }
5408
- function decodeCookieValue(value) {
5409
- try {
5410
- var decodedValue = decodeURIComponent(value);
5411
- return [decodedValue !== value, decodedValue];
5412
+ function done(sequence) {
5413
+ // If we everything went successfully, and it is the first sequence, save this session for future reference
5414
+ if (sequence === 1) {
5415
+ save();
5416
+ callback();
5412
5417
  }
5413
- catch (_a) { }
5414
- return [false, value];
5415
5418
  }
5416
- function encodeCookieValue(value) {
5417
- return encodeURIComponent(value);
5419
+ function delay() {
5420
+ // Progressively increase delay as we continue to send more payloads from the client to the server
5421
+ // If we are not uploading data to a server, and instead invoking UploadCallback, in that case keep returning configured value
5422
+ var gap = config$2.lean === false && discoverBytes > 0 ? 100 /* Setting.MinUploadDelay */ : data$3.sequence * config$2.delay;
5423
+ return typeof config$2.upload === "string" ? Math.max(Math.min(gap, 30000 /* Setting.MaxUploadDelay */), 100 /* Setting.MinUploadDelay */) : config$2.delay;
5418
5424
  }
5419
- function setCookie(key, value, time) {
5420
- // only write cookies if we are currently in a cookie writing mode (and they are supported)
5421
- // OR if we are trying to write an empty cookie (i.e. clear the cookie value out)
5422
- if ((config$2.track || value === "" /* Constant.Empty */) && ((navigator === null || navigator === void 0 ? void 0 : navigator.cookieEnabled) || supported(document, "cookie" /* Constant.Cookie */))) {
5423
- // Some browsers automatically url encode cookie values if they are not url encoded.
5424
- // We therefore encode and decode cookie values ourselves.
5425
- var encodedValue = encodeCookieValue(value);
5426
- var expiry = new Date();
5427
- expiry.setDate(expiry.getDate() + time);
5428
- var expires = expiry ? "expires=" /* Constant.Expires */ + expiry.toUTCString() : "" /* Constant.Empty */;
5429
- var cookie = "".concat(key, "=").concat(encodedValue).concat(";" /* Constant.Semicolon */).concat(expires).concat(";path=/" /* Constant.Path */);
5430
- try {
5431
- // Attempt to get the root domain only once and fall back to writing cookie on the current domain.
5432
- if (rootDomain === null) {
5433
- var hostname = location.hostname ? location.hostname.split("." /* Constant.Dot */) : [];
5434
- // Walk backwards on a domain and attempt to set a cookie, until successful
5435
- for (var i = hostname.length - 1; i >= 0; i--) {
5436
- rootDomain = ".".concat(hostname[i]).concat(rootDomain ? rootDomain : "" /* Constant.Empty */);
5437
- // We do not wish to attempt writing a cookie on the absolute last part of the domain, e.g. .com or .net.
5438
- // So we start attempting after second-last part, e.g. .domain.com (PASS) or .co.uk (FAIL)
5439
- if (i < hostname.length - 1) {
5440
- // Write the cookie on the current computed top level domain
5441
- document.cookie = "".concat(cookie).concat(";" /* Constant.Semicolon */).concat("domain=" /* Constant.Domain */).concat(rootDomain);
5442
- // Once written, check if the cookie exists and its value matches exactly with what we intended to set
5443
- // Checking for exact value match helps us eliminate a corner case where the cookie may already be present with a different value
5444
- // If the check is successful, no more action is required and we can return from the function since rootDomain cookie is already set
5445
- // If the check fails, continue with the for loop until we can successfully set and verify the cookie
5446
- if (getCookie(key) === value) {
5447
- return;
5448
- }
5449
- }
5425
+ function response(payload) {
5426
+ var lines = payload && payload.length > 0 ? payload.split("\n") : [];
5427
+ for (var _i = 0, lines_1 = lines; _i < lines_1.length; _i++) {
5428
+ var line = lines_1[_i];
5429
+ var parts = line && line.length > 0 ? line.split(/ (.*)/) : ["" /* Constant.Empty */];
5430
+ switch (parts[0]) {
5431
+ case "END" /* Constant.End */:
5432
+ // Clear out session storage and end the session so we can start fresh the next time
5433
+ trigger(6 /* Check.Server */);
5434
+ break;
5435
+ case "UPGRADE" /* Constant.Upgrade */:
5436
+ // Upgrade current session to send back playback information
5437
+ upgrade("Auto" /* Constant.Auto */);
5438
+ break;
5439
+ case "ACTION" /* Constant.Action */:
5440
+ // Invoke action callback, if configured and has a valid value
5441
+ if (config$2.action && parts.length > 1) {
5442
+ config$2.action(parts[1]);
5450
5443
  }
5451
- // Finally, if we were not successful and gone through all the options, play it safe and reset rootDomain to be empty
5452
- // This forces our code to fall back to always writing cookie to the current domain
5453
- rootDomain = "" /* Constant.Empty */;
5454
- }
5455
- }
5456
- catch (_a) {
5457
- rootDomain = "" /* Constant.Empty */;
5444
+ break;
5445
+ case "EXTRACT" /* Constant.Extract */:
5446
+ if (parts.length > 1) {
5447
+ trigger$2(parts[1]);
5448
+ }
5449
+ break;
5450
+ case "SIGNAL" /* Constant.Signal */:
5451
+ if (parts.length > 1) {
5452
+ signalsEvent(parts[1]);
5453
+ }
5454
+ break;
5458
5455
  }
5459
- document.cookie = rootDomain ? "".concat(cookie).concat(";" /* Constant.Semicolon */).concat("domain=" /* Constant.Domain */).concat(rootDomain) : cookie;
5460
5456
  }
5461
5457
  }
5462
5458
 
5463
- var data$1 = null;
5464
- function start$7() {
5465
- var m = data$2;
5466
- data$1 = {
5467
- version: version$1,
5468
- sequence: 0,
5469
- start: 0,
5470
- duration: 0,
5471
- projectId: m.projectId,
5472
- userId: m.userId,
5473
- sessionId: m.sessionId,
5474
- pageNum: m.pageNum,
5475
- upload: 0 /* Upload.Async */,
5476
- end: 0 /* BooleanFlag.False */,
5477
- applicationPlatform: 0 /* ApplicationPlatform.WebApp */,
5478
- url: "",
5479
- };
5459
+ var history$2 = {};
5460
+ var data$2;
5461
+ function start$8() {
5462
+ bind(window, "error", handler);
5463
+ history$2 = {};
5480
5464
  }
5481
- function stop$7() {
5482
- data$1 = null;
5465
+ function handler(error) {
5466
+ handler.dn = 4 /* FunctionNames.ScriptHandler */;
5467
+ var e = error.error || error;
5468
+ // While rare, it's possible for code to fail repeatedly during the lifetime of the same page
5469
+ // In those cases, we only want to log the failure first few times and not spam logs with redundant information.
5470
+ if (!(e.message in history$2)) {
5471
+ history$2[e.message] = 0;
5472
+ }
5473
+ if (history$2[e.message]++ >= 5 /* Setting.ScriptErrorLimit */) {
5474
+ return true;
5475
+ }
5476
+ // Send back information only if the handled error has valid information
5477
+ if (e === null || e === void 0 ? void 0 : e.message) {
5478
+ data$2 = {
5479
+ message: e.message,
5480
+ line: error.lineno,
5481
+ column: error.colno,
5482
+ stack: e.stack,
5483
+ source: error.filename,
5484
+ };
5485
+ encode$1(31 /* Event.ScriptError */);
5486
+ }
5487
+ return true;
5483
5488
  }
5484
- function envelope(last) {
5485
- data$1.start = data$1.start + data$1.duration;
5486
- data$1.duration = time() - data$1.start;
5487
- data$1.sequence++;
5488
- data$1.upload = last && "sendBeacon" in navigator ? 1 /* Upload.Beacon */ : 0 /* Upload.Async */;
5489
- data$1.end = last ? 1 /* BooleanFlag.True */ : 0 /* BooleanFlag.False */;
5490
- data$1.applicationPlatform = 0 /* ApplicationPlatform.WebApp */;
5491
- data$1.url = url$1(location.href, false, true);
5492
- return [
5493
- data$1.version,
5494
- data$1.sequence,
5495
- data$1.start,
5496
- data$1.duration,
5497
- data$1.projectId,
5498
- data$1.userId,
5499
- data$1.sessionId,
5500
- data$1.pageNum,
5501
- data$1.upload,
5502
- data$1.end,
5503
- data$1.applicationPlatform,
5504
- data$1.url,
5505
- ];
5489
+
5490
+ function encode$1 (type) {
5491
+ return __awaiter(this, void 0, void 0, function () {
5492
+ var tokens;
5493
+ return __generator(this, function (_a) {
5494
+ tokens = [time(), type];
5495
+ switch (type) {
5496
+ case 31 /* Event.ScriptError */:
5497
+ tokens.push(data$2.message);
5498
+ tokens.push(data$2.line);
5499
+ tokens.push(data$2.column);
5500
+ tokens.push(data$2.stack);
5501
+ tokens.push(url$1(data$2.source));
5502
+ queue(tokens);
5503
+ break;
5504
+ case 33 /* Event.Log */:
5505
+ if (data$1) {
5506
+ tokens.push(data$1.code);
5507
+ tokens.push(data$1.name);
5508
+ tokens.push(data$1.message);
5509
+ tokens.push(data$1.stack);
5510
+ tokens.push(data$1.severity);
5511
+ queue(tokens, false);
5512
+ }
5513
+ break;
5514
+ case 41 /* Event.Fraud */:
5515
+ if (data$e) {
5516
+ tokens.push(data$e.id);
5517
+ tokens.push(data$e.target);
5518
+ tokens.push(data$e.checksum);
5519
+ queue(tokens, false);
5520
+ }
5521
+ break;
5522
+ }
5523
+ return [2 /*return*/];
5524
+ });
5525
+ });
5506
5526
  }
5507
5527
 
5508
- var history$1;
5509
- function reset$2() {
5510
- history$1 = [];
5528
+ var history$1 = {};
5529
+ var data$1;
5530
+ function start$7() {
5531
+ history$1 = {};
5511
5532
  }
5512
- function report(e) {
5513
- // Do not report the same message twice for the same page
5514
- if (history$1 && history$1.indexOf(e.message) === -1) {
5515
- var url = config$2.report;
5516
- if (url && url.length > 0) {
5517
- var payload = { v: data$1.version, p: data$1.projectId, u: data$1.userId, s: data$1.sessionId, n: data$1.pageNum };
5518
- if (e.message) {
5519
- payload.m = e.message;
5520
- }
5521
- if (e.stack) {
5522
- payload.e = e.stack;
5523
- }
5524
- // Using POST request instead of a GET request (img-src) to not violate existing CSP rules
5525
- // Since, Clarity already uses XHR to upload data, we stick with similar POST mechanism for reporting too
5526
- var xhr = new XMLHttpRequest();
5527
- xhr.open("POST", url, true);
5528
- xhr.send(JSON.stringify(payload));
5529
- history$1.push(e.message);
5530
- }
5533
+ function log(code, severity, name, message, stack) {
5534
+ if (name === void 0) { name = null; }
5535
+ if (message === void 0) { message = null; }
5536
+ if (stack === void 0) { stack = null; }
5537
+ var key = name ? "".concat(name, "|").concat(message) : "";
5538
+ // While rare, it's possible for code to fail repeatedly during the lifetime of the same page
5539
+ // In those cases, we only want to log the failure once and not spam logs with redundant information.
5540
+ if (code in history$1 && history$1[code].indexOf(key) >= 0) {
5541
+ return;
5531
5542
  }
5532
- return e;
5543
+ data$1 = { code: code, name: name, message: message, stack: stack, severity: severity };
5544
+ // Maintain history of errors in memory to avoid sending redundant information
5545
+ if (code in history$1) {
5546
+ history$1[code].push(key);
5547
+ }
5548
+ else {
5549
+ history$1[code] = [key];
5550
+ }
5551
+ encode$1(33 /* Event.Log */);
5552
+ }
5553
+ function stop$7() {
5554
+ history$1 = {};
5533
5555
  }
5534
5556
 
5535
- // biome-ignore lint/complexity/noBannedTypes: specifically looking to instrument function calls
5536
- function measure (method) {
5537
- return function () {
5538
- var args = [];
5539
- for (var _i = 0; _i < arguments.length; _i++) {
5540
- args[_i] = arguments[_i];
5541
- }
5542
- var start = performance.now();
5543
- try {
5544
- method.apply(this, args);
5545
- }
5546
- catch (ex) {
5547
- throw report(ex);
5548
- }
5549
- var duration = performance.now() - start;
5550
- sum(4 /* Metric.TotalCost */, duration);
5551
- if (duration > 30 /* Setting.LongTask */) {
5552
- count$1(7 /* Metric.LongTaskCount */);
5553
- max(6 /* Metric.ThreadBlockedTime */, duration);
5554
- log$1(9 /* Code.FunctionExecutionTime */, 0 /* Severity.Info */, "".concat(method.dn || method.name, "-").concat(duration));
5555
- }
5556
- };
5557
+ function api(method) {
5558
+ // Zone.js, a popular package for Angular, overrides native browser APIs which can lead to inconsistent state for single page applications.
5559
+ // Example issue: https://github.com/angular/angular/issues/31712
5560
+ // As a work around, we ensuring Clarity access APIs outside of Zone (and use native implementation instead)
5561
+ var isZone = window["Zone" /* Constant.Zone */] && "__symbol__" /* Constant.Symbol */ in window["Zone" /* Constant.Zone */];
5562
+ if (isZone) {
5563
+ log(11 /* Code.AngularZone */, 0 /* Severity.Info */);
5564
+ return window["Zone" /* Constant.Zone */]["__symbol__" /* Constant.Symbol */](method);
5565
+ }
5566
+ return method;
5557
5567
  }
5558
5568
 
5559
5569
  var bindings = new Map();
@@ -5647,7 +5657,7 @@ function start$6() {
5647
5657
  }
5648
5658
  function check$1() {
5649
5659
  if (count++ > 20 /* Setting.CallStackDepth */) {
5650
- log$1(4 /* Code.CallStackDepth */, 0 /* Severity.Info */);
5660
+ log(4 /* Code.CallStackDepth */, 0 /* Severity.Info */);
5651
5661
  return false;
5652
5662
  }
5653
5663
  return true;
@@ -5677,7 +5687,7 @@ var status = false;
5677
5687
  function start$5() {
5678
5688
  status = true;
5679
5689
  start$I();
5680
- reset$o();
5690
+ reset$n();
5681
5691
  reset$1();
5682
5692
  reset$2();
5683
5693
  start$6();
@@ -5686,7 +5696,7 @@ function stop$5() {
5686
5696
  stop$6();
5687
5697
  reset$2();
5688
5698
  reset$1();
5689
- reset$o();
5699
+ reset$n();
5690
5700
  stop$F();
5691
5701
  status = false;
5692
5702
  }
@@ -5751,12 +5761,12 @@ function restart() {
5751
5761
 
5752
5762
  function start$4() {
5753
5763
  start$4.dn = 3 /* FunctionNames.DiagnosticStart */;
5754
- start$C();
5755
- start$d();
5756
- start$c();
5764
+ start$B();
5765
+ start$8();
5766
+ start$7();
5757
5767
  }
5758
5768
  function stop$4() {
5759
- stop$c();
5769
+ stop$7();
5760
5770
  }
5761
5771
 
5762
5772
  var diagnostic = /*#__PURE__*/Object.freeze({
@@ -5769,29 +5779,29 @@ function start$3() {
5769
5779
  start$3.dn = 20 /* FunctionNames.LayoutStart */;
5770
5780
  // The order below is important
5771
5781
  // and is determined by interdependencies of modules
5772
- start$y();
5773
- start$A();
5774
- start$k();
5782
+ start$x();
5783
+ start$z();
5784
+ start$j();
5775
5785
  if (config$2.delayDom) {
5776
5786
  // Lazy load layout module as part of page load time performance improvements experiment
5777
5787
  bind(window, 'load', function () {
5778
- start$x();
5788
+ start$w();
5779
5789
  });
5780
5790
  }
5781
5791
  else {
5782
- start$x();
5792
+ start$w();
5783
5793
  }
5784
- start$i();
5785
- start$z();
5786
- start$B();
5794
+ start$h();
5795
+ start$y();
5796
+ start$A();
5787
5797
  }
5788
5798
  function stop$3() {
5789
- stop$y();
5790
- stop$i();
5799
+ stop$x();
5800
+ stop$h();
5801
+ stop$u();
5791
5802
  stop$v();
5792
5803
  stop$w();
5793
- stop$x();
5794
- stop$z();
5804
+ stop$y();
5795
5805
  }
5796
5806
 
5797
5807
  var layout = /*#__PURE__*/Object.freeze({
@@ -5967,7 +5977,7 @@ function start$2() {
5967
5977
  // Capture connection properties, if available
5968
5978
  if (navigator && "connection" in navigator) {
5969
5979
  // biome-ignore lint/complexity/useLiteralKeys: connection isn't on every browser, so effectiveType gives unncessary typescript error
5970
- log(27 /* Dimension.ConnectionType */, navigator.connection["effectiveType"]);
5980
+ log$1(27 /* Dimension.ConnectionType */, navigator.connection["effectiveType"]);
5971
5981
  }
5972
5982
  // Check the browser support performance observer as a pre-requisite for any performance measurement
5973
5983
  if (window.PerformanceObserver && PerformanceObserver.supportedEntryTypes) {
@@ -5982,7 +5992,7 @@ function start$2() {
5982
5992
  }
5983
5993
  }
5984
5994
  else {
5985
- log$1(3 /* Code.PerformanceObserver */, 0 /* Severity.Info */);
5995
+ log(3 /* Code.PerformanceObserver */, 0 /* Severity.Info */);
5986
5996
  }
5987
5997
  }
5988
5998
  function observe() {
@@ -6011,7 +6021,7 @@ function observe() {
6011
6021
  }
6012
6022
  }
6013
6023
  catch (_a) {
6014
- log$1(3 /* Code.PerformanceObserver */, 1 /* Severity.Warning */);
6024
+ log(3 /* Code.PerformanceObserver */, 1 /* Severity.Warning */);
6015
6025
  }
6016
6026
  }
6017
6027
  function handle(entries) {
@@ -6028,7 +6038,7 @@ function process$1(entries) {
6028
6038
  break;
6029
6039
  case "resource" /* Constant.Resource */: {
6030
6040
  var name_1 = entry.name;
6031
- log(4 /* Dimension.NetworkHosts */, host(name_1));
6041
+ log$1(4 /* Dimension.NetworkHosts */, host(name_1));
6032
6042
  if (name_1 === config$2.upload || name_1 === config$2.fallback) {
6033
6043
  max(28 /* Metric.UploadTime */, entry.duration);
6034
6044
  }
@@ -6048,7 +6058,7 @@ function process$1(entries) {
6048
6058
  if (visible && "PerformanceEventTiming" in window && "interactionId" in PerformanceEventTiming.prototype) {
6049
6059
  processInteractionEntry(entry);
6050
6060
  // Logging it as dimension because we're always looking for the last value.
6051
- log(37 /* Dimension.InteractionNextPaint */, estimateP98LongestInteraction().toString());
6061
+ log$1(37 /* Dimension.InteractionNextPaint */, estimateP98LongestInteraction().toString());
6052
6062
  }
6053
6063
  break;
6054
6064
  case "layout-shift" /* Constant.CLS */:
@@ -6149,7 +6159,7 @@ function start(config$1) {
6149
6159
  if (check()) {
6150
6160
  config(config$1);
6151
6161
  start$5();
6152
- start$f();
6162
+ start$a();
6153
6163
  for (var _i = 0, modules_1 = modules; _i < modules_1.length; _i++) {
6154
6164
  var x = modules_1[_i];
6155
6165
  measure(x.start)();
@@ -6186,7 +6196,7 @@ function stop() {
6186
6196
  var x = _a[_i];
6187
6197
  measure(x.stop)();
6188
6198
  }
6189
- stop$e();
6199
+ stop$9();
6190
6200
  stop$5();
6191
6201
  setup();
6192
6202
  }