@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.mjs CHANGED
@@ -76,119 +76,73 @@ function computeAggregateDimension(primitiveScores, aggregateDimension, allAggre
76
76
  // src/manifest/constants.ts
77
77
  var ENR_SEPARATOR = "_";
78
78
 
79
- // src/manifest/signals/SignalInstance.ts
80
- var _evaluator, _onLogMessage;
81
- var SignalInstance = class {
82
- constructor(data, evaluator, onLogMessage) {
83
- __privateAdd(this, _evaluator, void 0);
84
- __privateAdd(this, _onLogMessage, void 0);
85
- __publicField(this, "signal");
86
- this.signal = data;
87
- __privateSet(this, _evaluator, evaluator);
88
- __privateSet(this, _onLogMessage, onLogMessage);
89
- }
90
- /** Computes storage update commands to take based on a state update and the signal's criteria */
91
- computeSignal(update, commands) {
92
- const isAtCap = update.scores[this.signal.id] >= this.signal.cap;
93
- if (isAtCap && this.signal.dur !== "t") {
94
- return;
95
- }
96
- const criteriaMatchUpdate = __privateGet(this, _evaluator).evaluate(
97
- update,
98
- this.signal.crit,
99
- commands,
100
- this.signal,
101
- __privateGet(this, _onLogMessage)
102
- );
103
- const scoreCommand = this.signal.dur === "s" || this.signal.dur === "t" ? "modscoreS" : "modscore";
104
- if (!criteriaMatchUpdate.changed) {
105
- return;
106
- }
107
- if (criteriaMatchUpdate.result) {
108
- commands.push({
109
- type: scoreCommand,
110
- data: { dimension: this.signal.id, delta: this.signal.str }
111
- });
112
- } else if (this.signal.dur === "t") {
113
- const sessionScore = update.visitor.sessionScores[this.signal.id];
114
- if (sessionScore) {
115
- commands.push({
116
- type: scoreCommand,
117
- data: { dimension: this.signal.id, delta: -sessionScore }
118
- });
119
- }
120
- }
121
- }
122
- };
123
- _evaluator = new WeakMap();
124
- _onLogMessage = new WeakMap();
125
-
126
- // src/manifest/ManifestInstance.ts
127
- var _mf, _signalInstances, _onLogMessage2;
128
- var ManifestInstance = class {
129
- constructor({
130
- manifest,
131
- evaluator = new GroupCriteriaEvaluator({}),
132
- // eslint-disable-next-line @typescript-eslint/no-empty-function
133
- onLogMessage = () => {
134
- }
135
- }) {
136
- __publicField(this, "data");
137
- __privateAdd(this, _mf, void 0);
138
- __privateAdd(this, _signalInstances, void 0);
139
- __privateAdd(this, _onLogMessage2, void 0);
140
- var _a, _b, _c;
141
- __privateSet(this, _mf, (_a = manifest.project) != null ? _a : {});
142
- this.data = manifest;
143
- __privateSet(this, _signalInstances, Object.entries((_c = (_b = __privateGet(this, _mf).pz) == null ? void 0 : _b.sig) != null ? _c : []).map(
144
- ([id, signal]) => new SignalInstance({ ...signal, id }, evaluator, onLogMessage)
145
- ));
146
- __privateSet(this, _onLogMessage2, onLogMessage);
147
- }
148
- rollForControlGroup() {
149
- var _a, _b;
150
- return Math.random() < ((_b = (_a = __privateGet(this, _mf).pz) == null ? void 0 : _a.control) != null ? _b : 0);
151
- }
152
- getTest(name) {
153
- var _a;
154
- return (_a = __privateGet(this, _mf).test) == null ? void 0 : _a[name];
79
+ // src/manifest/signals/criteria/util/isNumberMatch.ts
80
+ function isNumberMatch(lhs, match) {
81
+ var _a;
82
+ if (typeof lhs === "undefined" || lhs === null) {
83
+ return false;
155
84
  }
156
- computeSignals(update) {
157
- const commands = [];
158
- __privateGet(this, _onLogMessage2).call(this, ["debug", 200, "GROUP"]);
159
- try {
160
- __privateGet(this, _signalInstances).forEach((signal) => {
161
- __privateGet(this, _onLogMessage2).call(this, ["debug", 201, "GROUP", signal.signal]);
162
- try {
163
- signal.computeSignal(update, commands);
164
- } finally {
165
- __privateGet(this, _onLogMessage2).call(this, ["debug", 201, "ENDGROUP"]);
166
- }
167
- });
168
- } finally {
169
- __privateGet(this, _onLogMessage2).call(this, ["debug", 200, "ENDGROUP"]);
170
- }
171
- return commands;
85
+ const lhsValue = Number(lhs);
86
+ if (isNaN(lhsValue)) {
87
+ return false;
172
88
  }
173
- /**
174
- * Computes aggregated scores based on other dimensions
175
- */
176
- computeAggregateDimensions(primitiveScores) {
177
- var _a, _b;
178
- return computeAggregateDimensions(primitiveScores, (_b = (_a = __privateGet(this, _mf).pz) == null ? void 0 : _a.agg) != null ? _b : {});
89
+ switch ((_a = match == null ? void 0 : match.op) != null ? _a : "=") {
90
+ case "=":
91
+ return lhsValue === match.rhs;
92
+ case "!=":
93
+ return lhsValue !== match.rhs;
94
+ case ">":
95
+ return lhsValue > match.rhs;
96
+ case "<":
97
+ return lhsValue < match.rhs;
98
+ default:
99
+ console.warn(`Unknown match type ${match.op} is false.`);
100
+ return false;
179
101
  }
180
- getDimensionByKey(scoreKey) {
181
- var _a, _b, _c, _d;
182
- const enrichmentIndex = scoreKey.indexOf(ENR_SEPARATOR);
183
- if (enrichmentIndex <= 0) {
184
- return (_b = (_a = __privateGet(this, _mf).pz) == null ? void 0 : _a.sig) == null ? void 0 : _b[scoreKey];
102
+ }
103
+ function explainNumberMatch(lhs, match) {
104
+ return `${lhs} ${explainNumberMatchCriteria(match)}`;
105
+ }
106
+ function explainNumberMatchCriteria(match) {
107
+ return `${match.op} ${match.rhs}`;
108
+ }
109
+
110
+ // src/manifest/utils/getEnrichmentVectorKey.ts
111
+ function getEnrichmentVectorKey(category, value) {
112
+ return `${category}${ENR_SEPARATOR}${value}`;
113
+ }
114
+
115
+ // src/manifest/goals/evaluators/EnrichmentGoalEvaluator.ts
116
+ var _goal, _id;
117
+ var EnrichmentGoalEvaluator = class {
118
+ constructor(options) {
119
+ __privateAdd(this, _goal, void 0);
120
+ __privateAdd(this, _id, void 0);
121
+ __privateSet(this, _goal, options.goal);
122
+ __privateSet(this, _id, options.id);
123
+ }
124
+ get id() {
125
+ return __privateGet(this, _id);
126
+ }
127
+ evaluate({ scores }) {
128
+ const name = getEnrichmentVectorKey(__privateGet(this, _goal).cat, __privateGet(this, _goal).value);
129
+ const score = scores == null ? void 0 : scores[name];
130
+ if (typeof score !== "number") {
131
+ return {
132
+ triggered: false
133
+ };
185
134
  }
186
- return (_d = (_c = __privateGet(this, _mf).pz) == null ? void 0 : _c.enr) == null ? void 0 : _d[scoreKey.substring(0, enrichmentIndex)];
135
+ const isMatch = isNumberMatch(score, {
136
+ op: __privateGet(this, _goal).op,
137
+ rhs: __privateGet(this, _goal).score
138
+ });
139
+ return {
140
+ triggered: isMatch
141
+ };
187
142
  }
188
143
  };
189
- _mf = new WeakMap();
190
- _signalInstances = new WeakMap();
191
- _onLogMessage2 = new WeakMap();
144
+ _goal = new WeakMap();
145
+ _id = new WeakMap();
192
146
 
193
147
  // src/manifest/signals/criteria/evaluators/cookieEvaluator.ts
194
148
  import { dequal } from "dequal/lite";
@@ -307,42 +261,6 @@ var eventEvaluator = ({ update, criteria, onLogMessage }) => {
307
261
  return finalResult;
308
262
  };
309
263
 
310
- // src/manifest/utils/getEnrichmentVectorKey.ts
311
- function getEnrichmentVectorKey(category, value) {
312
- return `${category}${ENR_SEPARATOR}${value}`;
313
- }
314
-
315
- // src/manifest/signals/criteria/util/isNumberMatch.ts
316
- function isNumberMatch(lhs, match) {
317
- var _a;
318
- if (typeof lhs === "undefined" || lhs === null) {
319
- return false;
320
- }
321
- const lhsValue = Number(lhs);
322
- if (isNaN(lhsValue)) {
323
- return false;
324
- }
325
- switch ((_a = match == null ? void 0 : match.op) != null ? _a : "=") {
326
- case "=":
327
- return lhsValue === match.rhs;
328
- case "!=":
329
- return lhsValue !== match.rhs;
330
- case ">":
331
- return lhsValue > match.rhs;
332
- case "<":
333
- return lhsValue < match.rhs;
334
- default:
335
- console.warn(`Unknown match type ${match.op} is false.`);
336
- return false;
337
- }
338
- }
339
- function explainNumberMatch(lhs, match) {
340
- return `${lhs} ${explainNumberMatchCriteria(match)}`;
341
- }
342
- function explainNumberMatchCriteria(match) {
343
- return `${match.op} ${match.rhs}`;
344
- }
345
-
346
264
  // src/manifest/signals/criteria/evaluators/pageViewCountEvaluator.ts
347
265
  var pageViewCountDimension = getEnrichmentVectorKey("$pvc", "v");
348
266
  var pageViewCountEvaluator = ({ update, criteria, commands, onLogMessage }) => {
@@ -472,6 +390,232 @@ var GroupCriteriaEvaluator = class {
472
390
  };
473
391
  _evaluators = new WeakMap();
474
392
 
393
+ // src/manifest/goals/evaluators/QuirkGoalEvaluator.ts
394
+ var _goal2, _id2;
395
+ var QuirkGoalEvaluator = class {
396
+ constructor(options) {
397
+ __privateAdd(this, _goal2, void 0);
398
+ __privateAdd(this, _id2, void 0);
399
+ __privateSet(this, _goal2, options.goal);
400
+ __privateSet(this, _id2, options.id);
401
+ }
402
+ get id() {
403
+ return __privateGet(this, _id2);
404
+ }
405
+ evaluate({ quirks }) {
406
+ const quirkValue = quirks == null ? void 0 : quirks[__privateGet(this, _goal2).id];
407
+ if (typeof quirkValue !== "string") {
408
+ return {
409
+ triggered: false
410
+ };
411
+ }
412
+ const isMatch = isStringMatch(quirkValue, {
413
+ op: __privateGet(this, _goal2).op,
414
+ rhs: __privateGet(this, _goal2).value,
415
+ cs: __privateGet(this, _goal2).cs
416
+ });
417
+ return {
418
+ triggered: isMatch
419
+ };
420
+ }
421
+ };
422
+ _goal2 = new WeakMap();
423
+ _id2 = new WeakMap();
424
+
425
+ // src/manifest/goals/evaluators/SignalGoalEvaluator.ts
426
+ var _goal3, _id3;
427
+ var SignalGoalEvaluator = class {
428
+ constructor(options) {
429
+ __privateAdd(this, _goal3, void 0);
430
+ __privateAdd(this, _id3, void 0);
431
+ __privateSet(this, _id3, options.id);
432
+ __privateSet(this, _goal3, options.goal);
433
+ }
434
+ get id() {
435
+ return __privateGet(this, _id3);
436
+ }
437
+ evaluate({ scores }) {
438
+ const score = scores == null ? void 0 : scores[__privateGet(this, _goal3).id];
439
+ if (typeof score !== "number") {
440
+ return {
441
+ triggered: false
442
+ };
443
+ }
444
+ const isMatch = isNumberMatch(score, {
445
+ op: __privateGet(this, _goal3).op,
446
+ rhs: __privateGet(this, _goal3).score
447
+ });
448
+ return {
449
+ triggered: isMatch
450
+ };
451
+ }
452
+ };
453
+ _goal3 = new WeakMap();
454
+ _id3 = new WeakMap();
455
+
456
+ // src/manifest/goals/evaluators/index.ts
457
+ var resolveGoalEvaluator = ({ id, goal }) => {
458
+ let evaluator;
459
+ if (goal.type === "sig") {
460
+ evaluator = new SignalGoalEvaluator({
461
+ id,
462
+ goal
463
+ });
464
+ } else if (goal.type === "enr") {
465
+ evaluator = new EnrichmentGoalEvaluator({
466
+ id,
467
+ goal
468
+ });
469
+ } else if (goal.type === "qrk") {
470
+ evaluator = new QuirkGoalEvaluator({
471
+ id,
472
+ goal
473
+ });
474
+ }
475
+ return evaluator;
476
+ };
477
+
478
+ // src/manifest/signals/SignalInstance.ts
479
+ var _evaluator, _onLogMessage;
480
+ var SignalInstance = class {
481
+ constructor(data, evaluator, onLogMessage) {
482
+ __privateAdd(this, _evaluator, void 0);
483
+ __privateAdd(this, _onLogMessage, void 0);
484
+ __publicField(this, "signal");
485
+ this.signal = data;
486
+ __privateSet(this, _evaluator, evaluator);
487
+ __privateSet(this, _onLogMessage, onLogMessage);
488
+ }
489
+ /** Computes storage update commands to take based on a state update and the signal's criteria */
490
+ computeSignal(update, commands) {
491
+ const isAtCap = update.scores[this.signal.id] >= this.signal.cap;
492
+ if (isAtCap && this.signal.dur !== "t") {
493
+ return;
494
+ }
495
+ const criteriaMatchUpdate = __privateGet(this, _evaluator).evaluate(
496
+ update,
497
+ this.signal.crit,
498
+ commands,
499
+ this.signal,
500
+ __privateGet(this, _onLogMessage)
501
+ );
502
+ const scoreCommand = this.signal.dur === "s" || this.signal.dur === "t" ? "modscoreS" : "modscore";
503
+ if (!criteriaMatchUpdate.changed) {
504
+ return;
505
+ }
506
+ if (criteriaMatchUpdate.result) {
507
+ commands.push({
508
+ type: scoreCommand,
509
+ data: { dimension: this.signal.id, delta: this.signal.str }
510
+ });
511
+ } else if (this.signal.dur === "t") {
512
+ const sessionScore = update.visitor.sessionScores[this.signal.id];
513
+ if (sessionScore) {
514
+ commands.push({
515
+ type: scoreCommand,
516
+ data: { dimension: this.signal.id, delta: -sessionScore }
517
+ });
518
+ }
519
+ }
520
+ }
521
+ };
522
+ _evaluator = new WeakMap();
523
+ _onLogMessage = new WeakMap();
524
+
525
+ // src/manifest/ManifestInstance.ts
526
+ var _mf, _signalInstances, _goalEvaluators, _onLogMessage2;
527
+ var ManifestInstance = class {
528
+ constructor({
529
+ manifest,
530
+ evaluator = new GroupCriteriaEvaluator({}),
531
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
532
+ onLogMessage = () => {
533
+ }
534
+ }) {
535
+ __publicField(this, "data");
536
+ __privateAdd(this, _mf, void 0);
537
+ __privateAdd(this, _signalInstances, void 0);
538
+ __privateAdd(this, _goalEvaluators, void 0);
539
+ __privateAdd(this, _onLogMessage2, void 0);
540
+ var _a, _b, _c, _d;
541
+ __privateSet(this, _mf, (_a = manifest.project) != null ? _a : {});
542
+ this.data = manifest;
543
+ __privateSet(this, _signalInstances, Object.entries((_c = (_b = __privateGet(this, _mf).pz) == null ? void 0 : _b.sig) != null ? _c : []).map(
544
+ ([id, signal]) => new SignalInstance({ ...signal, id }, evaluator, onLogMessage)
545
+ ));
546
+ __privateSet(this, _goalEvaluators, Object.entries((_d = __privateGet(this, _mf).goal) != null ? _d : {}).map(([id, goal]) => {
547
+ const evaluator2 = resolveGoalEvaluator({
548
+ id,
549
+ goal
550
+ });
551
+ if (!evaluator2) {
552
+ console.warn(`Unable to resolve goal evaluator for goal ${id}`);
553
+ }
554
+ return evaluator2;
555
+ }).filter((evaluator2) => !!evaluator2));
556
+ __privateSet(this, _onLogMessage2, onLogMessage);
557
+ }
558
+ rollForControlGroup() {
559
+ var _a, _b;
560
+ return Math.random() < ((_b = (_a = __privateGet(this, _mf).pz) == null ? void 0 : _a.control) != null ? _b : 0);
561
+ }
562
+ getTest(name) {
563
+ var _a;
564
+ return (_a = __privateGet(this, _mf).test) == null ? void 0 : _a[name];
565
+ }
566
+ computeSignals(update) {
567
+ const commands = [];
568
+ __privateGet(this, _onLogMessage2).call(this, ["debug", 200, "GROUP"]);
569
+ try {
570
+ __privateGet(this, _signalInstances).forEach((signal) => {
571
+ __privateGet(this, _onLogMessage2).call(this, ["debug", 201, "GROUP", signal.signal]);
572
+ try {
573
+ signal.computeSignal(update, commands);
574
+ } finally {
575
+ __privateGet(this, _onLogMessage2).call(this, ["debug", 201, "ENDGROUP"]);
576
+ }
577
+ });
578
+ } finally {
579
+ __privateGet(this, _onLogMessage2).call(this, ["debug", 200, "ENDGROUP"]);
580
+ }
581
+ return commands;
582
+ }
583
+ computeGoals(data) {
584
+ const commands = [];
585
+ __privateGet(this, _goalEvaluators).forEach((evaluator) => {
586
+ const { triggered } = evaluator.evaluate(data);
587
+ if (triggered) {
588
+ commands.push({
589
+ type: "setgoal",
590
+ data: {
591
+ goal: evaluator.id
592
+ }
593
+ });
594
+ }
595
+ });
596
+ return commands;
597
+ }
598
+ /**
599
+ * Computes aggregated scores based on other dimensions
600
+ */
601
+ computeAggregateDimensions(primitiveScores) {
602
+ var _a, _b;
603
+ return computeAggregateDimensions(primitiveScores, (_b = (_a = __privateGet(this, _mf).pz) == null ? void 0 : _a.agg) != null ? _b : {});
604
+ }
605
+ getDimensionByKey(scoreKey) {
606
+ var _a, _b, _c, _d;
607
+ const enrichmentIndex = scoreKey.indexOf(ENR_SEPARATOR);
608
+ if (enrichmentIndex <= 0) {
609
+ return (_b = (_a = __privateGet(this, _mf).pz) == null ? void 0 : _a.sig) == null ? void 0 : _b[scoreKey];
610
+ }
611
+ return (_d = (_c = __privateGet(this, _mf).pz) == null ? void 0 : _c.enr) == null ? void 0 : _d[scoreKey.substring(0, enrichmentIndex)];
612
+ }
613
+ };
614
+ _mf = new WeakMap();
615
+ _signalInstances = new WeakMap();
616
+ _goalEvaluators = new WeakMap();
617
+ _onLogMessage2 = new WeakMap();
618
+
475
619
  // src/placement/criteria/evaluateVariantMatch.ts
476
620
  function evaluateVariantMatch(variantId, match, vec, onLogMessage) {
477
621
  onLogMessage == null ? void 0 : onLogMessage(["info", 301, "GROUP", { id: variantId, op: match == null ? void 0 : match.op }]);
@@ -975,6 +1119,7 @@ var emptyVisitorData = () => ({
975
1119
  scores: {},
976
1120
  sessionScores: {},
977
1121
  tests: {},
1122
+ goals: {},
978
1123
  consent: false,
979
1124
  controlGroup: false
980
1125
  });
@@ -989,7 +1134,7 @@ var clone = rfdc();
989
1134
  function applyCommandsToData(commands, state, inControlGroup) {
990
1135
  const newData = state ? clone(state) : emptyVisitorData();
991
1136
  commands.forEach((command) => {
992
- var _a, _b;
1137
+ var _a, _b, _c;
993
1138
  switch (command.type) {
994
1139
  case "consent":
995
1140
  newData.consent = command.data;
@@ -1025,6 +1170,10 @@ function applyCommandsToData(commands, state, inControlGroup) {
1025
1170
  case "setcontrol":
1026
1171
  newData.controlGroup = command.data;
1027
1172
  break;
1173
+ case "setgoal":
1174
+ newData.goals = (_c = newData.goals) != null ? _c : {};
1175
+ newData.goals[command.data.goal] = true;
1176
+ break;
1028
1177
  default:
1029
1178
  throw new Error(`Unknown command`);
1030
1179
  }
@@ -1190,7 +1339,7 @@ currentData_get = function() {
1190
1339
  };
1191
1340
  _replaceData = new WeakSet();
1192
1341
  replaceData_fn = function(data, quiet = false) {
1193
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1342
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1194
1343
  const oldData = __privateGet(this, _currentData, currentData_get);
1195
1344
  const now = Date.now();
1196
1345
  if (data.controlGroup) {
@@ -1211,6 +1360,7 @@ replaceData_fn = function(data, quiet = false) {
1211
1360
  const haveSessionScoresChanged = !dequal3(oldData == null ? void 0 : oldData.visitorData.sessionScores, data.sessionScores);
1212
1361
  const haveQuirksChanged = !dequal3(oldData == null ? void 0 : oldData.visitorData.quirks, data.quirks);
1213
1362
  const haveTestsChanged = !dequal3(oldData == null ? void 0 : oldData.visitorData.tests, data.tests);
1363
+ const haveGoalsChanged = !dequal3(oldData == null ? void 0 : oldData.visitorData.goals, data.goals);
1214
1364
  const updatedData = {
1215
1365
  updated: now,
1216
1366
  visitorData: data
@@ -1235,6 +1385,15 @@ replaceData_fn = function(data, quiet = false) {
1235
1385
  __privateGet(this, _mitt2).emit("controlGroupUpdated", data);
1236
1386
  (_i = (_h = __privateGet(this, _options)).onLogMessage) == null ? void 0 : _i.call(_h, ["debug", 104, (_g = data.controlGroup) != null ? _g : false]);
1237
1387
  }
1388
+ if (haveGoalsChanged) {
1389
+ const newGoalKeys = Object.keys((_j = data.goals) != null ? _j : {});
1390
+ for (let i = 0; i < newGoalKeys.length; i++) {
1391
+ const key = newGoalKeys[i];
1392
+ if (!((_k = oldData == null ? void 0 : oldData.visitorData.goals) == null ? void 0 : _k[key])) {
1393
+ __privateGet(this, _mitt2).emit("goalConverted", { goalId: key });
1394
+ }
1395
+ }
1396
+ }
1238
1397
  }
1239
1398
  };
1240
1399
  _setVisitTimeout = new WeakSet();
@@ -1287,10 +1446,10 @@ import { dequal as dequal4 } from "dequal/lite";
1287
1446
  import mitt3 from "mitt";
1288
1447
  var CONTEXTUAL_EDITING_TEST_NAME = "contextual_editing_test";
1289
1448
  var CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID = "contextual_editing_test_selected_variant";
1290
- var _serverTransitionState, _scores, _state, _pzCache, _mitt3, _emitTest, emitTest_fn, _updateComputedScores, updateComputedScores_fn, _calculateScores, calculateScores_fn;
1449
+ var _serverTransitionState, _scores, _state, _pzCache, _plugins, _mitt3, _updateGoals, updateGoals_fn, _updateComputedScores, updateComputedScores_fn, _calculateScores, calculateScores_fn;
1291
1450
  var Context = class {
1292
1451
  constructor(options) {
1293
- __privateAdd(this, _emitTest);
1452
+ __privateAdd(this, _updateGoals);
1294
1453
  __privateAdd(this, _updateComputedScores);
1295
1454
  __privateAdd(this, _calculateScores);
1296
1455
  __publicField(this, "manifest");
@@ -1298,6 +1457,7 @@ var Context = class {
1298
1457
  __privateAdd(this, _scores, {});
1299
1458
  __privateAdd(this, _state, void 0);
1300
1459
  __privateAdd(this, _pzCache, {});
1460
+ __privateAdd(this, _plugins, void 0);
1301
1461
  __privateAdd(this, _mitt3, mitt3());
1302
1462
  /**
1303
1463
  * Subscribe to events
@@ -1310,7 +1470,8 @@ var Context = class {
1310
1470
  var _a, _b;
1311
1471
  const { manifest, ...storageOptions } = options;
1312
1472
  __privateSet(this, _state, {});
1313
- (_a = options.plugins) == null ? void 0 : _a.forEach((plugin) => {
1473
+ __privateSet(this, _plugins, options.plugins);
1474
+ (_a = __privateGet(this, _plugins)) == null ? void 0 : _a.forEach((plugin) => {
1314
1475
  if (!plugin.logDrain) {
1315
1476
  return;
1316
1477
  }
@@ -1320,7 +1481,19 @@ var Context = class {
1320
1481
  try {
1321
1482
  this.manifest = new ManifestInstance({
1322
1483
  onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message),
1323
- manifest,
1484
+ manifest: {
1485
+ project: {
1486
+ ...manifest.project,
1487
+ goal: {
1488
+ is_developer: {
1489
+ type: "sig",
1490
+ id: "1_dev",
1491
+ op: ">",
1492
+ score: 0
1493
+ }
1494
+ }
1495
+ }
1496
+ },
1324
1497
  evaluator: new GroupCriteriaEvaluator({
1325
1498
  CK: cookieEvaluator,
1326
1499
  QS: queryStringEvaluator,
@@ -1353,11 +1526,15 @@ var Context = class {
1353
1526
  previousState: __privateGet(this, _state),
1354
1527
  visitor: this.storage.data
1355
1528
  });
1529
+ __privateMethod(this, _updateGoals, updateGoals_fn).call(this, {
1530
+ quirks: quirks.quirks,
1531
+ scores: void 0
1532
+ });
1356
1533
  this.storage.updateData(updates);
1357
1534
  __privateGet(this, _mitt3).emit("quirksUpdated", quirks.quirks);
1358
1535
  __privateGet(this, _mitt3).emit("log", ["info", 4, quirks.quirks]);
1359
1536
  });
1360
- (_b = options.plugins) == null ? void 0 : _b.forEach((plugin) => {
1537
+ (_b = __privateGet(this, _plugins)) == null ? void 0 : _b.forEach((plugin) => {
1361
1538
  if (!plugin.init) {
1362
1539
  return;
1363
1540
  }
@@ -1367,6 +1544,13 @@ var Context = class {
1367
1544
  __privateGet(this, _mitt3).emit("log", ["info", 1, "ENDGROUP"]);
1368
1545
  }
1369
1546
  }
1547
+ internal_emitPersonalizationResult(event) {
1548
+ __privateGet(this, _mitt3).emit("personalizationResult", event);
1549
+ __privateGet(this, _pzCache)[event.name] = event.variantIds;
1550
+ }
1551
+ internal_emitTestResult(event) {
1552
+ __privateGet(this, _mitt3).emit("testResult", event);
1553
+ }
1370
1554
  /** Gets the current visitor's dimension score vector. */
1371
1555
  get scores() {
1372
1556
  return __privateGet(this, _scores);
@@ -1472,7 +1656,7 @@ var Context = class {
1472
1656
  if (__privateGet(this, _serverTransitionState)) {
1473
1657
  __privateMethod(this, _updateComputedScores, updateComputedScores_fn).call(this, this.storage.data);
1474
1658
  Object.entries(newServerSideTests).forEach(([testName, testVariantId]) => {
1475
- __privateMethod(this, _emitTest, emitTest_fn).call(this, {
1659
+ this.internal_emitTestResult({
1476
1660
  name: testName,
1477
1661
  variantId: testVariantId,
1478
1662
  variantAssigned: true
@@ -1481,6 +1665,15 @@ var Context = class {
1481
1665
  __privateSet(this, _serverTransitionState, void 0);
1482
1666
  __privateGet(this, _mitt3).emit("log", ["debug", 131]);
1483
1667
  }
1668
+ if (__privateGet(this, _plugins)) {
1669
+ for (let i = 0; i < __privateGet(this, _plugins).length; i++) {
1670
+ const plugin = __privateGet(this, _plugins)[i];
1671
+ if (!plugin.update) {
1672
+ continue;
1673
+ }
1674
+ await plugin.update(newData);
1675
+ }
1676
+ }
1484
1677
  } finally {
1485
1678
  __privateGet(this, _mitt3).emit("log", ["info", 2, "ENDGROUP"]);
1486
1679
  }
@@ -1532,7 +1725,7 @@ var Context = class {
1532
1725
  context: this,
1533
1726
  onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message)
1534
1727
  });
1535
- __privateMethod(this, _emitTest, emitTest_fn).call(this, {
1728
+ this.internal_emitTestResult({
1536
1729
  name: options.name,
1537
1730
  variantId: (_c = (_b = value.result) == null ? void 0 : _b.id) != null ? _c : void 0,
1538
1731
  variantAssigned: value.variantAssigned
@@ -1559,8 +1752,7 @@ var Context = class {
1559
1752
  if (previousPlacement && dequal4(eventData.variantIds, previousPlacement)) {
1560
1753
  eventData.changed = false;
1561
1754
  }
1562
- __privateGet(this, _mitt3).emit("personalizationResult", eventData);
1563
- __privateGet(this, _pzCache)[options.name] = eventData.variantIds;
1755
+ this.internal_emitPersonalizationResult(eventData);
1564
1756
  return value;
1565
1757
  }
1566
1758
  /**
@@ -1569,6 +1761,15 @@ var Context = class {
1569
1761
  */
1570
1762
  async forget(fromAllDevices) {
1571
1763
  __privateSet(this, _state, {});
1764
+ if (__privateGet(this, _plugins)) {
1765
+ for (let i = 0; i < __privateGet(this, _plugins).length; i++) {
1766
+ const plugin = __privateGet(this, _plugins)[i];
1767
+ if (!plugin.forget) {
1768
+ continue;
1769
+ }
1770
+ await plugin.forget();
1771
+ }
1772
+ }
1572
1773
  await this.storage.delete(fromAllDevices);
1573
1774
  }
1574
1775
  /**
@@ -1596,10 +1797,14 @@ _serverTransitionState = new WeakMap();
1596
1797
  _scores = new WeakMap();
1597
1798
  _state = new WeakMap();
1598
1799
  _pzCache = new WeakMap();
1800
+ _plugins = new WeakMap();
1599
1801
  _mitt3 = new WeakMap();
1600
- _emitTest = new WeakSet();
1601
- emitTest_fn = function(event) {
1602
- __privateGet(this, _mitt3).emit("testResult", event);
1802
+ _updateGoals = new WeakSet();
1803
+ updateGoals_fn = async function(data) {
1804
+ const goalCommands = this.manifest.computeGoals(data);
1805
+ if (goalCommands.length !== 0) {
1806
+ await this.storage.updateData(goalCommands);
1807
+ }
1603
1808
  };
1604
1809
  _updateComputedScores = new WeakSet();
1605
1810
  updateComputedScores_fn = function(newData) {
@@ -1607,6 +1812,10 @@ updateComputedScores_fn = function(newData) {
1607
1812
  const newScoresHaveChanged = !dequal4(newScores, __privateGet(this, _scores));
1608
1813
  if (newScoresHaveChanged) {
1609
1814
  __privateSet(this, _scores, newScores);
1815
+ __privateMethod(this, _updateGoals, updateGoals_fn).call(this, {
1816
+ scores: __privateGet(this, _scores),
1817
+ quirks: void 0
1818
+ });
1610
1819
  __privateGet(this, _mitt3).emit("scoresUpdated", newScores);
1611
1820
  __privateGet(this, _mitt3).emit("log", ["info", 3, newScores]);
1612
1821
  }
@@ -1747,6 +1956,721 @@ var ScriptType = /* @__PURE__ */ ((ScriptType2) => {
1747
1956
  })(ScriptType || {});
1748
1957
  var EdgeNodeTagName = "nesitag";
1749
1958
 
1959
+ // src/insights/index.ts
1960
+ import { nanoid } from "nanoid";
1961
+
1962
+ // src/insights/constants.ts
1963
+ var TIMEZONE_MAP = {
1964
+ "Asia/Barnaul": "RU",
1965
+ "Africa/Nouakchott": "MR",
1966
+ "Africa/Lusaka": "ZM",
1967
+ "Asia/Pyongyang": "KP",
1968
+ "Europe/Bratislava": "SK",
1969
+ "America/Belize": "BZ",
1970
+ "America/Maceio": "BR",
1971
+ "Pacific/Chuuk": "FM",
1972
+ "Indian/Comoro": "KM",
1973
+ "Pacific/Palau": "PW",
1974
+ "Asia/Jakarta": "ID",
1975
+ "Africa/Windhoek": "NA",
1976
+ "America/Chihuahua": "MX",
1977
+ "America/Nome": "US",
1978
+ "Africa/Mbabane": "SZ",
1979
+ "Africa/Porto-Novo": "BJ",
1980
+ "Europe/San_Marino": "SM",
1981
+ "Pacific/Fakaofo": "TK",
1982
+ "America/Denver": "US",
1983
+ "Europe/Belgrade": "RS",
1984
+ "America/Indiana/Tell_City": "US",
1985
+ "America/Fortaleza": "BR",
1986
+ "America/Halifax": "CA",
1987
+ "Europe/Bucharest": "RO",
1988
+ "America/Indiana/Petersburg": "US",
1989
+ "Europe/Kirov": "RU",
1990
+ "Europe/Athens": "GR",
1991
+ "America/Argentina/Ushuaia": "AR",
1992
+ "Europe/Monaco": "MC",
1993
+ "Europe/Vilnius": "LT",
1994
+ "Europe/Copenhagen": "DK",
1995
+ "Pacific/Kanton": "KI",
1996
+ "America/Caracas": "VE",
1997
+ "Asia/Almaty": "KZ",
1998
+ "Europe/Paris": "FR",
1999
+ "Africa/Blantyre": "MW",
2000
+ "Asia/Muscat": "OM",
2001
+ "America/North_Dakota/Beulah": "US",
2002
+ "America/Matamoros": "MX",
2003
+ "Asia/Irkutsk": "RU",
2004
+ "America/Costa_Rica": "CR",
2005
+ "America/Araguaina": "BR",
2006
+ "Atlantic/Canary": "ES",
2007
+ "America/Santo_Domingo": "DO",
2008
+ "America/Vancouver": "CA",
2009
+ "Africa/Addis_Ababa": "ET",
2010
+ "Africa/Accra": "GH",
2011
+ "Pacific/Kwajalein": "MH",
2012
+ "Asia/Baghdad": "IQ",
2013
+ "Australia/Adelaide": "AU",
2014
+ "Australia/Hobart": "AU",
2015
+ "America/Guayaquil": "EC",
2016
+ "America/Argentina/Tucuman": "AR",
2017
+ "Australia/Lindeman": "AU",
2018
+ "America/New_York": "US",
2019
+ "Pacific/Fiji": "FJ",
2020
+ "America/Antigua": "AG",
2021
+ "Africa/Casablanca": "MA",
2022
+ "America/Paramaribo": "SR",
2023
+ "Africa/Cairo": "EG",
2024
+ "America/Cayenne": "GF",
2025
+ "America/Detroit": "US",
2026
+ "Antarctica/Syowa": "AQ",
2027
+ "Africa/Douala": "CM",
2028
+ "America/Argentina/La_Rioja": "AR",
2029
+ "Africa/Lagos": "NG",
2030
+ "America/St_Barthelemy": "BL",
2031
+ "Asia/Nicosia": "CY",
2032
+ "Asia/Macau": "MO",
2033
+ "Europe/Riga": "LV",
2034
+ "Asia/Ashgabat": "TM",
2035
+ "Indian/Antananarivo": "MG",
2036
+ "America/Argentina/San_Juan": "AR",
2037
+ "Asia/Aden": "YE",
2038
+ "Asia/Tomsk": "RU",
2039
+ "America/Asuncion": "PY",
2040
+ "Pacific/Bougainville": "PG",
2041
+ "Asia/Vientiane": "LA",
2042
+ "America/Mazatlan": "MX",
2043
+ "Africa/Luanda": "AO",
2044
+ "Europe/Oslo": "NO",
2045
+ "Africa/Kinshasa": "CD",
2046
+ "Europe/Warsaw": "PL",
2047
+ "America/Grand_Turk": "TC",
2048
+ "Asia/Seoul": "KR",
2049
+ "Africa/Tripoli": "LY",
2050
+ "America/St_Thomas": "VI",
2051
+ "Asia/Kathmandu": "NP",
2052
+ "Pacific/Pitcairn": "PN",
2053
+ "Pacific/Nauru": "NR",
2054
+ "America/Curacao": "CW",
2055
+ "Asia/Kabul": "AF",
2056
+ "Pacific/Tongatapu": "TO",
2057
+ "Europe/Simferopol": "UA",
2058
+ "Asia/Ust-Nera": "RU",
2059
+ "Africa/Mogadishu": "SO",
2060
+ "Indian/Mayotte": "YT",
2061
+ "Pacific/Niue": "NU",
2062
+ "America/Thunder_Bay": "CA",
2063
+ "Atlantic/Azores": "PT",
2064
+ "Pacific/Gambier": "PF",
2065
+ "Europe/Stockholm": "SE",
2066
+ "Africa/Libreville": "GA",
2067
+ "America/Punta_Arenas": "CL",
2068
+ "America/Guatemala": "GT",
2069
+ "America/Noronha": "BR",
2070
+ "Europe/Helsinki": "FI",
2071
+ "Asia/Gaza": "PS",
2072
+ "Pacific/Kosrae": "FM",
2073
+ "America/Aruba": "AW",
2074
+ "America/Nassau": "BS",
2075
+ "Asia/Choibalsan": "MN",
2076
+ "America/Winnipeg": "CA",
2077
+ "America/Anguilla": "AI",
2078
+ "Asia/Thimphu": "BT",
2079
+ "Asia/Beirut": "LB",
2080
+ "Atlantic/Faroe": "FO",
2081
+ "Europe/Berlin": "DE",
2082
+ "Europe/Amsterdam": "NL",
2083
+ "Pacific/Honolulu": "US",
2084
+ "America/Regina": "CA",
2085
+ "America/Scoresbysund": "GL",
2086
+ "Europe/Vienna": "AT",
2087
+ "Europe/Tirane": "AL",
2088
+ "Africa/El_Aaiun": "EH",
2089
+ "America/Creston": "CA",
2090
+ "Asia/Qostanay": "KZ",
2091
+ "Asia/Ho_Chi_Minh": "VN",
2092
+ "Europe/Samara": "RU",
2093
+ "Europe/Rome": "IT",
2094
+ "Australia/Eucla": "AU",
2095
+ "America/El_Salvador": "SV",
2096
+ "America/Chicago": "US",
2097
+ "Africa/Abidjan": "CI",
2098
+ "Asia/Kamchatka": "RU",
2099
+ "Pacific/Tarawa": "KI",
2100
+ "America/Santiago": "CL",
2101
+ "America/Bahia": "BR",
2102
+ "Indian/Christmas": "CX",
2103
+ "Asia/Atyrau": "KZ",
2104
+ "Asia/Dushanbe": "TJ",
2105
+ "Europe/Ulyanovsk": "RU",
2106
+ "America/Yellowknife": "CA",
2107
+ "America/Recife": "BR",
2108
+ "Australia/Sydney": "AU",
2109
+ "America/Fort_Nelson": "CA",
2110
+ "Pacific/Efate": "VU",
2111
+ "Europe/Saratov": "RU",
2112
+ "Africa/Banjul": "GM",
2113
+ "Asia/Omsk": "RU",
2114
+ "Europe/Ljubljana": "SI",
2115
+ "Europe/Budapest": "HU",
2116
+ "Europe/Astrakhan": "RU",
2117
+ "America/Argentina/Buenos_Aires": "AR",
2118
+ "Pacific/Chatham": "NZ",
2119
+ "America/Argentina/Salta": "AR",
2120
+ "Africa/Niamey": "NE",
2121
+ "Asia/Pontianak": "ID",
2122
+ "Indian/Reunion": "RE",
2123
+ "Asia/Hong_Kong": "HK",
2124
+ "Antarctica/McMurdo": "AQ",
2125
+ "Africa/Malabo": "GQ",
2126
+ "America/Los_Angeles": "US",
2127
+ "America/Argentina/Cordoba": "AR",
2128
+ "Pacific/Pohnpei": "FM",
2129
+ "America/Tijuana": "MX",
2130
+ "America/Campo_Grande": "BR",
2131
+ "America/Dawson_Creek": "CA",
2132
+ "Asia/Novosibirsk": "RU",
2133
+ "Pacific/Pago_Pago": "AS",
2134
+ "Asia/Jerusalem": "IL",
2135
+ "Europe/Sarajevo": "BA",
2136
+ "Africa/Freetown": "SL",
2137
+ "Asia/Yekaterinburg": "RU",
2138
+ "America/Juneau": "US",
2139
+ "Africa/Ouagadougou": "BF",
2140
+ "Africa/Monrovia": "LR",
2141
+ "Europe/Kiev": "UA",
2142
+ "America/Argentina/San_Luis": "AR",
2143
+ "Asia/Tokyo": "JP",
2144
+ "Asia/Qatar": "QA",
2145
+ "America/La_Paz": "BO",
2146
+ "America/Bogota": "CO",
2147
+ "America/Thule": "GL",
2148
+ "Asia/Manila": "PH",
2149
+ "Asia/Hovd": "MN",
2150
+ "Asia/Tehran": "IR",
2151
+ "Atlantic/Madeira": "PT",
2152
+ "America/Metlakatla": "US",
2153
+ "Europe/Vatican": "VA",
2154
+ "Asia/Bishkek": "KG",
2155
+ "Asia/Dili": "TL",
2156
+ "Antarctica/Palmer": "AQ",
2157
+ "Atlantic/Cape_Verde": "CV",
2158
+ "Indian/Chagos": "IO",
2159
+ "America/Kentucky/Monticello": "US",
2160
+ "Africa/Algiers": "DZ",
2161
+ "Africa/Maseru": "LS",
2162
+ "Asia/Kuala_Lumpur": "MY",
2163
+ "Africa/Khartoum": "SD",
2164
+ "America/Argentina/Rio_Gallegos": "AR",
2165
+ "America/Blanc-Sablon": "CA",
2166
+ "Africa/Maputo": "MZ",
2167
+ "America/Tortola": "VG",
2168
+ "Atlantic/Bermuda": "BM",
2169
+ "America/Argentina/Catamarca": "AR",
2170
+ "America/Cayman": "KY",
2171
+ "America/Puerto_Rico": "PR",
2172
+ "Pacific/Majuro": "MH",
2173
+ "Europe/Busingen": "DE",
2174
+ "Pacific/Midway": "UM",
2175
+ "Indian/Cocos": "CC",
2176
+ "Asia/Singapore": "SG",
2177
+ "America/Boise": "US",
2178
+ "America/Nuuk": "GL",
2179
+ "America/Goose_Bay": "CA",
2180
+ "Australia/Broken_Hill": "AU",
2181
+ "Africa/Dar_es_Salaam": "TZ",
2182
+ "Africa/Asmara": "ER",
2183
+ "Asia/Samarkand": "UZ",
2184
+ "Asia/Tbilisi": "GE",
2185
+ "America/Argentina/Jujuy": "AR",
2186
+ "America/Indiana/Winamac": "US",
2187
+ "America/Porto_Velho": "BR",
2188
+ "Asia/Magadan": "RU",
2189
+ "Europe/Zaporozhye": "UA",
2190
+ "Antarctica/Casey": "AQ",
2191
+ "Asia/Shanghai": "CN",
2192
+ "Pacific/Norfolk": "NF",
2193
+ "Europe/Guernsey": "GG",
2194
+ "Australia/Brisbane": "AU",
2195
+ "Antarctica/DumontDUrville": "AQ",
2196
+ "America/Havana": "CU",
2197
+ "America/Atikokan": "CA",
2198
+ "America/Mexico_City": "MX",
2199
+ "America/Rankin_Inlet": "CA",
2200
+ "America/Cuiaba": "BR",
2201
+ "America/Resolute": "CA",
2202
+ "Africa/Ceuta": "ES",
2203
+ "Arctic/Longyearbyen": "SJ",
2204
+ "Pacific/Guam": "GU",
2205
+ "Asia/Damascus": "SY",
2206
+ "Asia/Colombo": "LK",
2207
+ "Asia/Yerevan": "AM",
2208
+ "America/Montserrat": "MS",
2209
+ "America/Belem": "BR",
2210
+ "Europe/Kaliningrad": "RU",
2211
+ "Atlantic/South_Georgia": "GS",
2212
+ "Asia/Tashkent": "UZ",
2213
+ "Asia/Kolkata": "IN",
2214
+ "America/St_Johns": "CA",
2215
+ "Asia/Srednekolymsk": "RU",
2216
+ "Asia/Yakutsk": "RU",
2217
+ "Europe/Prague": "CZ",
2218
+ "Africa/Djibouti": "DJ",
2219
+ "Asia/Dubai": "AE",
2220
+ "Europe/Uzhgorod": "UA",
2221
+ "America/Edmonton": "CA",
2222
+ "Asia/Famagusta": "CY",
2223
+ "America/Indiana/Knox": "US",
2224
+ "Asia/Hebron": "PS",
2225
+ "Asia/Taipei": "TW",
2226
+ "Europe/London": "GB",
2227
+ "Africa/Dakar": "SN",
2228
+ "Australia/Darwin": "AU",
2229
+ "America/Glace_Bay": "CA",
2230
+ "Antarctica/Vostok": "AQ",
2231
+ "America/Indiana/Vincennes": "US",
2232
+ "America/Nipigon": "CA",
2233
+ "Asia/Kuwait": "KW",
2234
+ "Pacific/Guadalcanal": "SB",
2235
+ "America/Toronto": "CA",
2236
+ "Africa/Gaborone": "BW",
2237
+ "Africa/Bujumbura": "BI",
2238
+ "Africa/Lubumbashi": "CD",
2239
+ "America/Merida": "MX",
2240
+ "America/Marigot": "MF",
2241
+ "Europe/Zagreb": "HR",
2242
+ "Pacific/Easter": "CL",
2243
+ "America/Santarem": "BR",
2244
+ "Pacific/Noumea": "NC",
2245
+ "America/Sitka": "US",
2246
+ "Atlantic/Stanley": "FK",
2247
+ "Pacific/Funafuti": "TV",
2248
+ "America/Iqaluit": "CA",
2249
+ "America/Rainy_River": "CA",
2250
+ "America/Anchorage": "US",
2251
+ "America/Lima": "PE",
2252
+ "Asia/Baku": "AZ",
2253
+ "America/Indiana/Vevay": "US",
2254
+ "Asia/Ulaanbaatar": "MN",
2255
+ "America/Managua": "NI",
2256
+ "Asia/Krasnoyarsk": "RU",
2257
+ "Asia/Qyzylorda": "KZ",
2258
+ "America/Eirunepe": "BR",
2259
+ "Europe/Podgorica": "ME",
2260
+ "Europe/Chisinau": "MD",
2261
+ "Europe/Mariehamn": "AX",
2262
+ "Europe/Volgograd": "RU",
2263
+ "Africa/Nairobi": "KE",
2264
+ "Europe/Isle_of_Man": "IM",
2265
+ "America/Menominee": "US",
2266
+ "Africa/Harare": "ZW",
2267
+ "Asia/Anadyr": "RU",
2268
+ "America/Moncton": "CA",
2269
+ "Indian/Maldives": "MV",
2270
+ "America/Whitehorse": "CA",
2271
+ "Antarctica/Mawson": "AQ",
2272
+ "Europe/Madrid": "ES",
2273
+ "America/Argentina/Mendoza": "AR",
2274
+ "America/Manaus": "BR",
2275
+ "Africa/Bangui": "CF",
2276
+ "Indian/Mauritius": "MU",
2277
+ "Africa/Tunis": "TN",
2278
+ "Australia/Lord_Howe": "AU",
2279
+ "America/Kentucky/Louisville": "US",
2280
+ "America/North_Dakota/Center": "US",
2281
+ "Asia/Novokuznetsk": "RU",
2282
+ "Asia/Makassar": "ID",
2283
+ "America/Port_of_Spain": "TT",
2284
+ "America/Bahia_Banderas": "MX",
2285
+ "Pacific/Auckland": "NZ",
2286
+ "America/Sao_Paulo": "BR",
2287
+ "Asia/Dhaka": "BD",
2288
+ "America/Pangnirtung": "CA",
2289
+ "Europe/Dublin": "IE",
2290
+ "Asia/Brunei": "BN",
2291
+ "Africa/Brazzaville": "CG",
2292
+ "America/Montevideo": "UY",
2293
+ "America/Jamaica": "JM",
2294
+ "America/Indiana/Indianapolis": "US",
2295
+ "America/Kralendijk": "BQ",
2296
+ "Europe/Gibraltar": "GI",
2297
+ "Pacific/Marquesas": "PF",
2298
+ "Pacific/Apia": "WS",
2299
+ "Europe/Jersey": "JE",
2300
+ "America/Phoenix": "US",
2301
+ "Africa/Ndjamena": "TD",
2302
+ "Asia/Karachi": "PK",
2303
+ "Africa/Kampala": "UG",
2304
+ "Asia/Sakhalin": "RU",
2305
+ "America/Martinique": "MQ",
2306
+ "Europe/Moscow": "RU",
2307
+ "Africa/Conakry": "GN",
2308
+ "America/Barbados": "BB",
2309
+ "Africa/Lome": "TG",
2310
+ "America/Ojinaga": "MX",
2311
+ "America/Tegucigalpa": "HN",
2312
+ "Asia/Bangkok": "TH",
2313
+ "Africa/Johannesburg": "ZA",
2314
+ "Europe/Vaduz": "LI",
2315
+ "Africa/Sao_Tome": "ST",
2316
+ "America/Cambridge_Bay": "CA",
2317
+ "America/Lower_Princes": "SX",
2318
+ "America/Miquelon": "PM",
2319
+ "America/St_Kitts": "KN",
2320
+ "Australia/Melbourne": "AU",
2321
+ "Europe/Minsk": "BY",
2322
+ "Asia/Vladivostok": "RU",
2323
+ "Europe/Sofia": "BG",
2324
+ "Antarctica/Davis": "AQ",
2325
+ "Pacific/Galapagos": "EC",
2326
+ "America/North_Dakota/New_Salem": "US",
2327
+ "Asia/Amman": "JO",
2328
+ "Pacific/Wallis": "WF",
2329
+ "America/Hermosillo": "MX",
2330
+ "Pacific/Kiritimati": "KI",
2331
+ "Antarctica/Macquarie": "AU",
2332
+ "America/Guyana": "GY",
2333
+ "Asia/Riyadh": "SA",
2334
+ "Pacific/Tahiti": "PF",
2335
+ "America/St_Vincent": "VC",
2336
+ "America/Cancun": "MX",
2337
+ "America/Grenada": "GD",
2338
+ "Pacific/Wake": "UM",
2339
+ "America/Dawson": "CA",
2340
+ "Europe/Brussels": "BE",
2341
+ "Indian/Kerguelen": "TF",
2342
+ "America/Yakutat": "US",
2343
+ "Indian/Mahe": "SC",
2344
+ "Atlantic/Reykjavik": "IS",
2345
+ "America/Panama": "PA",
2346
+ "America/Guadeloupe": "GP",
2347
+ "Europe/Malta": "MT",
2348
+ "Antarctica/Troll": "AQ",
2349
+ "Asia/Jayapura": "ID",
2350
+ "Asia/Bahrain": "BH",
2351
+ "Asia/Chita": "RU",
2352
+ "Europe/Tallinn": "EE",
2353
+ "Asia/Khandyga": "RU",
2354
+ "America/Rio_Branco": "BR",
2355
+ "Atlantic/St_Helena": "SH",
2356
+ "Africa/Juba": "SS",
2357
+ "America/Adak": "US",
2358
+ "Pacific/Saipan": "MP",
2359
+ "America/St_Lucia": "LC",
2360
+ "America/Inuvik": "CA",
2361
+ "Europe/Luxembourg": "LU",
2362
+ "Africa/Bissau": "GW",
2363
+ "Asia/Oral": "KZ",
2364
+ "America/Boa_Vista": "BR",
2365
+ "Europe/Skopje": "MK",
2366
+ "America/Port-au-Prince": "HT",
2367
+ "Pacific/Port_Moresby": "PG",
2368
+ "Europe/Andorra": "AD",
2369
+ "America/Indiana/Marengo": "US",
2370
+ "Africa/Kigali": "RW",
2371
+ "Africa/Bamako": "ML",
2372
+ "America/Dominica": "DM",
2373
+ "Asia/Aqtobe": "KZ",
2374
+ "Europe/Istanbul": "TR",
2375
+ "Pacific/Rarotonga": "CK",
2376
+ "America/Danmarkshavn": "GL",
2377
+ "Europe/Zurich": "CH",
2378
+ "Asia/Yangon": "MM",
2379
+ "America/Monterrey": "MX",
2380
+ "Europe/Lisbon": "PT",
2381
+ "Asia/Kuching": "MY",
2382
+ "Antarctica/Rothera": "AQ",
2383
+ "Australia/Perth": "AU",
2384
+ "Asia/Phnom_Penh": "KH",
2385
+ "America/Swift_Current": "CA",
2386
+ "Asia/Aqtau": "KZ",
2387
+ "Asia/Urumqi": "CN",
2388
+ "Asia/Calcutta": "IN"
2389
+ };
2390
+
2391
+ // src/insights/index.ts
2392
+ var getBasePayload = () => {
2393
+ const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
2394
+ const location = TIMEZONE_MAP[timeZone];
2395
+ const locale = navigator.languages && navigator.languages.length ? navigator.languages[0] : navigator.userLanguage || navigator.language || navigator.browserLanguage || "en";
2396
+ return {
2397
+ "user-agent": window.navigator.userAgent,
2398
+ locale,
2399
+ location,
2400
+ referrer: document.referrer,
2401
+ pathname: window.location.pathname,
2402
+ href: window.location.href
2403
+ };
2404
+ };
2405
+ var createInsightsClient = ({ endpoint }) => {
2406
+ const url = new URL(endpoint.host);
2407
+ url.pathname = "/v0/events";
2408
+ url.searchParams.set("name", "analytics_events");
2409
+ const endpointUrl = url.toString();
2410
+ const sendMessage = async (message) => {
2411
+ const converted = {
2412
+ ...message,
2413
+ payload: JSON.stringify(message.payload)
2414
+ };
2415
+ const response = await fetch(endpointUrl, {
2416
+ method: "POST",
2417
+ headers: {
2418
+ "Content-Type": "application/json",
2419
+ Authorization: `Bearer ${endpoint.apiKey}`
2420
+ },
2421
+ body: JSON.stringify(converted)
2422
+ });
2423
+ const json = await response.json();
2424
+ return json;
2425
+ };
2426
+ return {
2427
+ sessionStart: (options) => {
2428
+ const message = {
2429
+ action: "session_start",
2430
+ version: "1",
2431
+ session_id: options.sessionId,
2432
+ visitor_id: options.visitorId,
2433
+ page_view_id: options.pageId,
2434
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
2435
+ payload: {
2436
+ ...getBasePayload(),
2437
+ previous_session_id: options.previousSessionId
2438
+ }
2439
+ };
2440
+ return sendMessage(message);
2441
+ },
2442
+ pageHit: (options) => {
2443
+ const message = {
2444
+ action: "page_hit",
2445
+ version: "1",
2446
+ session_id: options.sessionId,
2447
+ visitor_id: options.visitorId,
2448
+ page_view_id: options.pageId,
2449
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
2450
+ payload: getBasePayload()
2451
+ };
2452
+ return sendMessage(message);
2453
+ },
2454
+ testResult: (options) => {
2455
+ const message = {
2456
+ action: "test_result",
2457
+ version: "1",
2458
+ session_id: options.sessionId,
2459
+ visitor_id: options.visitorId,
2460
+ page_view_id: options.pageId,
2461
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
2462
+ payload: {
2463
+ ...getBasePayload(),
2464
+ ...options
2465
+ }
2466
+ };
2467
+ return sendMessage(message);
2468
+ },
2469
+ personalizationResult: async (options) => {
2470
+ const messages = options.variantIds.map((variantId) => {
2471
+ const message = {
2472
+ action: "personalization_result",
2473
+ version: "1",
2474
+ session_id: options.sessionId,
2475
+ visitor_id: options.visitorId,
2476
+ page_view_id: options.pageId,
2477
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
2478
+ payload: {
2479
+ ...getBasePayload(),
2480
+ name: options.name,
2481
+ variantId,
2482
+ control: options.control,
2483
+ changed: options.changed
2484
+ }
2485
+ };
2486
+ return message;
2487
+ });
2488
+ await Promise.all(messages.map((message) => sendMessage(message)));
2489
+ },
2490
+ goalConvert: (options) => {
2491
+ const message = {
2492
+ action: "goal_convert",
2493
+ version: "1",
2494
+ session_id: options.sessionId,
2495
+ visitor_id: options.visitorId,
2496
+ page_view_id: options.pageId,
2497
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
2498
+ payload: {
2499
+ ...getBasePayload(),
2500
+ goalId: options.goalId
2501
+ }
2502
+ };
2503
+ return sendMessage(message);
2504
+ }
2505
+ };
2506
+ };
2507
+ var createInsightsStorage = () => {
2508
+ const STORAGE_KEY2 = "ufin";
2509
+ return {
2510
+ get: () => {
2511
+ const data = localStorage.getItem(STORAGE_KEY2);
2512
+ if (!data) {
2513
+ return;
2514
+ }
2515
+ return JSON.parse(data);
2516
+ },
2517
+ set: (data) => {
2518
+ const toSet = {
2519
+ ...data,
2520
+ updated: Date.now()
2521
+ };
2522
+ localStorage.setItem(STORAGE_KEY2, JSON.stringify(toSet));
2523
+ },
2524
+ clear: () => {
2525
+ localStorage.removeItem(STORAGE_KEY2);
2526
+ }
2527
+ };
2528
+ };
2529
+ var generateVisitorId = () => {
2530
+ return `visitor_${nanoid()}`;
2531
+ };
2532
+ var generateSessionId = () => {
2533
+ return `session_${nanoid()}`;
2534
+ };
2535
+ var generatePageId = () => {
2536
+ return `page_${nanoid()}`;
2537
+ };
2538
+ var createInsights = ({
2539
+ endpoint,
2540
+ sessionDurationSeconds = 30 * 60
2541
+ }) => {
2542
+ const client = createInsightsClient({
2543
+ endpoint
2544
+ });
2545
+ const storage = createInsightsStorage();
2546
+ let storageData = void 0;
2547
+ let pageId = generatePageId();
2548
+ return {
2549
+ init: () => {
2550
+ storageData = storage.get();
2551
+ if (!storageData || Date.now() - storageData.updated > sessionDurationSeconds * 1e3) {
2552
+ const previousSessionId = storageData == null ? void 0 : storageData.sessionId;
2553
+ storageData = {
2554
+ visitorId: (storageData == null ? void 0 : storageData.visitorId) || generateVisitorId(),
2555
+ sessionId: generateSessionId(),
2556
+ updated: Date.now()
2557
+ };
2558
+ storage.set(storageData);
2559
+ client.sessionStart({
2560
+ visitorId: storageData.visitorId,
2561
+ sessionId: storageData.sessionId,
2562
+ previousSessionId,
2563
+ maxAgeSeconds: sessionDurationSeconds,
2564
+ pageId
2565
+ });
2566
+ } else if (storageData) {
2567
+ storage.set(storageData);
2568
+ }
2569
+ },
2570
+ pageHit: () => {
2571
+ if (!storageData) {
2572
+ console.error("Insights not initialized");
2573
+ return;
2574
+ }
2575
+ client.pageHit({
2576
+ visitorId: storageData.visitorId,
2577
+ sessionId: storageData.sessionId,
2578
+ pageId
2579
+ });
2580
+ },
2581
+ testResult: (result) => {
2582
+ if (!storageData) {
2583
+ console.error("Insights not initialized");
2584
+ return;
2585
+ }
2586
+ client.testResult({
2587
+ ...result,
2588
+ visitorId: storageData.visitorId,
2589
+ sessionId: storageData.sessionId,
2590
+ pageId
2591
+ });
2592
+ pageId = generatePageId();
2593
+ },
2594
+ personalizationResult: (result) => {
2595
+ if (!storageData) {
2596
+ console.error("Insights not initialized");
2597
+ return;
2598
+ }
2599
+ client.personalizationResult({
2600
+ ...result,
2601
+ visitorId: storageData.visitorId,
2602
+ sessionId: storageData.sessionId,
2603
+ pageId
2604
+ });
2605
+ },
2606
+ goalConvert: (goalId) => {
2607
+ if (!storageData) {
2608
+ console.error("Insights not initialized");
2609
+ return;
2610
+ }
2611
+ client.goalConvert({
2612
+ visitorId: storageData.visitorId,
2613
+ sessionId: storageData.sessionId,
2614
+ goalId,
2615
+ pageId
2616
+ });
2617
+ },
2618
+ forget: () => {
2619
+ storage.clear();
2620
+ storageData = void 0;
2621
+ },
2622
+ get sessionId() {
2623
+ return storageData == null ? void 0 : storageData.sessionId;
2624
+ }
2625
+ };
2626
+ };
2627
+ var enableUniformInsights = (options) => {
2628
+ const insights = createInsights({
2629
+ endpoint: options.endpoint
2630
+ });
2631
+ return {
2632
+ init: (context) => {
2633
+ const consentChanged = () => {
2634
+ if (context.storage.data.consent) {
2635
+ insights.init();
2636
+ } else {
2637
+ insights.forget();
2638
+ }
2639
+ };
2640
+ const handlePersonalizationResult = (data) => {
2641
+ insights.personalizationResult(data);
2642
+ };
2643
+ const handleTestResult = (result) => {
2644
+ insights.testResult(result);
2645
+ };
2646
+ const handleGoalConvert = (result) => {
2647
+ insights.goalConvert(result.goalId);
2648
+ };
2649
+ context.storage.events.on("goalConverted", handleGoalConvert);
2650
+ context.storage.events.on("consentUpdated", consentChanged);
2651
+ context.events.on("personalizationResult", handlePersonalizationResult);
2652
+ context.events.on("testResult", handleTestResult);
2653
+ if (context.storage.data.consent) {
2654
+ consentChanged();
2655
+ }
2656
+ return () => {
2657
+ context.storage.events.off("consentUpdated", consentChanged);
2658
+ context.storage.events.off("goalConverted", handleGoalConvert);
2659
+ context.events.off("personalizationResult", handlePersonalizationResult);
2660
+ context.events.off("testResult", handleTestResult);
2661
+ };
2662
+ },
2663
+ update: (context) => {
2664
+ if (context.url) {
2665
+ insights.pageHit();
2666
+ }
2667
+ },
2668
+ forget: () => {
2669
+ insights.forget();
2670
+ }
2671
+ };
2672
+ };
2673
+
1750
2674
  // src/logging/enableConsoleLogDrain.ts
1751
2675
  import rfdc2 from "rfdc";
1752
2676
 
@@ -1950,6 +2874,7 @@ export {
1950
2874
  enableConsoleLogDrain,
1951
2875
  enableContextDevTools,
1952
2876
  enableDebugConsoleLogDrain,
2877
+ enableUniformInsights,
1953
2878
  evaluateVariantMatch,
1954
2879
  eventEvaluator,
1955
2880
  explainStringMatch,