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