@uniformdev/context 19.79.0 → 19.79.1-alpha.7

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/dist/index.js CHANGED
@@ -80,6 +80,7 @@ __export(src_exports, {
80
80
  enableConsoleLogDrain: () => enableConsoleLogDrain,
81
81
  enableContextDevTools: () => enableContextDevTools,
82
82
  enableDebugConsoleLogDrain: () => enableDebugConsoleLogDrain,
83
+ enableUniformInsights: () => enableUniformInsights,
83
84
  evaluateVariantMatch: () => evaluateVariantMatch,
84
85
  eventEvaluator: () => eventEvaluator,
85
86
  explainStringMatch: () => explainStringMatch,
@@ -146,119 +147,73 @@ function computeAggregateDimension(primitiveScores, aggregateDimension, allAggre
146
147
  // src/manifest/constants.ts
147
148
  var ENR_SEPARATOR = "_";
148
149
 
149
- // src/manifest/signals/SignalInstance.ts
150
- var _evaluator, _onLogMessage;
151
- var SignalInstance = class {
152
- constructor(data, evaluator, onLogMessage) {
153
- __privateAdd(this, _evaluator, void 0);
154
- __privateAdd(this, _onLogMessage, void 0);
155
- __publicField(this, "signal");
156
- this.signal = data;
157
- __privateSet(this, _evaluator, evaluator);
158
- __privateSet(this, _onLogMessage, onLogMessage);
159
- }
160
- /** Computes storage update commands to take based on a state update and the signal's criteria */
161
- computeSignal(update, commands) {
162
- const isAtCap = update.scores[this.signal.id] >= this.signal.cap;
163
- if (isAtCap && this.signal.dur !== "t") {
164
- return;
165
- }
166
- const criteriaMatchUpdate = __privateGet(this, _evaluator).evaluate(
167
- update,
168
- this.signal.crit,
169
- commands,
170
- this.signal,
171
- __privateGet(this, _onLogMessage)
172
- );
173
- const scoreCommand = this.signal.dur === "s" || this.signal.dur === "t" ? "modscoreS" : "modscore";
174
- if (!criteriaMatchUpdate.changed) {
175
- return;
176
- }
177
- if (criteriaMatchUpdate.result) {
178
- commands.push({
179
- type: scoreCommand,
180
- data: { dimension: this.signal.id, delta: this.signal.str }
181
- });
182
- } else if (this.signal.dur === "t") {
183
- const sessionScore = update.visitor.sessionScores[this.signal.id];
184
- if (sessionScore) {
185
- commands.push({
186
- type: scoreCommand,
187
- data: { dimension: this.signal.id, delta: -sessionScore }
188
- });
189
- }
190
- }
191
- }
192
- };
193
- _evaluator = new WeakMap();
194
- _onLogMessage = new WeakMap();
195
-
196
- // src/manifest/ManifestInstance.ts
197
- var _mf, _signalInstances, _onLogMessage2;
198
- var ManifestInstance = class {
199
- constructor({
200
- manifest,
201
- evaluator = new GroupCriteriaEvaluator({}),
202
- // eslint-disable-next-line @typescript-eslint/no-empty-function
203
- onLogMessage = () => {
204
- }
205
- }) {
206
- __publicField(this, "data");
207
- __privateAdd(this, _mf, void 0);
208
- __privateAdd(this, _signalInstances, void 0);
209
- __privateAdd(this, _onLogMessage2, void 0);
210
- var _a, _b, _c;
211
- __privateSet(this, _mf, (_a = manifest.project) != null ? _a : {});
212
- this.data = manifest;
213
- __privateSet(this, _signalInstances, Object.entries((_c = (_b = __privateGet(this, _mf).pz) == null ? void 0 : _b.sig) != null ? _c : []).map(
214
- ([id, signal]) => new SignalInstance({ ...signal, id }, evaluator, onLogMessage)
215
- ));
216
- __privateSet(this, _onLogMessage2, onLogMessage);
217
- }
218
- rollForControlGroup() {
219
- var _a, _b;
220
- return Math.random() < ((_b = (_a = __privateGet(this, _mf).pz) == null ? void 0 : _a.control) != null ? _b : 0);
221
- }
222
- getTest(name) {
223
- var _a;
224
- return (_a = __privateGet(this, _mf).test) == null ? void 0 : _a[name];
150
+ // src/manifest/signals/criteria/util/isNumberMatch.ts
151
+ function isNumberMatch(lhs, match) {
152
+ var _a;
153
+ if (typeof lhs === "undefined" || lhs === null) {
154
+ return false;
225
155
  }
226
- computeSignals(update) {
227
- const commands = [];
228
- __privateGet(this, _onLogMessage2).call(this, ["debug", 200, "GROUP"]);
229
- try {
230
- __privateGet(this, _signalInstances).forEach((signal) => {
231
- __privateGet(this, _onLogMessage2).call(this, ["debug", 201, "GROUP", signal.signal]);
232
- try {
233
- signal.computeSignal(update, commands);
234
- } finally {
235
- __privateGet(this, _onLogMessage2).call(this, ["debug", 201, "ENDGROUP"]);
236
- }
237
- });
238
- } finally {
239
- __privateGet(this, _onLogMessage2).call(this, ["debug", 200, "ENDGROUP"]);
240
- }
241
- return commands;
156
+ const lhsValue = Number(lhs);
157
+ if (isNaN(lhsValue)) {
158
+ return false;
242
159
  }
243
- /**
244
- * Computes aggregated scores based on other dimensions
245
- */
246
- computeAggregateDimensions(primitiveScores) {
247
- var _a, _b;
248
- return computeAggregateDimensions(primitiveScores, (_b = (_a = __privateGet(this, _mf).pz) == null ? void 0 : _a.agg) != null ? _b : {});
160
+ switch ((_a = match == null ? void 0 : match.op) != null ? _a : "=") {
161
+ case "=":
162
+ return lhsValue === match.rhs;
163
+ case "!=":
164
+ return lhsValue !== match.rhs;
165
+ case ">":
166
+ return lhsValue > match.rhs;
167
+ case "<":
168
+ return lhsValue < match.rhs;
169
+ default:
170
+ console.warn(`Unknown match type ${match.op} is false.`);
171
+ return false;
249
172
  }
250
- getDimensionByKey(scoreKey) {
251
- var _a, _b, _c, _d;
252
- const enrichmentIndex = scoreKey.indexOf(ENR_SEPARATOR);
253
- if (enrichmentIndex <= 0) {
254
- return (_b = (_a = __privateGet(this, _mf).pz) == null ? void 0 : _a.sig) == null ? void 0 : _b[scoreKey];
173
+ }
174
+ function explainNumberMatch(lhs, match) {
175
+ return `${lhs} ${explainNumberMatchCriteria(match)}`;
176
+ }
177
+ function explainNumberMatchCriteria(match) {
178
+ return `${match.op} ${match.rhs}`;
179
+ }
180
+
181
+ // src/manifest/utils/getEnrichmentVectorKey.ts
182
+ function getEnrichmentVectorKey(category, value) {
183
+ return `${category}${ENR_SEPARATOR}${value}`;
184
+ }
185
+
186
+ // src/manifest/goals/evaluators/EnrichmentGoalEvaluator.ts
187
+ var _goal, _id;
188
+ var EnrichmentGoalEvaluator = class {
189
+ constructor(options) {
190
+ __privateAdd(this, _goal, void 0);
191
+ __privateAdd(this, _id, void 0);
192
+ __privateSet(this, _goal, options.goal);
193
+ __privateSet(this, _id, options.id);
194
+ }
195
+ get id() {
196
+ return __privateGet(this, _id);
197
+ }
198
+ evaluate({ scores }) {
199
+ const name = getEnrichmentVectorKey(__privateGet(this, _goal).cat, __privateGet(this, _goal).value);
200
+ const score = scores == null ? void 0 : scores[name];
201
+ if (typeof score !== "number") {
202
+ return {
203
+ triggered: false
204
+ };
255
205
  }
256
- return (_d = (_c = __privateGet(this, _mf).pz) == null ? void 0 : _c.enr) == null ? void 0 : _d[scoreKey.substring(0, enrichmentIndex)];
206
+ const isMatch = isNumberMatch(score, {
207
+ op: __privateGet(this, _goal).op,
208
+ rhs: __privateGet(this, _goal).score
209
+ });
210
+ return {
211
+ triggered: isMatch
212
+ };
257
213
  }
258
214
  };
259
- _mf = new WeakMap();
260
- _signalInstances = new WeakMap();
261
- _onLogMessage2 = new WeakMap();
215
+ _goal = new WeakMap();
216
+ _id = new WeakMap();
262
217
 
263
218
  // src/manifest/signals/criteria/evaluators/cookieEvaluator.ts
264
219
  var import_lite = require("dequal/lite");
@@ -377,42 +332,6 @@ var eventEvaluator = ({ update, criteria, onLogMessage }) => {
377
332
  return finalResult;
378
333
  };
379
334
 
380
- // src/manifest/utils/getEnrichmentVectorKey.ts
381
- function getEnrichmentVectorKey(category, value) {
382
- return `${category}${ENR_SEPARATOR}${value}`;
383
- }
384
-
385
- // src/manifest/signals/criteria/util/isNumberMatch.ts
386
- function isNumberMatch(lhs, match) {
387
- var _a;
388
- if (typeof lhs === "undefined" || lhs === null) {
389
- return false;
390
- }
391
- const lhsValue = Number(lhs);
392
- if (isNaN(lhsValue)) {
393
- return false;
394
- }
395
- switch ((_a = match == null ? void 0 : match.op) != null ? _a : "=") {
396
- case "=":
397
- return lhsValue === match.rhs;
398
- case "!=":
399
- return lhsValue !== match.rhs;
400
- case ">":
401
- return lhsValue > match.rhs;
402
- case "<":
403
- return lhsValue < match.rhs;
404
- default:
405
- console.warn(`Unknown match type ${match.op} is false.`);
406
- return false;
407
- }
408
- }
409
- function explainNumberMatch(lhs, match) {
410
- return `${lhs} ${explainNumberMatchCriteria(match)}`;
411
- }
412
- function explainNumberMatchCriteria(match) {
413
- return `${match.op} ${match.rhs}`;
414
- }
415
-
416
335
  // src/manifest/signals/criteria/evaluators/pageViewCountEvaluator.ts
417
336
  var pageViewCountDimension = getEnrichmentVectorKey("$pvc", "v");
418
337
  var pageViewCountEvaluator = ({ update, criteria, commands, onLogMessage }) => {
@@ -542,6 +461,232 @@ var GroupCriteriaEvaluator = class {
542
461
  };
543
462
  _evaluators = new WeakMap();
544
463
 
464
+ // src/manifest/goals/evaluators/QuirkGoalEvaluator.ts
465
+ var _goal2, _id2;
466
+ var QuirkGoalEvaluator = class {
467
+ constructor(options) {
468
+ __privateAdd(this, _goal2, void 0);
469
+ __privateAdd(this, _id2, void 0);
470
+ __privateSet(this, _goal2, options.goal);
471
+ __privateSet(this, _id2, options.id);
472
+ }
473
+ get id() {
474
+ return __privateGet(this, _id2);
475
+ }
476
+ evaluate({ quirks }) {
477
+ const quirkValue = quirks == null ? void 0 : quirks[__privateGet(this, _goal2).id];
478
+ if (typeof quirkValue !== "string") {
479
+ return {
480
+ triggered: false
481
+ };
482
+ }
483
+ const isMatch = isStringMatch(quirkValue, {
484
+ op: __privateGet(this, _goal2).op,
485
+ rhs: __privateGet(this, _goal2).value,
486
+ cs: __privateGet(this, _goal2).cs
487
+ });
488
+ return {
489
+ triggered: isMatch
490
+ };
491
+ }
492
+ };
493
+ _goal2 = new WeakMap();
494
+ _id2 = new WeakMap();
495
+
496
+ // src/manifest/goals/evaluators/SignalGoalEvaluator.ts
497
+ var _goal3, _id3;
498
+ var SignalGoalEvaluator = class {
499
+ constructor(options) {
500
+ __privateAdd(this, _goal3, void 0);
501
+ __privateAdd(this, _id3, void 0);
502
+ __privateSet(this, _id3, options.id);
503
+ __privateSet(this, _goal3, options.goal);
504
+ }
505
+ get id() {
506
+ return __privateGet(this, _id3);
507
+ }
508
+ evaluate({ scores }) {
509
+ const score = scores == null ? void 0 : scores[__privateGet(this, _goal3).id];
510
+ if (typeof score !== "number") {
511
+ return {
512
+ triggered: false
513
+ };
514
+ }
515
+ const isMatch = isNumberMatch(score, {
516
+ op: __privateGet(this, _goal3).op,
517
+ rhs: __privateGet(this, _goal3).score
518
+ });
519
+ return {
520
+ triggered: isMatch
521
+ };
522
+ }
523
+ };
524
+ _goal3 = new WeakMap();
525
+ _id3 = new WeakMap();
526
+
527
+ // src/manifest/goals/evaluators/index.ts
528
+ var resolveGoalEvaluator = ({ id, goal }) => {
529
+ let evaluator;
530
+ if (goal.type === "sig") {
531
+ evaluator = new SignalGoalEvaluator({
532
+ id,
533
+ goal
534
+ });
535
+ } else if (goal.type === "enr") {
536
+ evaluator = new EnrichmentGoalEvaluator({
537
+ id,
538
+ goal
539
+ });
540
+ } else if (goal.type === "qrk") {
541
+ evaluator = new QuirkGoalEvaluator({
542
+ id,
543
+ goal
544
+ });
545
+ }
546
+ return evaluator;
547
+ };
548
+
549
+ // src/manifest/signals/SignalInstance.ts
550
+ var _evaluator, _onLogMessage;
551
+ var SignalInstance = class {
552
+ constructor(data, evaluator, onLogMessage) {
553
+ __privateAdd(this, _evaluator, void 0);
554
+ __privateAdd(this, _onLogMessage, void 0);
555
+ __publicField(this, "signal");
556
+ this.signal = data;
557
+ __privateSet(this, _evaluator, evaluator);
558
+ __privateSet(this, _onLogMessage, onLogMessage);
559
+ }
560
+ /** Computes storage update commands to take based on a state update and the signal's criteria */
561
+ computeSignal(update, commands) {
562
+ const isAtCap = update.scores[this.signal.id] >= this.signal.cap;
563
+ if (isAtCap && this.signal.dur !== "t") {
564
+ return;
565
+ }
566
+ const criteriaMatchUpdate = __privateGet(this, _evaluator).evaluate(
567
+ update,
568
+ this.signal.crit,
569
+ commands,
570
+ this.signal,
571
+ __privateGet(this, _onLogMessage)
572
+ );
573
+ const scoreCommand = this.signal.dur === "s" || this.signal.dur === "t" ? "modscoreS" : "modscore";
574
+ if (!criteriaMatchUpdate.changed) {
575
+ return;
576
+ }
577
+ if (criteriaMatchUpdate.result) {
578
+ commands.push({
579
+ type: scoreCommand,
580
+ data: { dimension: this.signal.id, delta: this.signal.str }
581
+ });
582
+ } else if (this.signal.dur === "t") {
583
+ const sessionScore = update.visitor.sessionScores[this.signal.id];
584
+ if (sessionScore) {
585
+ commands.push({
586
+ type: scoreCommand,
587
+ data: { dimension: this.signal.id, delta: -sessionScore }
588
+ });
589
+ }
590
+ }
591
+ }
592
+ };
593
+ _evaluator = new WeakMap();
594
+ _onLogMessage = new WeakMap();
595
+
596
+ // src/manifest/ManifestInstance.ts
597
+ var _mf, _signalInstances, _goalEvaluators, _onLogMessage2;
598
+ var ManifestInstance = class {
599
+ constructor({
600
+ manifest,
601
+ evaluator = new GroupCriteriaEvaluator({}),
602
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
603
+ onLogMessage = () => {
604
+ }
605
+ }) {
606
+ __publicField(this, "data");
607
+ __privateAdd(this, _mf, void 0);
608
+ __privateAdd(this, _signalInstances, void 0);
609
+ __privateAdd(this, _goalEvaluators, void 0);
610
+ __privateAdd(this, _onLogMessage2, void 0);
611
+ var _a, _b, _c, _d;
612
+ __privateSet(this, _mf, (_a = manifest.project) != null ? _a : {});
613
+ this.data = manifest;
614
+ __privateSet(this, _signalInstances, Object.entries((_c = (_b = __privateGet(this, _mf).pz) == null ? void 0 : _b.sig) != null ? _c : []).map(
615
+ ([id, signal]) => new SignalInstance({ ...signal, id }, evaluator, onLogMessage)
616
+ ));
617
+ __privateSet(this, _goalEvaluators, Object.entries((_d = __privateGet(this, _mf).goal) != null ? _d : {}).map(([id, goal]) => {
618
+ const evaluator2 = resolveGoalEvaluator({
619
+ id,
620
+ goal
621
+ });
622
+ if (!evaluator2) {
623
+ console.warn(`Unable to resolve goal evaluator for goal ${id}`);
624
+ }
625
+ return evaluator2;
626
+ }).filter((evaluator2) => !!evaluator2));
627
+ __privateSet(this, _onLogMessage2, onLogMessage);
628
+ }
629
+ rollForControlGroup() {
630
+ var _a, _b;
631
+ return Math.random() < ((_b = (_a = __privateGet(this, _mf).pz) == null ? void 0 : _a.control) != null ? _b : 0);
632
+ }
633
+ getTest(name) {
634
+ var _a;
635
+ return (_a = __privateGet(this, _mf).test) == null ? void 0 : _a[name];
636
+ }
637
+ computeSignals(update) {
638
+ const commands = [];
639
+ __privateGet(this, _onLogMessage2).call(this, ["debug", 200, "GROUP"]);
640
+ try {
641
+ __privateGet(this, _signalInstances).forEach((signal) => {
642
+ __privateGet(this, _onLogMessage2).call(this, ["debug", 201, "GROUP", signal.signal]);
643
+ try {
644
+ signal.computeSignal(update, commands);
645
+ } finally {
646
+ __privateGet(this, _onLogMessage2).call(this, ["debug", 201, "ENDGROUP"]);
647
+ }
648
+ });
649
+ } finally {
650
+ __privateGet(this, _onLogMessage2).call(this, ["debug", 200, "ENDGROUP"]);
651
+ }
652
+ return commands;
653
+ }
654
+ computeGoals(data) {
655
+ const commands = [];
656
+ __privateGet(this, _goalEvaluators).forEach((evaluator) => {
657
+ const { triggered } = evaluator.evaluate(data);
658
+ if (triggered) {
659
+ commands.push({
660
+ type: "setgoal",
661
+ data: {
662
+ goal: evaluator.id
663
+ }
664
+ });
665
+ }
666
+ });
667
+ return commands;
668
+ }
669
+ /**
670
+ * Computes aggregated scores based on other dimensions
671
+ */
672
+ computeAggregateDimensions(primitiveScores) {
673
+ var _a, _b;
674
+ return computeAggregateDimensions(primitiveScores, (_b = (_a = __privateGet(this, _mf).pz) == null ? void 0 : _a.agg) != null ? _b : {});
675
+ }
676
+ getDimensionByKey(scoreKey) {
677
+ var _a, _b, _c, _d;
678
+ const enrichmentIndex = scoreKey.indexOf(ENR_SEPARATOR);
679
+ if (enrichmentIndex <= 0) {
680
+ return (_b = (_a = __privateGet(this, _mf).pz) == null ? void 0 : _a.sig) == null ? void 0 : _b[scoreKey];
681
+ }
682
+ return (_d = (_c = __privateGet(this, _mf).pz) == null ? void 0 : _c.enr) == null ? void 0 : _d[scoreKey.substring(0, enrichmentIndex)];
683
+ }
684
+ };
685
+ _mf = new WeakMap();
686
+ _signalInstances = new WeakMap();
687
+ _goalEvaluators = new WeakMap();
688
+ _onLogMessage2 = new WeakMap();
689
+
545
690
  // src/placement/criteria/evaluateVariantMatch.ts
546
691
  function evaluateVariantMatch(variantId, match, vec, onLogMessage) {
547
692
  onLogMessage == null ? void 0 : onLogMessage(["info", 301, "GROUP", { id: variantId, op: match == null ? void 0 : match.op }]);
@@ -1045,6 +1190,7 @@ var emptyVisitorData = () => ({
1045
1190
  scores: {},
1046
1191
  sessionScores: {},
1047
1192
  tests: {},
1193
+ goals: {},
1048
1194
  consent: false,
1049
1195
  controlGroup: false
1050
1196
  });
@@ -1059,7 +1205,7 @@ var clone = (0, import_rfdc.default)();
1059
1205
  function applyCommandsToData(commands, state, inControlGroup) {
1060
1206
  const newData = state ? clone(state) : emptyVisitorData();
1061
1207
  commands.forEach((command) => {
1062
- var _a, _b;
1208
+ var _a, _b, _c;
1063
1209
  switch (command.type) {
1064
1210
  case "consent":
1065
1211
  newData.consent = command.data;
@@ -1095,6 +1241,10 @@ function applyCommandsToData(commands, state, inControlGroup) {
1095
1241
  case "setcontrol":
1096
1242
  newData.controlGroup = command.data;
1097
1243
  break;
1244
+ case "setgoal":
1245
+ newData.goals = (_c = newData.goals) != null ? _c : {};
1246
+ newData.goals[command.data.goal] = true;
1247
+ break;
1098
1248
  default:
1099
1249
  throw new Error(`Unknown command`);
1100
1250
  }
@@ -1260,7 +1410,7 @@ currentData_get = function() {
1260
1410
  };
1261
1411
  _replaceData = new WeakSet();
1262
1412
  replaceData_fn = function(data, quiet = false) {
1263
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1413
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1264
1414
  const oldData = __privateGet(this, _currentData, currentData_get);
1265
1415
  const now = Date.now();
1266
1416
  if (data.controlGroup) {
@@ -1281,6 +1431,7 @@ replaceData_fn = function(data, quiet = false) {
1281
1431
  const haveSessionScoresChanged = !(0, import_lite3.dequal)(oldData == null ? void 0 : oldData.visitorData.sessionScores, data.sessionScores);
1282
1432
  const haveQuirksChanged = !(0, import_lite3.dequal)(oldData == null ? void 0 : oldData.visitorData.quirks, data.quirks);
1283
1433
  const haveTestsChanged = !(0, import_lite3.dequal)(oldData == null ? void 0 : oldData.visitorData.tests, data.tests);
1434
+ const haveGoalsChanged = !(0, import_lite3.dequal)(oldData == null ? void 0 : oldData.visitorData.goals, data.goals);
1284
1435
  const updatedData = {
1285
1436
  updated: now,
1286
1437
  visitorData: data
@@ -1305,6 +1456,15 @@ replaceData_fn = function(data, quiet = false) {
1305
1456
  __privateGet(this, _mitt2).emit("controlGroupUpdated", data);
1306
1457
  (_i = (_h = __privateGet(this, _options)).onLogMessage) == null ? void 0 : _i.call(_h, ["debug", 104, (_g = data.controlGroup) != null ? _g : false]);
1307
1458
  }
1459
+ if (haveGoalsChanged) {
1460
+ const newGoalKeys = Object.keys((_j = data.goals) != null ? _j : {});
1461
+ for (let i = 0; i < newGoalKeys.length; i++) {
1462
+ const key = newGoalKeys[i];
1463
+ if (!((_k = oldData == null ? void 0 : oldData.visitorData.goals) == null ? void 0 : _k[key])) {
1464
+ __privateGet(this, _mitt2).emit("goalConverted", { goalId: key });
1465
+ }
1466
+ }
1467
+ }
1308
1468
  }
1309
1469
  };
1310
1470
  _setVisitTimeout = new WeakSet();
@@ -1357,10 +1517,10 @@ var import_lite4 = require("dequal/lite");
1357
1517
  var import_mitt3 = __toESM(require("mitt"));
1358
1518
  var CONTEXTUAL_EDITING_TEST_NAME = "contextual_editing_test";
1359
1519
  var CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID = "contextual_editing_test_selected_variant";
1360
- var _serverTransitionState, _scores, _state, _pzCache, _mitt3, _emitTest, emitTest_fn, _updateComputedScores, updateComputedScores_fn, _calculateScores, calculateScores_fn;
1520
+ var _serverTransitionState, _scores, _state, _pzCache, _plugins, _mitt3, _updateGoals, updateGoals_fn, _updateComputedScores, updateComputedScores_fn, _calculateScores, calculateScores_fn;
1361
1521
  var Context = class {
1362
1522
  constructor(options) {
1363
- __privateAdd(this, _emitTest);
1523
+ __privateAdd(this, _updateGoals);
1364
1524
  __privateAdd(this, _updateComputedScores);
1365
1525
  __privateAdd(this, _calculateScores);
1366
1526
  __publicField(this, "manifest");
@@ -1368,6 +1528,7 @@ var Context = class {
1368
1528
  __privateAdd(this, _scores, {});
1369
1529
  __privateAdd(this, _state, void 0);
1370
1530
  __privateAdd(this, _pzCache, {});
1531
+ __privateAdd(this, _plugins, void 0);
1371
1532
  __privateAdd(this, _mitt3, (0, import_mitt3.default)());
1372
1533
  /**
1373
1534
  * Subscribe to events
@@ -1380,7 +1541,8 @@ var Context = class {
1380
1541
  var _a, _b;
1381
1542
  const { manifest, ...storageOptions } = options;
1382
1543
  __privateSet(this, _state, {});
1383
- (_a = options.plugins) == null ? void 0 : _a.forEach((plugin) => {
1544
+ __privateSet(this, _plugins, options.plugins);
1545
+ (_a = __privateGet(this, _plugins)) == null ? void 0 : _a.forEach((plugin) => {
1384
1546
  if (!plugin.logDrain) {
1385
1547
  return;
1386
1548
  }
@@ -1390,7 +1552,19 @@ var Context = class {
1390
1552
  try {
1391
1553
  this.manifest = new ManifestInstance({
1392
1554
  onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message),
1393
- manifest,
1555
+ manifest: {
1556
+ project: {
1557
+ ...manifest.project,
1558
+ goal: {
1559
+ is_developer: {
1560
+ type: "sig",
1561
+ id: "1_dev",
1562
+ op: ">",
1563
+ score: 0
1564
+ }
1565
+ }
1566
+ }
1567
+ },
1394
1568
  evaluator: new GroupCriteriaEvaluator({
1395
1569
  CK: cookieEvaluator,
1396
1570
  QS: queryStringEvaluator,
@@ -1423,11 +1597,15 @@ var Context = class {
1423
1597
  previousState: __privateGet(this, _state),
1424
1598
  visitor: this.storage.data
1425
1599
  });
1600
+ __privateMethod(this, _updateGoals, updateGoals_fn).call(this, {
1601
+ quirks: quirks.quirks,
1602
+ scores: void 0
1603
+ });
1426
1604
  this.storage.updateData(updates);
1427
1605
  __privateGet(this, _mitt3).emit("quirksUpdated", quirks.quirks);
1428
1606
  __privateGet(this, _mitt3).emit("log", ["info", 4, quirks.quirks]);
1429
1607
  });
1430
- (_b = options.plugins) == null ? void 0 : _b.forEach((plugin) => {
1608
+ (_b = __privateGet(this, _plugins)) == null ? void 0 : _b.forEach((plugin) => {
1431
1609
  if (!plugin.init) {
1432
1610
  return;
1433
1611
  }
@@ -1437,6 +1615,13 @@ var Context = class {
1437
1615
  __privateGet(this, _mitt3).emit("log", ["info", 1, "ENDGROUP"]);
1438
1616
  }
1439
1617
  }
1618
+ internal_emitPersonalizationResult(event) {
1619
+ __privateGet(this, _mitt3).emit("personalizationResult", event);
1620
+ __privateGet(this, _pzCache)[event.name] = event.variantIds;
1621
+ }
1622
+ internal_emitTestResult(event) {
1623
+ __privateGet(this, _mitt3).emit("testResult", event);
1624
+ }
1440
1625
  /** Gets the current visitor's dimension score vector. */
1441
1626
  get scores() {
1442
1627
  return __privateGet(this, _scores);
@@ -1542,7 +1727,7 @@ var Context = class {
1542
1727
  if (__privateGet(this, _serverTransitionState)) {
1543
1728
  __privateMethod(this, _updateComputedScores, updateComputedScores_fn).call(this, this.storage.data);
1544
1729
  Object.entries(newServerSideTests).forEach(([testName, testVariantId]) => {
1545
- __privateMethod(this, _emitTest, emitTest_fn).call(this, {
1730
+ this.internal_emitTestResult({
1546
1731
  name: testName,
1547
1732
  variantId: testVariantId,
1548
1733
  variantAssigned: true
@@ -1551,6 +1736,15 @@ var Context = class {
1551
1736
  __privateSet(this, _serverTransitionState, void 0);
1552
1737
  __privateGet(this, _mitt3).emit("log", ["debug", 131]);
1553
1738
  }
1739
+ if (__privateGet(this, _plugins)) {
1740
+ for (let i = 0; i < __privateGet(this, _plugins).length; i++) {
1741
+ const plugin = __privateGet(this, _plugins)[i];
1742
+ if (!plugin.update) {
1743
+ continue;
1744
+ }
1745
+ await plugin.update(newData);
1746
+ }
1747
+ }
1554
1748
  } finally {
1555
1749
  __privateGet(this, _mitt3).emit("log", ["info", 2, "ENDGROUP"]);
1556
1750
  }
@@ -1602,7 +1796,7 @@ var Context = class {
1602
1796
  context: this,
1603
1797
  onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message)
1604
1798
  });
1605
- __privateMethod(this, _emitTest, emitTest_fn).call(this, {
1799
+ this.internal_emitTestResult({
1606
1800
  name: options.name,
1607
1801
  variantId: (_c = (_b = value.result) == null ? void 0 : _b.id) != null ? _c : void 0,
1608
1802
  variantAssigned: value.variantAssigned
@@ -1629,8 +1823,7 @@ var Context = class {
1629
1823
  if (previousPlacement && (0, import_lite4.dequal)(eventData.variantIds, previousPlacement)) {
1630
1824
  eventData.changed = false;
1631
1825
  }
1632
- __privateGet(this, _mitt3).emit("personalizationResult", eventData);
1633
- __privateGet(this, _pzCache)[options.name] = eventData.variantIds;
1826
+ this.internal_emitPersonalizationResult(eventData);
1634
1827
  return value;
1635
1828
  }
1636
1829
  /**
@@ -1639,6 +1832,15 @@ var Context = class {
1639
1832
  */
1640
1833
  async forget(fromAllDevices) {
1641
1834
  __privateSet(this, _state, {});
1835
+ if (__privateGet(this, _plugins)) {
1836
+ for (let i = 0; i < __privateGet(this, _plugins).length; i++) {
1837
+ const plugin = __privateGet(this, _plugins)[i];
1838
+ if (!plugin.forget) {
1839
+ continue;
1840
+ }
1841
+ await plugin.forget();
1842
+ }
1843
+ }
1642
1844
  await this.storage.delete(fromAllDevices);
1643
1845
  }
1644
1846
  /**
@@ -1666,10 +1868,14 @@ _serverTransitionState = new WeakMap();
1666
1868
  _scores = new WeakMap();
1667
1869
  _state = new WeakMap();
1668
1870
  _pzCache = new WeakMap();
1871
+ _plugins = new WeakMap();
1669
1872
  _mitt3 = new WeakMap();
1670
- _emitTest = new WeakSet();
1671
- emitTest_fn = function(event) {
1672
- __privateGet(this, _mitt3).emit("testResult", event);
1873
+ _updateGoals = new WeakSet();
1874
+ updateGoals_fn = async function(data) {
1875
+ const goalCommands = this.manifest.computeGoals(data);
1876
+ if (goalCommands.length !== 0) {
1877
+ await this.storage.updateData(goalCommands);
1878
+ }
1673
1879
  };
1674
1880
  _updateComputedScores = new WeakSet();
1675
1881
  updateComputedScores_fn = function(newData) {
@@ -1677,6 +1883,10 @@ updateComputedScores_fn = function(newData) {
1677
1883
  const newScoresHaveChanged = !(0, import_lite4.dequal)(newScores, __privateGet(this, _scores));
1678
1884
  if (newScoresHaveChanged) {
1679
1885
  __privateSet(this, _scores, newScores);
1886
+ __privateMethod(this, _updateGoals, updateGoals_fn).call(this, {
1887
+ scores: __privateGet(this, _scores),
1888
+ quirks: void 0
1889
+ });
1680
1890
  __privateGet(this, _mitt3).emit("scoresUpdated", newScores);
1681
1891
  __privateGet(this, _mitt3).emit("log", ["info", 3, newScores]);
1682
1892
  }
@@ -1817,6 +2027,721 @@ var ScriptType = /* @__PURE__ */ ((ScriptType2) => {
1817
2027
  })(ScriptType || {});
1818
2028
  var EdgeNodeTagName = "nesitag";
1819
2029
 
2030
+ // src/insights/index.ts
2031
+ var import_nanoid = require("nanoid");
2032
+
2033
+ // src/insights/constants.ts
2034
+ var TIMEZONE_MAP = {
2035
+ "Asia/Barnaul": "RU",
2036
+ "Africa/Nouakchott": "MR",
2037
+ "Africa/Lusaka": "ZM",
2038
+ "Asia/Pyongyang": "KP",
2039
+ "Europe/Bratislava": "SK",
2040
+ "America/Belize": "BZ",
2041
+ "America/Maceio": "BR",
2042
+ "Pacific/Chuuk": "FM",
2043
+ "Indian/Comoro": "KM",
2044
+ "Pacific/Palau": "PW",
2045
+ "Asia/Jakarta": "ID",
2046
+ "Africa/Windhoek": "NA",
2047
+ "America/Chihuahua": "MX",
2048
+ "America/Nome": "US",
2049
+ "Africa/Mbabane": "SZ",
2050
+ "Africa/Porto-Novo": "BJ",
2051
+ "Europe/San_Marino": "SM",
2052
+ "Pacific/Fakaofo": "TK",
2053
+ "America/Denver": "US",
2054
+ "Europe/Belgrade": "RS",
2055
+ "America/Indiana/Tell_City": "US",
2056
+ "America/Fortaleza": "BR",
2057
+ "America/Halifax": "CA",
2058
+ "Europe/Bucharest": "RO",
2059
+ "America/Indiana/Petersburg": "US",
2060
+ "Europe/Kirov": "RU",
2061
+ "Europe/Athens": "GR",
2062
+ "America/Argentina/Ushuaia": "AR",
2063
+ "Europe/Monaco": "MC",
2064
+ "Europe/Vilnius": "LT",
2065
+ "Europe/Copenhagen": "DK",
2066
+ "Pacific/Kanton": "KI",
2067
+ "America/Caracas": "VE",
2068
+ "Asia/Almaty": "KZ",
2069
+ "Europe/Paris": "FR",
2070
+ "Africa/Blantyre": "MW",
2071
+ "Asia/Muscat": "OM",
2072
+ "America/North_Dakota/Beulah": "US",
2073
+ "America/Matamoros": "MX",
2074
+ "Asia/Irkutsk": "RU",
2075
+ "America/Costa_Rica": "CR",
2076
+ "America/Araguaina": "BR",
2077
+ "Atlantic/Canary": "ES",
2078
+ "America/Santo_Domingo": "DO",
2079
+ "America/Vancouver": "CA",
2080
+ "Africa/Addis_Ababa": "ET",
2081
+ "Africa/Accra": "GH",
2082
+ "Pacific/Kwajalein": "MH",
2083
+ "Asia/Baghdad": "IQ",
2084
+ "Australia/Adelaide": "AU",
2085
+ "Australia/Hobart": "AU",
2086
+ "America/Guayaquil": "EC",
2087
+ "America/Argentina/Tucuman": "AR",
2088
+ "Australia/Lindeman": "AU",
2089
+ "America/New_York": "US",
2090
+ "Pacific/Fiji": "FJ",
2091
+ "America/Antigua": "AG",
2092
+ "Africa/Casablanca": "MA",
2093
+ "America/Paramaribo": "SR",
2094
+ "Africa/Cairo": "EG",
2095
+ "America/Cayenne": "GF",
2096
+ "America/Detroit": "US",
2097
+ "Antarctica/Syowa": "AQ",
2098
+ "Africa/Douala": "CM",
2099
+ "America/Argentina/La_Rioja": "AR",
2100
+ "Africa/Lagos": "NG",
2101
+ "America/St_Barthelemy": "BL",
2102
+ "Asia/Nicosia": "CY",
2103
+ "Asia/Macau": "MO",
2104
+ "Europe/Riga": "LV",
2105
+ "Asia/Ashgabat": "TM",
2106
+ "Indian/Antananarivo": "MG",
2107
+ "America/Argentina/San_Juan": "AR",
2108
+ "Asia/Aden": "YE",
2109
+ "Asia/Tomsk": "RU",
2110
+ "America/Asuncion": "PY",
2111
+ "Pacific/Bougainville": "PG",
2112
+ "Asia/Vientiane": "LA",
2113
+ "America/Mazatlan": "MX",
2114
+ "Africa/Luanda": "AO",
2115
+ "Europe/Oslo": "NO",
2116
+ "Africa/Kinshasa": "CD",
2117
+ "Europe/Warsaw": "PL",
2118
+ "America/Grand_Turk": "TC",
2119
+ "Asia/Seoul": "KR",
2120
+ "Africa/Tripoli": "LY",
2121
+ "America/St_Thomas": "VI",
2122
+ "Asia/Kathmandu": "NP",
2123
+ "Pacific/Pitcairn": "PN",
2124
+ "Pacific/Nauru": "NR",
2125
+ "America/Curacao": "CW",
2126
+ "Asia/Kabul": "AF",
2127
+ "Pacific/Tongatapu": "TO",
2128
+ "Europe/Simferopol": "UA",
2129
+ "Asia/Ust-Nera": "RU",
2130
+ "Africa/Mogadishu": "SO",
2131
+ "Indian/Mayotte": "YT",
2132
+ "Pacific/Niue": "NU",
2133
+ "America/Thunder_Bay": "CA",
2134
+ "Atlantic/Azores": "PT",
2135
+ "Pacific/Gambier": "PF",
2136
+ "Europe/Stockholm": "SE",
2137
+ "Africa/Libreville": "GA",
2138
+ "America/Punta_Arenas": "CL",
2139
+ "America/Guatemala": "GT",
2140
+ "America/Noronha": "BR",
2141
+ "Europe/Helsinki": "FI",
2142
+ "Asia/Gaza": "PS",
2143
+ "Pacific/Kosrae": "FM",
2144
+ "America/Aruba": "AW",
2145
+ "America/Nassau": "BS",
2146
+ "Asia/Choibalsan": "MN",
2147
+ "America/Winnipeg": "CA",
2148
+ "America/Anguilla": "AI",
2149
+ "Asia/Thimphu": "BT",
2150
+ "Asia/Beirut": "LB",
2151
+ "Atlantic/Faroe": "FO",
2152
+ "Europe/Berlin": "DE",
2153
+ "Europe/Amsterdam": "NL",
2154
+ "Pacific/Honolulu": "US",
2155
+ "America/Regina": "CA",
2156
+ "America/Scoresbysund": "GL",
2157
+ "Europe/Vienna": "AT",
2158
+ "Europe/Tirane": "AL",
2159
+ "Africa/El_Aaiun": "EH",
2160
+ "America/Creston": "CA",
2161
+ "Asia/Qostanay": "KZ",
2162
+ "Asia/Ho_Chi_Minh": "VN",
2163
+ "Europe/Samara": "RU",
2164
+ "Europe/Rome": "IT",
2165
+ "Australia/Eucla": "AU",
2166
+ "America/El_Salvador": "SV",
2167
+ "America/Chicago": "US",
2168
+ "Africa/Abidjan": "CI",
2169
+ "Asia/Kamchatka": "RU",
2170
+ "Pacific/Tarawa": "KI",
2171
+ "America/Santiago": "CL",
2172
+ "America/Bahia": "BR",
2173
+ "Indian/Christmas": "CX",
2174
+ "Asia/Atyrau": "KZ",
2175
+ "Asia/Dushanbe": "TJ",
2176
+ "Europe/Ulyanovsk": "RU",
2177
+ "America/Yellowknife": "CA",
2178
+ "America/Recife": "BR",
2179
+ "Australia/Sydney": "AU",
2180
+ "America/Fort_Nelson": "CA",
2181
+ "Pacific/Efate": "VU",
2182
+ "Europe/Saratov": "RU",
2183
+ "Africa/Banjul": "GM",
2184
+ "Asia/Omsk": "RU",
2185
+ "Europe/Ljubljana": "SI",
2186
+ "Europe/Budapest": "HU",
2187
+ "Europe/Astrakhan": "RU",
2188
+ "America/Argentina/Buenos_Aires": "AR",
2189
+ "Pacific/Chatham": "NZ",
2190
+ "America/Argentina/Salta": "AR",
2191
+ "Africa/Niamey": "NE",
2192
+ "Asia/Pontianak": "ID",
2193
+ "Indian/Reunion": "RE",
2194
+ "Asia/Hong_Kong": "HK",
2195
+ "Antarctica/McMurdo": "AQ",
2196
+ "Africa/Malabo": "GQ",
2197
+ "America/Los_Angeles": "US",
2198
+ "America/Argentina/Cordoba": "AR",
2199
+ "Pacific/Pohnpei": "FM",
2200
+ "America/Tijuana": "MX",
2201
+ "America/Campo_Grande": "BR",
2202
+ "America/Dawson_Creek": "CA",
2203
+ "Asia/Novosibirsk": "RU",
2204
+ "Pacific/Pago_Pago": "AS",
2205
+ "Asia/Jerusalem": "IL",
2206
+ "Europe/Sarajevo": "BA",
2207
+ "Africa/Freetown": "SL",
2208
+ "Asia/Yekaterinburg": "RU",
2209
+ "America/Juneau": "US",
2210
+ "Africa/Ouagadougou": "BF",
2211
+ "Africa/Monrovia": "LR",
2212
+ "Europe/Kiev": "UA",
2213
+ "America/Argentina/San_Luis": "AR",
2214
+ "Asia/Tokyo": "JP",
2215
+ "Asia/Qatar": "QA",
2216
+ "America/La_Paz": "BO",
2217
+ "America/Bogota": "CO",
2218
+ "America/Thule": "GL",
2219
+ "Asia/Manila": "PH",
2220
+ "Asia/Hovd": "MN",
2221
+ "Asia/Tehran": "IR",
2222
+ "Atlantic/Madeira": "PT",
2223
+ "America/Metlakatla": "US",
2224
+ "Europe/Vatican": "VA",
2225
+ "Asia/Bishkek": "KG",
2226
+ "Asia/Dili": "TL",
2227
+ "Antarctica/Palmer": "AQ",
2228
+ "Atlantic/Cape_Verde": "CV",
2229
+ "Indian/Chagos": "IO",
2230
+ "America/Kentucky/Monticello": "US",
2231
+ "Africa/Algiers": "DZ",
2232
+ "Africa/Maseru": "LS",
2233
+ "Asia/Kuala_Lumpur": "MY",
2234
+ "Africa/Khartoum": "SD",
2235
+ "America/Argentina/Rio_Gallegos": "AR",
2236
+ "America/Blanc-Sablon": "CA",
2237
+ "Africa/Maputo": "MZ",
2238
+ "America/Tortola": "VG",
2239
+ "Atlantic/Bermuda": "BM",
2240
+ "America/Argentina/Catamarca": "AR",
2241
+ "America/Cayman": "KY",
2242
+ "America/Puerto_Rico": "PR",
2243
+ "Pacific/Majuro": "MH",
2244
+ "Europe/Busingen": "DE",
2245
+ "Pacific/Midway": "UM",
2246
+ "Indian/Cocos": "CC",
2247
+ "Asia/Singapore": "SG",
2248
+ "America/Boise": "US",
2249
+ "America/Nuuk": "GL",
2250
+ "America/Goose_Bay": "CA",
2251
+ "Australia/Broken_Hill": "AU",
2252
+ "Africa/Dar_es_Salaam": "TZ",
2253
+ "Africa/Asmara": "ER",
2254
+ "Asia/Samarkand": "UZ",
2255
+ "Asia/Tbilisi": "GE",
2256
+ "America/Argentina/Jujuy": "AR",
2257
+ "America/Indiana/Winamac": "US",
2258
+ "America/Porto_Velho": "BR",
2259
+ "Asia/Magadan": "RU",
2260
+ "Europe/Zaporozhye": "UA",
2261
+ "Antarctica/Casey": "AQ",
2262
+ "Asia/Shanghai": "CN",
2263
+ "Pacific/Norfolk": "NF",
2264
+ "Europe/Guernsey": "GG",
2265
+ "Australia/Brisbane": "AU",
2266
+ "Antarctica/DumontDUrville": "AQ",
2267
+ "America/Havana": "CU",
2268
+ "America/Atikokan": "CA",
2269
+ "America/Mexico_City": "MX",
2270
+ "America/Rankin_Inlet": "CA",
2271
+ "America/Cuiaba": "BR",
2272
+ "America/Resolute": "CA",
2273
+ "Africa/Ceuta": "ES",
2274
+ "Arctic/Longyearbyen": "SJ",
2275
+ "Pacific/Guam": "GU",
2276
+ "Asia/Damascus": "SY",
2277
+ "Asia/Colombo": "LK",
2278
+ "Asia/Yerevan": "AM",
2279
+ "America/Montserrat": "MS",
2280
+ "America/Belem": "BR",
2281
+ "Europe/Kaliningrad": "RU",
2282
+ "Atlantic/South_Georgia": "GS",
2283
+ "Asia/Tashkent": "UZ",
2284
+ "Asia/Kolkata": "IN",
2285
+ "America/St_Johns": "CA",
2286
+ "Asia/Srednekolymsk": "RU",
2287
+ "Asia/Yakutsk": "RU",
2288
+ "Europe/Prague": "CZ",
2289
+ "Africa/Djibouti": "DJ",
2290
+ "Asia/Dubai": "AE",
2291
+ "Europe/Uzhgorod": "UA",
2292
+ "America/Edmonton": "CA",
2293
+ "Asia/Famagusta": "CY",
2294
+ "America/Indiana/Knox": "US",
2295
+ "Asia/Hebron": "PS",
2296
+ "Asia/Taipei": "TW",
2297
+ "Europe/London": "GB",
2298
+ "Africa/Dakar": "SN",
2299
+ "Australia/Darwin": "AU",
2300
+ "America/Glace_Bay": "CA",
2301
+ "Antarctica/Vostok": "AQ",
2302
+ "America/Indiana/Vincennes": "US",
2303
+ "America/Nipigon": "CA",
2304
+ "Asia/Kuwait": "KW",
2305
+ "Pacific/Guadalcanal": "SB",
2306
+ "America/Toronto": "CA",
2307
+ "Africa/Gaborone": "BW",
2308
+ "Africa/Bujumbura": "BI",
2309
+ "Africa/Lubumbashi": "CD",
2310
+ "America/Merida": "MX",
2311
+ "America/Marigot": "MF",
2312
+ "Europe/Zagreb": "HR",
2313
+ "Pacific/Easter": "CL",
2314
+ "America/Santarem": "BR",
2315
+ "Pacific/Noumea": "NC",
2316
+ "America/Sitka": "US",
2317
+ "Atlantic/Stanley": "FK",
2318
+ "Pacific/Funafuti": "TV",
2319
+ "America/Iqaluit": "CA",
2320
+ "America/Rainy_River": "CA",
2321
+ "America/Anchorage": "US",
2322
+ "America/Lima": "PE",
2323
+ "Asia/Baku": "AZ",
2324
+ "America/Indiana/Vevay": "US",
2325
+ "Asia/Ulaanbaatar": "MN",
2326
+ "America/Managua": "NI",
2327
+ "Asia/Krasnoyarsk": "RU",
2328
+ "Asia/Qyzylorda": "KZ",
2329
+ "America/Eirunepe": "BR",
2330
+ "Europe/Podgorica": "ME",
2331
+ "Europe/Chisinau": "MD",
2332
+ "Europe/Mariehamn": "AX",
2333
+ "Europe/Volgograd": "RU",
2334
+ "Africa/Nairobi": "KE",
2335
+ "Europe/Isle_of_Man": "IM",
2336
+ "America/Menominee": "US",
2337
+ "Africa/Harare": "ZW",
2338
+ "Asia/Anadyr": "RU",
2339
+ "America/Moncton": "CA",
2340
+ "Indian/Maldives": "MV",
2341
+ "America/Whitehorse": "CA",
2342
+ "Antarctica/Mawson": "AQ",
2343
+ "Europe/Madrid": "ES",
2344
+ "America/Argentina/Mendoza": "AR",
2345
+ "America/Manaus": "BR",
2346
+ "Africa/Bangui": "CF",
2347
+ "Indian/Mauritius": "MU",
2348
+ "Africa/Tunis": "TN",
2349
+ "Australia/Lord_Howe": "AU",
2350
+ "America/Kentucky/Louisville": "US",
2351
+ "America/North_Dakota/Center": "US",
2352
+ "Asia/Novokuznetsk": "RU",
2353
+ "Asia/Makassar": "ID",
2354
+ "America/Port_of_Spain": "TT",
2355
+ "America/Bahia_Banderas": "MX",
2356
+ "Pacific/Auckland": "NZ",
2357
+ "America/Sao_Paulo": "BR",
2358
+ "Asia/Dhaka": "BD",
2359
+ "America/Pangnirtung": "CA",
2360
+ "Europe/Dublin": "IE",
2361
+ "Asia/Brunei": "BN",
2362
+ "Africa/Brazzaville": "CG",
2363
+ "America/Montevideo": "UY",
2364
+ "America/Jamaica": "JM",
2365
+ "America/Indiana/Indianapolis": "US",
2366
+ "America/Kralendijk": "BQ",
2367
+ "Europe/Gibraltar": "GI",
2368
+ "Pacific/Marquesas": "PF",
2369
+ "Pacific/Apia": "WS",
2370
+ "Europe/Jersey": "JE",
2371
+ "America/Phoenix": "US",
2372
+ "Africa/Ndjamena": "TD",
2373
+ "Asia/Karachi": "PK",
2374
+ "Africa/Kampala": "UG",
2375
+ "Asia/Sakhalin": "RU",
2376
+ "America/Martinique": "MQ",
2377
+ "Europe/Moscow": "RU",
2378
+ "Africa/Conakry": "GN",
2379
+ "America/Barbados": "BB",
2380
+ "Africa/Lome": "TG",
2381
+ "America/Ojinaga": "MX",
2382
+ "America/Tegucigalpa": "HN",
2383
+ "Asia/Bangkok": "TH",
2384
+ "Africa/Johannesburg": "ZA",
2385
+ "Europe/Vaduz": "LI",
2386
+ "Africa/Sao_Tome": "ST",
2387
+ "America/Cambridge_Bay": "CA",
2388
+ "America/Lower_Princes": "SX",
2389
+ "America/Miquelon": "PM",
2390
+ "America/St_Kitts": "KN",
2391
+ "Australia/Melbourne": "AU",
2392
+ "Europe/Minsk": "BY",
2393
+ "Asia/Vladivostok": "RU",
2394
+ "Europe/Sofia": "BG",
2395
+ "Antarctica/Davis": "AQ",
2396
+ "Pacific/Galapagos": "EC",
2397
+ "America/North_Dakota/New_Salem": "US",
2398
+ "Asia/Amman": "JO",
2399
+ "Pacific/Wallis": "WF",
2400
+ "America/Hermosillo": "MX",
2401
+ "Pacific/Kiritimati": "KI",
2402
+ "Antarctica/Macquarie": "AU",
2403
+ "America/Guyana": "GY",
2404
+ "Asia/Riyadh": "SA",
2405
+ "Pacific/Tahiti": "PF",
2406
+ "America/St_Vincent": "VC",
2407
+ "America/Cancun": "MX",
2408
+ "America/Grenada": "GD",
2409
+ "Pacific/Wake": "UM",
2410
+ "America/Dawson": "CA",
2411
+ "Europe/Brussels": "BE",
2412
+ "Indian/Kerguelen": "TF",
2413
+ "America/Yakutat": "US",
2414
+ "Indian/Mahe": "SC",
2415
+ "Atlantic/Reykjavik": "IS",
2416
+ "America/Panama": "PA",
2417
+ "America/Guadeloupe": "GP",
2418
+ "Europe/Malta": "MT",
2419
+ "Antarctica/Troll": "AQ",
2420
+ "Asia/Jayapura": "ID",
2421
+ "Asia/Bahrain": "BH",
2422
+ "Asia/Chita": "RU",
2423
+ "Europe/Tallinn": "EE",
2424
+ "Asia/Khandyga": "RU",
2425
+ "America/Rio_Branco": "BR",
2426
+ "Atlantic/St_Helena": "SH",
2427
+ "Africa/Juba": "SS",
2428
+ "America/Adak": "US",
2429
+ "Pacific/Saipan": "MP",
2430
+ "America/St_Lucia": "LC",
2431
+ "America/Inuvik": "CA",
2432
+ "Europe/Luxembourg": "LU",
2433
+ "Africa/Bissau": "GW",
2434
+ "Asia/Oral": "KZ",
2435
+ "America/Boa_Vista": "BR",
2436
+ "Europe/Skopje": "MK",
2437
+ "America/Port-au-Prince": "HT",
2438
+ "Pacific/Port_Moresby": "PG",
2439
+ "Europe/Andorra": "AD",
2440
+ "America/Indiana/Marengo": "US",
2441
+ "Africa/Kigali": "RW",
2442
+ "Africa/Bamako": "ML",
2443
+ "America/Dominica": "DM",
2444
+ "Asia/Aqtobe": "KZ",
2445
+ "Europe/Istanbul": "TR",
2446
+ "Pacific/Rarotonga": "CK",
2447
+ "America/Danmarkshavn": "GL",
2448
+ "Europe/Zurich": "CH",
2449
+ "Asia/Yangon": "MM",
2450
+ "America/Monterrey": "MX",
2451
+ "Europe/Lisbon": "PT",
2452
+ "Asia/Kuching": "MY",
2453
+ "Antarctica/Rothera": "AQ",
2454
+ "Australia/Perth": "AU",
2455
+ "Asia/Phnom_Penh": "KH",
2456
+ "America/Swift_Current": "CA",
2457
+ "Asia/Aqtau": "KZ",
2458
+ "Asia/Urumqi": "CN",
2459
+ "Asia/Calcutta": "IN"
2460
+ };
2461
+
2462
+ // src/insights/index.ts
2463
+ var getBasePayload = () => {
2464
+ const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
2465
+ const location = TIMEZONE_MAP[timeZone];
2466
+ const locale = navigator.languages && navigator.languages.length ? navigator.languages[0] : navigator.userLanguage || navigator.language || navigator.browserLanguage || "en";
2467
+ return {
2468
+ "user-agent": window.navigator.userAgent,
2469
+ locale,
2470
+ location,
2471
+ referrer: document.referrer,
2472
+ pathname: window.location.pathname,
2473
+ href: window.location.href
2474
+ };
2475
+ };
2476
+ var createInsightsClient = ({ endpoint }) => {
2477
+ const url = new URL(endpoint.host);
2478
+ url.pathname = "/v0/events";
2479
+ url.searchParams.set("name", "analytics_events");
2480
+ const endpointUrl = url.toString();
2481
+ const sendMessage = async (message) => {
2482
+ const converted = {
2483
+ ...message,
2484
+ payload: JSON.stringify(message.payload)
2485
+ };
2486
+ const response = await fetch(endpointUrl, {
2487
+ method: "POST",
2488
+ headers: {
2489
+ "Content-Type": "application/json",
2490
+ Authorization: `Bearer ${endpoint.apiKey}`
2491
+ },
2492
+ body: JSON.stringify(converted)
2493
+ });
2494
+ const json = await response.json();
2495
+ return json;
2496
+ };
2497
+ return {
2498
+ sessionStart: (options) => {
2499
+ const message = {
2500
+ action: "session_start",
2501
+ version: "1",
2502
+ session_id: options.sessionId,
2503
+ visitor_id: options.visitorId,
2504
+ page_view_id: options.pageId,
2505
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
2506
+ payload: {
2507
+ ...getBasePayload(),
2508
+ previous_session_id: options.previousSessionId
2509
+ }
2510
+ };
2511
+ return sendMessage(message);
2512
+ },
2513
+ pageHit: (options) => {
2514
+ const message = {
2515
+ action: "page_hit",
2516
+ version: "1",
2517
+ session_id: options.sessionId,
2518
+ visitor_id: options.visitorId,
2519
+ page_view_id: options.pageId,
2520
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
2521
+ payload: getBasePayload()
2522
+ };
2523
+ return sendMessage(message);
2524
+ },
2525
+ testResult: (options) => {
2526
+ const message = {
2527
+ action: "test_result",
2528
+ version: "1",
2529
+ session_id: options.sessionId,
2530
+ visitor_id: options.visitorId,
2531
+ page_view_id: options.pageId,
2532
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
2533
+ payload: {
2534
+ ...getBasePayload(),
2535
+ ...options
2536
+ }
2537
+ };
2538
+ return sendMessage(message);
2539
+ },
2540
+ personalizationResult: async (options) => {
2541
+ const messages = options.variantIds.map((variantId) => {
2542
+ const message = {
2543
+ action: "personalization_result",
2544
+ version: "1",
2545
+ session_id: options.sessionId,
2546
+ visitor_id: options.visitorId,
2547
+ page_view_id: options.pageId,
2548
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
2549
+ payload: {
2550
+ ...getBasePayload(),
2551
+ name: options.name,
2552
+ variantId,
2553
+ control: options.control,
2554
+ changed: options.changed
2555
+ }
2556
+ };
2557
+ return message;
2558
+ });
2559
+ await Promise.all(messages.map((message) => sendMessage(message)));
2560
+ },
2561
+ goalConvert: (options) => {
2562
+ const message = {
2563
+ action: "goal_convert",
2564
+ version: "1",
2565
+ session_id: options.sessionId,
2566
+ visitor_id: options.visitorId,
2567
+ page_view_id: options.pageId,
2568
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
2569
+ payload: {
2570
+ ...getBasePayload(),
2571
+ goalId: options.goalId
2572
+ }
2573
+ };
2574
+ return sendMessage(message);
2575
+ }
2576
+ };
2577
+ };
2578
+ var createInsightsStorage = () => {
2579
+ const STORAGE_KEY2 = "ufin";
2580
+ return {
2581
+ get: () => {
2582
+ const data = localStorage.getItem(STORAGE_KEY2);
2583
+ if (!data) {
2584
+ return;
2585
+ }
2586
+ return JSON.parse(data);
2587
+ },
2588
+ set: (data) => {
2589
+ const toSet = {
2590
+ ...data,
2591
+ updated: Date.now()
2592
+ };
2593
+ localStorage.setItem(STORAGE_KEY2, JSON.stringify(toSet));
2594
+ },
2595
+ clear: () => {
2596
+ localStorage.removeItem(STORAGE_KEY2);
2597
+ }
2598
+ };
2599
+ };
2600
+ var generateVisitorId = () => {
2601
+ return `visitor_${(0, import_nanoid.nanoid)()}`;
2602
+ };
2603
+ var generateSessionId = () => {
2604
+ return `session_${(0, import_nanoid.nanoid)()}`;
2605
+ };
2606
+ var generatePageId = () => {
2607
+ return `page_${(0, import_nanoid.nanoid)()}`;
2608
+ };
2609
+ var createInsights = ({
2610
+ endpoint,
2611
+ sessionDurationSeconds = 30 * 60
2612
+ }) => {
2613
+ const client = createInsightsClient({
2614
+ endpoint
2615
+ });
2616
+ const storage = createInsightsStorage();
2617
+ let storageData = void 0;
2618
+ let pageId = generatePageId();
2619
+ return {
2620
+ init: () => {
2621
+ storageData = storage.get();
2622
+ if (!storageData || Date.now() - storageData.updated > sessionDurationSeconds * 1e3) {
2623
+ const previousSessionId = storageData == null ? void 0 : storageData.sessionId;
2624
+ storageData = {
2625
+ visitorId: (storageData == null ? void 0 : storageData.visitorId) || generateVisitorId(),
2626
+ sessionId: generateSessionId(),
2627
+ updated: Date.now()
2628
+ };
2629
+ storage.set(storageData);
2630
+ client.sessionStart({
2631
+ visitorId: storageData.visitorId,
2632
+ sessionId: storageData.sessionId,
2633
+ previousSessionId,
2634
+ maxAgeSeconds: sessionDurationSeconds,
2635
+ pageId
2636
+ });
2637
+ } else if (storageData) {
2638
+ storage.set(storageData);
2639
+ }
2640
+ },
2641
+ pageHit: () => {
2642
+ if (!storageData) {
2643
+ console.error("Insights not initialized");
2644
+ return;
2645
+ }
2646
+ client.pageHit({
2647
+ visitorId: storageData.visitorId,
2648
+ sessionId: storageData.sessionId,
2649
+ pageId
2650
+ });
2651
+ },
2652
+ testResult: (result) => {
2653
+ if (!storageData) {
2654
+ console.error("Insights not initialized");
2655
+ return;
2656
+ }
2657
+ client.testResult({
2658
+ ...result,
2659
+ visitorId: storageData.visitorId,
2660
+ sessionId: storageData.sessionId,
2661
+ pageId
2662
+ });
2663
+ pageId = generatePageId();
2664
+ },
2665
+ personalizationResult: (result) => {
2666
+ if (!storageData) {
2667
+ console.error("Insights not initialized");
2668
+ return;
2669
+ }
2670
+ client.personalizationResult({
2671
+ ...result,
2672
+ visitorId: storageData.visitorId,
2673
+ sessionId: storageData.sessionId,
2674
+ pageId
2675
+ });
2676
+ },
2677
+ goalConvert: (goalId) => {
2678
+ if (!storageData) {
2679
+ console.error("Insights not initialized");
2680
+ return;
2681
+ }
2682
+ client.goalConvert({
2683
+ visitorId: storageData.visitorId,
2684
+ sessionId: storageData.sessionId,
2685
+ goalId,
2686
+ pageId
2687
+ });
2688
+ },
2689
+ forget: () => {
2690
+ storage.clear();
2691
+ storageData = void 0;
2692
+ },
2693
+ get sessionId() {
2694
+ return storageData == null ? void 0 : storageData.sessionId;
2695
+ }
2696
+ };
2697
+ };
2698
+ var enableUniformInsights = (options) => {
2699
+ const insights = createInsights({
2700
+ endpoint: options.endpoint
2701
+ });
2702
+ return {
2703
+ init: (context) => {
2704
+ const consentChanged = () => {
2705
+ if (context.storage.data.consent) {
2706
+ insights.init();
2707
+ } else {
2708
+ insights.forget();
2709
+ }
2710
+ };
2711
+ const handlePersonalizationResult = (data) => {
2712
+ insights.personalizationResult(data);
2713
+ };
2714
+ const handleTestResult = (result) => {
2715
+ insights.testResult(result);
2716
+ };
2717
+ const handleGoalConvert = (result) => {
2718
+ insights.goalConvert(result.goalId);
2719
+ };
2720
+ context.storage.events.on("goalConverted", handleGoalConvert);
2721
+ context.storage.events.on("consentUpdated", consentChanged);
2722
+ context.events.on("personalizationResult", handlePersonalizationResult);
2723
+ context.events.on("testResult", handleTestResult);
2724
+ if (context.storage.data.consent) {
2725
+ consentChanged();
2726
+ }
2727
+ return () => {
2728
+ context.storage.events.off("consentUpdated", consentChanged);
2729
+ context.storage.events.off("goalConverted", handleGoalConvert);
2730
+ context.events.off("personalizationResult", handlePersonalizationResult);
2731
+ context.events.off("testResult", handleTestResult);
2732
+ };
2733
+ },
2734
+ update: (context) => {
2735
+ if (context.url) {
2736
+ insights.pageHit();
2737
+ }
2738
+ },
2739
+ forget: () => {
2740
+ insights.forget();
2741
+ }
2742
+ };
2743
+ };
2744
+
1820
2745
  // src/logging/enableConsoleLogDrain.ts
1821
2746
  var import_rfdc2 = __toESM(require("rfdc"));
1822
2747
 
@@ -2021,6 +2946,7 @@ function parseQuickConnect(serialized) {
2021
2946
  enableConsoleLogDrain,
2022
2947
  enableContextDevTools,
2023
2948
  enableDebugConsoleLogDrain,
2949
+ enableUniformInsights,
2024
2950
  evaluateVariantMatch,
2025
2951
  eventEvaluator,
2026
2952
  explainStringMatch,