@uniformdev/context 19.127.0 → 19.128.1-alpha.11

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.
@@ -1,4 +1,4 @@
1
- import { av as paths$7, N as ManifestV2 } from '../types-R41eD1zH.mjs';
1
+ import { ay as paths$7, N as ManifestV2 } from '../types-g61S1nwH.mjs';
2
2
  import 'mitt';
3
3
 
4
4
  type LimitPolicy = <ReturnValue>(func: () => Promise<ReturnValue>) => Promise<ReturnValue>;
package/dist/api/api.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { av as paths$7, N as ManifestV2 } from '../types-R41eD1zH.js';
1
+ import { ay as paths$7, N as ManifestV2 } from '../types-g61S1nwH.js';
2
2
  import 'mitt';
3
3
 
4
4
  type LimitPolicy = <ReturnValue>(func: () => Promise<ReturnValue>) => Promise<ReturnValue>;
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { O as OutputSeverity, L as LogDrain, C as ContextPlugin, S as ScoreVector, A as AggregateDimension, T as TransitionDataStore, a as StorageCommands, V as VisitorData, b as TransitionDataStoreOptions, D as DecayFunction, c as CriteriaEvaluator, d as StringMatch, e as VariantMatchCriteria, f as LogMessage, g as DevToolsEvents } from './types-R41eD1zH.mjs';
2
- export { _ as AggregateDimensionInput, a4 as BehaviorTag, h as CONTEXTUAL_EDITING_TEST_NAME, i as CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID, n as Context, l as ContextEvents, m as ContextInstance, j as ContextOptions, at as ContextState, au as ContextStateUpdate, J as CriteriaEvaluatorParameters, I as CriteriaEvaluatorResult, ak as DecayOptions, q as DevToolsActions, t as DevToolsDataEvent, r as DevToolsEvent, x as DevToolsForgetEvent, u as DevToolsHelloEvent, s as DevToolsLogEvent, w as DevToolsRawCommandsEvent, p as DevToolsState, o as DevToolsUiVersion, v as DevToolsUpdateEvent, a1 as DimensionMatch, X as EnrichmentCategory, aq as EnrichmentData, ar as EventData, H as GroupCriteriaEvaluator, af as IdentifyCommand, F as LogMessageGroup, E as LogMessageSingle, y as LogMessages, G as ManifestInstance, N as ManifestV2, M as MessageCategory, B as MessageFunc, aa as ModifyScoreCommand, ab as ModifySessionScoreCommand, Y as NumberMatch, P as PersonalizationEvent, Q as PersonalizationManifest, a2 as PersonalizeOptions, a6 as PersonalizedResult, a5 as PersonalizedVariant, ao as Quirks, ai as SERVER_STATE_ID, ah as ServerToClientTransitionState, ac as SetConsentCommand, ag as SetControlGroupCommand, ad as SetQuirkCommand, ae as SetTestCommand, z as Severity, R as Signal, W as SignalCriteria, U as SignalCriteriaGroup, K as SignalData, a9 as StorageCommand, Z as TestDefinition, k as TestEvent, $ as TestOptions, a8 as TestResult, a7 as TestVariant, ap as Tests, aj as TransitionDataStoreEvents, an as VisitorDataStore, am as VisitorDataStoreEvents, al as VisitorDataStoreOptions, as as emptyVisitorData, a3 as personalizeVariations, a0 as testVariations } from './types-R41eD1zH.mjs';
1
+ import { O as OutputSeverity, L as LogDrain, C as ContextPlugin, S as ScoreVector, A as AggregateDimension, T as TransitionDataStore, a as StorageCommands, V as VisitorData, b as TransitionDataStoreOptions, D as DecayFunction, c as CriteriaEvaluator, d as StringMatch, e as VariantMatchCriteria, f as LogMessage, g as DevToolsEvents } from './types-g61S1nwH.mjs';
2
+ export { _ as AggregateDimensionInput, a4 as BehaviorTag, h as CONTEXTUAL_EDITING_TEST_NAME, i as CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID, n as Context, l as ContextEvents, m as ContextInstance, j as ContextOptions, aw as ContextState, ax as ContextStateUpdate, J as CriteriaEvaluatorParameters, I as CriteriaEvaluatorResult, al as DecayOptions, q as DevToolsActions, t as DevToolsDataEvent, r as DevToolsEvent, x as DevToolsForgetEvent, u as DevToolsHelloEvent, s as DevToolsLogEvent, w as DevToolsRawCommandsEvent, p as DevToolsState, o as DevToolsUiVersion, v as DevToolsUpdateEvent, a1 as DimensionMatch, X as EnrichmentCategory, ar as EnrichmentData, au as EventData, H as GroupCriteriaEvaluator, af as IdentifyCommand, F as LogMessageGroup, E as LogMessageSingle, y as LogMessages, G as ManifestInstance, N as ManifestV2, M as MessageCategory, B as MessageFunc, aa as ModifyScoreCommand, ab as ModifySessionScoreCommand, Y as NumberMatch, P as PersonalizationEvent, Q as PersonalizationManifest, as as PersonalizeControlVariant, a2 as PersonalizeOptions, at as PersonalizeVariants, a6 as PersonalizedResult, a5 as PersonalizedVariant, ap as Quirks, aj as SERVER_STATE_ID, ai as ServerToClientTransitionState, ac as SetConsentCommand, ag as SetControlGroupCommand, ah as SetPersonalizeVariantControlCommand, ad as SetQuirkCommand, ae as SetTestCommand, z as Severity, R as Signal, W as SignalCriteria, U as SignalCriteriaGroup, K as SignalData, a9 as StorageCommand, Z as TestDefinition, k as TestEvent, $ as TestOptions, a8 as TestResult, a7 as TestVariant, aq as Tests, ak as TransitionDataStoreEvents, ao as VisitorDataStore, an as VisitorDataStoreEvents, am as VisitorDataStoreOptions, av as emptyVisitorData, a3 as personalizeVariations, a0 as testVariations } from './types-g61S1nwH.mjs';
3
3
  import Cookies from 'js-cookie';
4
4
  import 'mitt';
5
5
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { O as OutputSeverity, L as LogDrain, C as ContextPlugin, S as ScoreVector, A as AggregateDimension, T as TransitionDataStore, a as StorageCommands, V as VisitorData, b as TransitionDataStoreOptions, D as DecayFunction, c as CriteriaEvaluator, d as StringMatch, e as VariantMatchCriteria, f as LogMessage, g as DevToolsEvents } from './types-R41eD1zH.js';
2
- export { _ as AggregateDimensionInput, a4 as BehaviorTag, h as CONTEXTUAL_EDITING_TEST_NAME, i as CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID, n as Context, l as ContextEvents, m as ContextInstance, j as ContextOptions, at as ContextState, au as ContextStateUpdate, J as CriteriaEvaluatorParameters, I as CriteriaEvaluatorResult, ak as DecayOptions, q as DevToolsActions, t as DevToolsDataEvent, r as DevToolsEvent, x as DevToolsForgetEvent, u as DevToolsHelloEvent, s as DevToolsLogEvent, w as DevToolsRawCommandsEvent, p as DevToolsState, o as DevToolsUiVersion, v as DevToolsUpdateEvent, a1 as DimensionMatch, X as EnrichmentCategory, aq as EnrichmentData, ar as EventData, H as GroupCriteriaEvaluator, af as IdentifyCommand, F as LogMessageGroup, E as LogMessageSingle, y as LogMessages, G as ManifestInstance, N as ManifestV2, M as MessageCategory, B as MessageFunc, aa as ModifyScoreCommand, ab as ModifySessionScoreCommand, Y as NumberMatch, P as PersonalizationEvent, Q as PersonalizationManifest, a2 as PersonalizeOptions, a6 as PersonalizedResult, a5 as PersonalizedVariant, ao as Quirks, ai as SERVER_STATE_ID, ah as ServerToClientTransitionState, ac as SetConsentCommand, ag as SetControlGroupCommand, ad as SetQuirkCommand, ae as SetTestCommand, z as Severity, R as Signal, W as SignalCriteria, U as SignalCriteriaGroup, K as SignalData, a9 as StorageCommand, Z as TestDefinition, k as TestEvent, $ as TestOptions, a8 as TestResult, a7 as TestVariant, ap as Tests, aj as TransitionDataStoreEvents, an as VisitorDataStore, am as VisitorDataStoreEvents, al as VisitorDataStoreOptions, as as emptyVisitorData, a3 as personalizeVariations, a0 as testVariations } from './types-R41eD1zH.js';
1
+ import { O as OutputSeverity, L as LogDrain, C as ContextPlugin, S as ScoreVector, A as AggregateDimension, T as TransitionDataStore, a as StorageCommands, V as VisitorData, b as TransitionDataStoreOptions, D as DecayFunction, c as CriteriaEvaluator, d as StringMatch, e as VariantMatchCriteria, f as LogMessage, g as DevToolsEvents } from './types-g61S1nwH.js';
2
+ export { _ as AggregateDimensionInput, a4 as BehaviorTag, h as CONTEXTUAL_EDITING_TEST_NAME, i as CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID, n as Context, l as ContextEvents, m as ContextInstance, j as ContextOptions, aw as ContextState, ax as ContextStateUpdate, J as CriteriaEvaluatorParameters, I as CriteriaEvaluatorResult, al as DecayOptions, q as DevToolsActions, t as DevToolsDataEvent, r as DevToolsEvent, x as DevToolsForgetEvent, u as DevToolsHelloEvent, s as DevToolsLogEvent, w as DevToolsRawCommandsEvent, p as DevToolsState, o as DevToolsUiVersion, v as DevToolsUpdateEvent, a1 as DimensionMatch, X as EnrichmentCategory, ar as EnrichmentData, au as EventData, H as GroupCriteriaEvaluator, af as IdentifyCommand, F as LogMessageGroup, E as LogMessageSingle, y as LogMessages, G as ManifestInstance, N as ManifestV2, M as MessageCategory, B as MessageFunc, aa as ModifyScoreCommand, ab as ModifySessionScoreCommand, Y as NumberMatch, P as PersonalizationEvent, Q as PersonalizationManifest, as as PersonalizeControlVariant, a2 as PersonalizeOptions, at as PersonalizeVariants, a6 as PersonalizedResult, a5 as PersonalizedVariant, ap as Quirks, aj as SERVER_STATE_ID, ai as ServerToClientTransitionState, ac as SetConsentCommand, ag as SetControlGroupCommand, ah as SetPersonalizeVariantControlCommand, ad as SetQuirkCommand, ae as SetTestCommand, z as Severity, R as Signal, W as SignalCriteria, U as SignalCriteriaGroup, K as SignalData, a9 as StorageCommand, Z as TestDefinition, k as TestEvent, $ as TestOptions, a8 as TestResult, a7 as TestVariant, aq as Tests, ak as TransitionDataStoreEvents, ao as VisitorDataStore, an as VisitorDataStoreEvents, am as VisitorDataStoreOptions, av as emptyVisitorData, a3 as personalizeVariations, a0 as testVariations } from './types-g61S1nwH.js';
3
3
  import Cookies from 'js-cookie';
4
4
  import 'mitt';
5
5
 
package/dist/index.esm.js CHANGED
@@ -123,6 +123,15 @@ var SignalInstance = class {
123
123
  _evaluator = new WeakMap();
124
124
  _onLogMessage = new WeakMap();
125
125
 
126
+ // src/manifest/utils/control.ts
127
+ var rollForControlGroup = (value) => {
128
+ let control = value;
129
+ if (control >= 1) {
130
+ control = control / 100;
131
+ }
132
+ return Math.random() < control;
133
+ };
134
+
126
135
  // src/manifest/ManifestInstance.ts
127
136
  var _mf, _signalInstances, _onLogMessage2;
128
137
  var ManifestInstance = class {
@@ -146,12 +155,8 @@ var ManifestInstance = class {
146
155
  __privateSet(this, _onLogMessage2, onLogMessage);
147
156
  }
148
157
  rollForControlGroup() {
149
- var _a, _b;
150
- let control = (_b = (_a = __privateGet(this, _mf).pz) == null ? void 0 : _a.control) != null ? _b : 0;
151
- if (control >= 1) {
152
- control = control / 100;
153
- }
154
- return Math.random() < control;
158
+ var _a;
159
+ return rollForControlGroup(((_a = __privateGet(this, _mf).pz) == null ? void 0 : _a.control) || 0);
155
160
  }
156
161
  getTest(name) {
157
162
  var _a;
@@ -499,7 +504,30 @@ function evaluateDimensionMatch(crit, vec, onLogMessage) {
499
504
  var _a, _b;
500
505
  const { op, l: lhs } = crit;
501
506
  const lhsScore = (_a = vec[lhs]) != null ? _a : 0;
502
- if (op === "+") {
507
+ if (op === "^") {
508
+ const [cat] = lhs.split(ENR_SEPARATOR);
509
+ let topVectorName = void 0;
510
+ let topScore = 0;
511
+ Object.keys(vec).forEach((vectorName) => {
512
+ if (vectorName.startsWith(`${cat}${ENR_SEPARATOR}`)) {
513
+ const score = vec[vectorName];
514
+ if (score > topScore) {
515
+ topVectorName = vectorName;
516
+ topScore = score;
517
+ }
518
+ }
519
+ });
520
+ const result = topVectorName === lhs;
521
+ onLogMessage == null ? void 0 : onLogMessage([
522
+ "info",
523
+ 302,
524
+ {
525
+ matched: result,
526
+ description: `${crit.l} has the highest score in the category`
527
+ }
528
+ ]);
529
+ return result;
530
+ } else if (op === "+") {
503
531
  const result = Math.max(...Object.values(vec)) === lhsScore && lhsScore > 0;
504
532
  onLogMessage == null ? void 0 : onLogMessage([
505
533
  "info",
@@ -586,31 +614,69 @@ function personalizeVariations({
586
614
  take = 1,
587
615
  onLogMessage
588
616
  }) {
589
- var _a, _b, _c;
617
+ var _a, _b, _c, _d, _e;
590
618
  onLogMessage == null ? void 0 : onLogMessage(["info", 300, "GROUP", { name, take }]);
591
619
  try {
592
620
  const control = (_a = context.storage.data.controlGroup) != null ? _a : false;
593
621
  const results = [];
594
622
  let personalized = false;
595
623
  const scores = context.scores;
624
+ let index = 0;
625
+ const defaultVariants = [];
626
+ for (const variant of variations) {
627
+ if (!((_b = variant.pz) == null ? void 0 : _b.crit.length)) {
628
+ defaultVariants.push(variant);
629
+ }
630
+ }
596
631
  for (const variant of variations) {
632
+ const currentIndex = index++;
597
633
  if (results.length === take) {
598
634
  break;
599
635
  }
600
- if (!((_b = variant.pz) == null ? void 0 : _b.crit.length)) {
601
- onLogMessage == null ? void 0 : onLogMessage(["info", 301, "GROUP", { id: variant.id, op: (_c = variant.pz) == null ? void 0 : _c.op }]);
636
+ if (!((_c = variant.pz) == null ? void 0 : _c.crit.length)) {
637
+ onLogMessage == null ? void 0 : onLogMessage(["info", 301, "GROUP", { id: variant.id, op: (_d = variant.pz) == null ? void 0 : _d.op }]);
602
638
  onLogMessage == null ? void 0 : onLogMessage(["info", 302, { matched: true, description: "default variation" }]);
603
639
  onLogMessage == null ? void 0 : onLogMessage(["info", 303, true]);
604
640
  onLogMessage == null ? void 0 : onLogMessage(["info", 301, "ENDGROUP"]);
605
- results.push(variant);
641
+ results.push({
642
+ ...variant,
643
+ control: false
644
+ });
606
645
  continue;
607
646
  }
608
647
  if (control) {
609
648
  continue;
610
649
  }
611
650
  if (evaluateVariantMatch(variant.id, variant.pz, scores, onLogMessage)) {
612
- personalized = true;
613
- results.push(variant);
651
+ let variantToAdd = variant;
652
+ let isControl = false;
653
+ if (take === 1 && defaultVariants.length && typeof variant.pz.control === "number") {
654
+ const testVariants = (_e = context.storage.data.personalizeVariants) == null ? void 0 : _e[name];
655
+ const entry = testVariants == null ? void 0 : testVariants.find((v) => v.index === currentIndex);
656
+ if (typeof entry !== "undefined") {
657
+ isControl = entry.control;
658
+ } else {
659
+ isControl = rollForControlGroup(variant.pz.control);
660
+ context.storage.updateData([
661
+ {
662
+ type: "setpersonalizecontrol",
663
+ data: {
664
+ personlizationName: name,
665
+ index: currentIndex,
666
+ control: isControl
667
+ }
668
+ }
669
+ ]);
670
+ }
671
+ if (isControl) {
672
+ variantToAdd = defaultVariants[0];
673
+ }
674
+ }
675
+ personalized = variant.id === variantToAdd.id;
676
+ results.push({
677
+ ...variantToAdd,
678
+ control: isControl
679
+ });
614
680
  }
615
681
  }
616
682
  return {
@@ -857,16 +923,19 @@ function parseScoreCookie(cookieValue) {
857
923
  if (!cookieValue)
858
924
  return;
859
925
  const types = cookieValue.split(TYPE_SEP);
860
- if (types.length > 3)
926
+ if (types.length > 5)
861
927
  return;
862
- const [abTestData, sessionScores, visitorScores] = types;
863
- return {
928
+ const [abTestData, sessionScores, visitorScores, controlGroup, personalizeVariants] = types;
929
+ const data = {
864
930
  // this is true since we're reading a cookie, which wouldn't exist if consent wasn't given
865
931
  consent: true,
866
932
  sessionScores: decodeCookieType(parseCookieType(sessionScores)),
867
933
  scores: decodeCookieType(parseCookieType(visitorScores)),
868
- tests: parseCookieType(abTestData)
934
+ tests: parseCookieType(abTestData),
935
+ controlGroup: controlGroup === "1",
936
+ personalizeVariants: decodePersonalizeVariants(personalizeVariants)
869
937
  };
938
+ return data;
870
939
  }
871
940
  function parseCookieType(type) {
872
941
  if (!type) {
@@ -890,9 +959,47 @@ function serializeCookie(data) {
890
959
  return [
891
960
  serializeCookieType(data.tests),
892
961
  serializeCookieType(encodeCookieType(data.sessionScores)),
893
- serializeCookieType(encodeCookieType(data.scores))
962
+ serializeCookieType(encodeCookieType(data.scores)),
963
+ data.controlGroup ? "1" : "0",
964
+ serializePersonalizeVariants(data)
894
965
  ].join(TYPE_SEP);
895
966
  }
967
+ function serializePersonalizeVariants({
968
+ personalizeVariants
969
+ }) {
970
+ const data = {};
971
+ if (typeof personalizeVariants === "object") {
972
+ Object.keys(personalizeVariants).forEach((personalizationName) => {
973
+ const results = [];
974
+ const variants = personalizeVariants[personalizationName];
975
+ variants.forEach((variant) => {
976
+ results.push(`${variant.index}:${variant.control ? "1" : "0"}`);
977
+ });
978
+ data[personalizationName] = results.join(",");
979
+ });
980
+ }
981
+ const serialized = serializeCookieType(data);
982
+ return serialized;
983
+ }
984
+ function decodePersonalizeVariants(data) {
985
+ const parsed = parseCookieType(data);
986
+ const keys = Object.keys(parsed);
987
+ if (!keys.length) {
988
+ return void 0;
989
+ }
990
+ const results = {};
991
+ Object.keys(parsed).forEach((key) => {
992
+ const variants = parsed[key].split(",");
993
+ results[key] = variants.map((variant) => {
994
+ const [index, control] = variant.split(":");
995
+ return {
996
+ index: parseInt(index, 10),
997
+ control: control === "1"
998
+ };
999
+ });
1000
+ });
1001
+ return results;
1002
+ }
896
1003
  function encodeCookieType(type) {
897
1004
  return Object.entries(type).reduce((acc, [key, value]) => {
898
1005
  acc[key] = ntob(value);
@@ -980,7 +1087,8 @@ var emptyVisitorData = () => ({
980
1087
  sessionScores: {},
981
1088
  tests: {},
982
1089
  consent: false,
983
- controlGroup: false
1090
+ controlGroup: false,
1091
+ personalizeVariants: {}
984
1092
  });
985
1093
 
986
1094
  // src/storage/VisitorDataStore.ts
@@ -1029,6 +1137,26 @@ function applyCommandsToData(commands, state, inControlGroup) {
1029
1137
  case "setcontrol":
1030
1138
  newData.controlGroup = command.data;
1031
1139
  break;
1140
+ case "setpersonalizecontrol":
1141
+ if (!newData.personalizeVariants) {
1142
+ newData.personalizeVariants = {};
1143
+ }
1144
+ if (!newData.personalizeVariants[command.data.personlizationName]) {
1145
+ newData.personalizeVariants[command.data.personlizationName] = [];
1146
+ }
1147
+ const existingDef = newData.personalizeVariants[command.data.personlizationName].find(
1148
+ (i) => i.index === command.data.index
1149
+ );
1150
+ if (!existingDef) {
1151
+ const newDef = {
1152
+ index: command.data.index,
1153
+ control: command.data.control
1154
+ };
1155
+ newData.personalizeVariants[command.data.personlizationName].push(newDef);
1156
+ } else if (existingDef.control !== command.data.control) {
1157
+ existingDef.control = command.data.control;
1158
+ }
1159
+ break;
1032
1160
  default:
1033
1161
  throw new Error(`Unknown command`);
1034
1162
  }
@@ -1553,10 +1681,10 @@ var Context = class {
1553
1681
  const previousPlacement = __privateGet(this, _pzCache)[options.name];
1554
1682
  const eventData = {
1555
1683
  name: options.name,
1556
- variantIds: value.variations.map((variation) => {
1557
- var _a;
1558
- return (_a = variation.id) != null ? _a : "Unknown";
1559
- }),
1684
+ variantIds: value.variations.map((variation) => ({
1685
+ id: variation.id || "Unknown",
1686
+ control: variation.control
1687
+ })),
1560
1688
  control: this.storage.data.controlGroup,
1561
1689
  changed: true
1562
1690
  };
@@ -1584,7 +1712,8 @@ var Context = class {
1584
1712
  const transitionState = {
1585
1713
  quirks: this.storage.data.quirks,
1586
1714
  ssv: __privateGet(this, _scores),
1587
- tests: {}
1715
+ tests: {},
1716
+ personalizeVariants: this.storage.data.personalizeVariants
1588
1717
  };
1589
1718
  const allTests = this.storage.data.tests;
1590
1719
  Object.entries(allTests).map(([testName, testValue]) => {
package/dist/index.js CHANGED
@@ -193,6 +193,15 @@ var SignalInstance = class {
193
193
  _evaluator = new WeakMap();
194
194
  _onLogMessage = new WeakMap();
195
195
 
196
+ // src/manifest/utils/control.ts
197
+ var rollForControlGroup = (value) => {
198
+ let control = value;
199
+ if (control >= 1) {
200
+ control = control / 100;
201
+ }
202
+ return Math.random() < control;
203
+ };
204
+
196
205
  // src/manifest/ManifestInstance.ts
197
206
  var _mf, _signalInstances, _onLogMessage2;
198
207
  var ManifestInstance = class {
@@ -216,12 +225,8 @@ var ManifestInstance = class {
216
225
  __privateSet(this, _onLogMessage2, onLogMessage);
217
226
  }
218
227
  rollForControlGroup() {
219
- var _a, _b;
220
- let control = (_b = (_a = __privateGet(this, _mf).pz) == null ? void 0 : _a.control) != null ? _b : 0;
221
- if (control >= 1) {
222
- control = control / 100;
223
- }
224
- return Math.random() < control;
228
+ var _a;
229
+ return rollForControlGroup(((_a = __privateGet(this, _mf).pz) == null ? void 0 : _a.control) || 0);
225
230
  }
226
231
  getTest(name) {
227
232
  var _a;
@@ -569,7 +574,30 @@ function evaluateDimensionMatch(crit, vec, onLogMessage) {
569
574
  var _a, _b;
570
575
  const { op, l: lhs } = crit;
571
576
  const lhsScore = (_a = vec[lhs]) != null ? _a : 0;
572
- if (op === "+") {
577
+ if (op === "^") {
578
+ const [cat] = lhs.split(ENR_SEPARATOR);
579
+ let topVectorName = void 0;
580
+ let topScore = 0;
581
+ Object.keys(vec).forEach((vectorName) => {
582
+ if (vectorName.startsWith(`${cat}${ENR_SEPARATOR}`)) {
583
+ const score = vec[vectorName];
584
+ if (score > topScore) {
585
+ topVectorName = vectorName;
586
+ topScore = score;
587
+ }
588
+ }
589
+ });
590
+ const result = topVectorName === lhs;
591
+ onLogMessage == null ? void 0 : onLogMessage([
592
+ "info",
593
+ 302,
594
+ {
595
+ matched: result,
596
+ description: `${crit.l} has the highest score in the category`
597
+ }
598
+ ]);
599
+ return result;
600
+ } else if (op === "+") {
573
601
  const result = Math.max(...Object.values(vec)) === lhsScore && lhsScore > 0;
574
602
  onLogMessage == null ? void 0 : onLogMessage([
575
603
  "info",
@@ -656,31 +684,69 @@ function personalizeVariations({
656
684
  take = 1,
657
685
  onLogMessage
658
686
  }) {
659
- var _a, _b, _c;
687
+ var _a, _b, _c, _d, _e;
660
688
  onLogMessage == null ? void 0 : onLogMessage(["info", 300, "GROUP", { name, take }]);
661
689
  try {
662
690
  const control = (_a = context.storage.data.controlGroup) != null ? _a : false;
663
691
  const results = [];
664
692
  let personalized = false;
665
693
  const scores = context.scores;
694
+ let index = 0;
695
+ const defaultVariants = [];
696
+ for (const variant of variations) {
697
+ if (!((_b = variant.pz) == null ? void 0 : _b.crit.length)) {
698
+ defaultVariants.push(variant);
699
+ }
700
+ }
666
701
  for (const variant of variations) {
702
+ const currentIndex = index++;
667
703
  if (results.length === take) {
668
704
  break;
669
705
  }
670
- if (!((_b = variant.pz) == null ? void 0 : _b.crit.length)) {
671
- onLogMessage == null ? void 0 : onLogMessage(["info", 301, "GROUP", { id: variant.id, op: (_c = variant.pz) == null ? void 0 : _c.op }]);
706
+ if (!((_c = variant.pz) == null ? void 0 : _c.crit.length)) {
707
+ onLogMessage == null ? void 0 : onLogMessage(["info", 301, "GROUP", { id: variant.id, op: (_d = variant.pz) == null ? void 0 : _d.op }]);
672
708
  onLogMessage == null ? void 0 : onLogMessage(["info", 302, { matched: true, description: "default variation" }]);
673
709
  onLogMessage == null ? void 0 : onLogMessage(["info", 303, true]);
674
710
  onLogMessage == null ? void 0 : onLogMessage(["info", 301, "ENDGROUP"]);
675
- results.push(variant);
711
+ results.push({
712
+ ...variant,
713
+ control: false
714
+ });
676
715
  continue;
677
716
  }
678
717
  if (control) {
679
718
  continue;
680
719
  }
681
720
  if (evaluateVariantMatch(variant.id, variant.pz, scores, onLogMessage)) {
682
- personalized = true;
683
- results.push(variant);
721
+ let variantToAdd = variant;
722
+ let isControl = false;
723
+ if (take === 1 && defaultVariants.length && typeof variant.pz.control === "number") {
724
+ const testVariants = (_e = context.storage.data.personalizeVariants) == null ? void 0 : _e[name];
725
+ const entry = testVariants == null ? void 0 : testVariants.find((v) => v.index === currentIndex);
726
+ if (typeof entry !== "undefined") {
727
+ isControl = entry.control;
728
+ } else {
729
+ isControl = rollForControlGroup(variant.pz.control);
730
+ context.storage.updateData([
731
+ {
732
+ type: "setpersonalizecontrol",
733
+ data: {
734
+ personlizationName: name,
735
+ index: currentIndex,
736
+ control: isControl
737
+ }
738
+ }
739
+ ]);
740
+ }
741
+ if (isControl) {
742
+ variantToAdd = defaultVariants[0];
743
+ }
744
+ }
745
+ personalized = variant.id === variantToAdd.id;
746
+ results.push({
747
+ ...variantToAdd,
748
+ control: isControl
749
+ });
684
750
  }
685
751
  }
686
752
  return {
@@ -927,16 +993,19 @@ function parseScoreCookie(cookieValue) {
927
993
  if (!cookieValue)
928
994
  return;
929
995
  const types = cookieValue.split(TYPE_SEP);
930
- if (types.length > 3)
996
+ if (types.length > 5)
931
997
  return;
932
- const [abTestData, sessionScores, visitorScores] = types;
933
- return {
998
+ const [abTestData, sessionScores, visitorScores, controlGroup, personalizeVariants] = types;
999
+ const data = {
934
1000
  // this is true since we're reading a cookie, which wouldn't exist if consent wasn't given
935
1001
  consent: true,
936
1002
  sessionScores: decodeCookieType(parseCookieType(sessionScores)),
937
1003
  scores: decodeCookieType(parseCookieType(visitorScores)),
938
- tests: parseCookieType(abTestData)
1004
+ tests: parseCookieType(abTestData),
1005
+ controlGroup: controlGroup === "1",
1006
+ personalizeVariants: decodePersonalizeVariants(personalizeVariants)
939
1007
  };
1008
+ return data;
940
1009
  }
941
1010
  function parseCookieType(type) {
942
1011
  if (!type) {
@@ -960,9 +1029,47 @@ function serializeCookie(data) {
960
1029
  return [
961
1030
  serializeCookieType(data.tests),
962
1031
  serializeCookieType(encodeCookieType(data.sessionScores)),
963
- serializeCookieType(encodeCookieType(data.scores))
1032
+ serializeCookieType(encodeCookieType(data.scores)),
1033
+ data.controlGroup ? "1" : "0",
1034
+ serializePersonalizeVariants(data)
964
1035
  ].join(TYPE_SEP);
965
1036
  }
1037
+ function serializePersonalizeVariants({
1038
+ personalizeVariants
1039
+ }) {
1040
+ const data = {};
1041
+ if (typeof personalizeVariants === "object") {
1042
+ Object.keys(personalizeVariants).forEach((personalizationName) => {
1043
+ const results = [];
1044
+ const variants = personalizeVariants[personalizationName];
1045
+ variants.forEach((variant) => {
1046
+ results.push(`${variant.index}:${variant.control ? "1" : "0"}`);
1047
+ });
1048
+ data[personalizationName] = results.join(",");
1049
+ });
1050
+ }
1051
+ const serialized = serializeCookieType(data);
1052
+ return serialized;
1053
+ }
1054
+ function decodePersonalizeVariants(data) {
1055
+ const parsed = parseCookieType(data);
1056
+ const keys = Object.keys(parsed);
1057
+ if (!keys.length) {
1058
+ return void 0;
1059
+ }
1060
+ const results = {};
1061
+ Object.keys(parsed).forEach((key) => {
1062
+ const variants = parsed[key].split(",");
1063
+ results[key] = variants.map((variant) => {
1064
+ const [index, control] = variant.split(":");
1065
+ return {
1066
+ index: parseInt(index, 10),
1067
+ control: control === "1"
1068
+ };
1069
+ });
1070
+ });
1071
+ return results;
1072
+ }
966
1073
  function encodeCookieType(type) {
967
1074
  return Object.entries(type).reduce((acc, [key, value]) => {
968
1075
  acc[key] = ntob(value);
@@ -1050,7 +1157,8 @@ var emptyVisitorData = () => ({
1050
1157
  sessionScores: {},
1051
1158
  tests: {},
1052
1159
  consent: false,
1053
- controlGroup: false
1160
+ controlGroup: false,
1161
+ personalizeVariants: {}
1054
1162
  });
1055
1163
 
1056
1164
  // src/storage/VisitorDataStore.ts
@@ -1099,6 +1207,26 @@ function applyCommandsToData(commands, state, inControlGroup) {
1099
1207
  case "setcontrol":
1100
1208
  newData.controlGroup = command.data;
1101
1209
  break;
1210
+ case "setpersonalizecontrol":
1211
+ if (!newData.personalizeVariants) {
1212
+ newData.personalizeVariants = {};
1213
+ }
1214
+ if (!newData.personalizeVariants[command.data.personlizationName]) {
1215
+ newData.personalizeVariants[command.data.personlizationName] = [];
1216
+ }
1217
+ const existingDef = newData.personalizeVariants[command.data.personlizationName].find(
1218
+ (i) => i.index === command.data.index
1219
+ );
1220
+ if (!existingDef) {
1221
+ const newDef = {
1222
+ index: command.data.index,
1223
+ control: command.data.control
1224
+ };
1225
+ newData.personalizeVariants[command.data.personlizationName].push(newDef);
1226
+ } else if (existingDef.control !== command.data.control) {
1227
+ existingDef.control = command.data.control;
1228
+ }
1229
+ break;
1102
1230
  default:
1103
1231
  throw new Error(`Unknown command`);
1104
1232
  }
@@ -1623,10 +1751,10 @@ var Context = class {
1623
1751
  const previousPlacement = __privateGet(this, _pzCache)[options.name];
1624
1752
  const eventData = {
1625
1753
  name: options.name,
1626
- variantIds: value.variations.map((variation) => {
1627
- var _a;
1628
- return (_a = variation.id) != null ? _a : "Unknown";
1629
- }),
1754
+ variantIds: value.variations.map((variation) => ({
1755
+ id: variation.id || "Unknown",
1756
+ control: variation.control
1757
+ })),
1630
1758
  control: this.storage.data.controlGroup,
1631
1759
  changed: true
1632
1760
  };
@@ -1654,7 +1782,8 @@ var Context = class {
1654
1782
  const transitionState = {
1655
1783
  quirks: this.storage.data.quirks,
1656
1784
  ssv: __privateGet(this, _scores),
1657
- tests: {}
1785
+ tests: {},
1786
+ personalizeVariants: this.storage.data.personalizeVariants
1658
1787
  };
1659
1788
  const allTests = this.storage.data.tests;
1660
1789
  Object.entries(allTests).map(([testName, testValue]) => {
package/dist/index.mjs CHANGED
@@ -123,6 +123,15 @@ var SignalInstance = class {
123
123
  _evaluator = new WeakMap();
124
124
  _onLogMessage = new WeakMap();
125
125
 
126
+ // src/manifest/utils/control.ts
127
+ var rollForControlGroup = (value) => {
128
+ let control = value;
129
+ if (control >= 1) {
130
+ control = control / 100;
131
+ }
132
+ return Math.random() < control;
133
+ };
134
+
126
135
  // src/manifest/ManifestInstance.ts
127
136
  var _mf, _signalInstances, _onLogMessage2;
128
137
  var ManifestInstance = class {
@@ -146,12 +155,8 @@ var ManifestInstance = class {
146
155
  __privateSet(this, _onLogMessage2, onLogMessage);
147
156
  }
148
157
  rollForControlGroup() {
149
- var _a, _b;
150
- let control = (_b = (_a = __privateGet(this, _mf).pz) == null ? void 0 : _a.control) != null ? _b : 0;
151
- if (control >= 1) {
152
- control = control / 100;
153
- }
154
- return Math.random() < control;
158
+ var _a;
159
+ return rollForControlGroup(((_a = __privateGet(this, _mf).pz) == null ? void 0 : _a.control) || 0);
155
160
  }
156
161
  getTest(name) {
157
162
  var _a;
@@ -499,7 +504,30 @@ function evaluateDimensionMatch(crit, vec, onLogMessage) {
499
504
  var _a, _b;
500
505
  const { op, l: lhs } = crit;
501
506
  const lhsScore = (_a = vec[lhs]) != null ? _a : 0;
502
- if (op === "+") {
507
+ if (op === "^") {
508
+ const [cat] = lhs.split(ENR_SEPARATOR);
509
+ let topVectorName = void 0;
510
+ let topScore = 0;
511
+ Object.keys(vec).forEach((vectorName) => {
512
+ if (vectorName.startsWith(`${cat}${ENR_SEPARATOR}`)) {
513
+ const score = vec[vectorName];
514
+ if (score > topScore) {
515
+ topVectorName = vectorName;
516
+ topScore = score;
517
+ }
518
+ }
519
+ });
520
+ const result = topVectorName === lhs;
521
+ onLogMessage == null ? void 0 : onLogMessage([
522
+ "info",
523
+ 302,
524
+ {
525
+ matched: result,
526
+ description: `${crit.l} has the highest score in the category`
527
+ }
528
+ ]);
529
+ return result;
530
+ } else if (op === "+") {
503
531
  const result = Math.max(...Object.values(vec)) === lhsScore && lhsScore > 0;
504
532
  onLogMessage == null ? void 0 : onLogMessage([
505
533
  "info",
@@ -586,31 +614,69 @@ function personalizeVariations({
586
614
  take = 1,
587
615
  onLogMessage
588
616
  }) {
589
- var _a, _b, _c;
617
+ var _a, _b, _c, _d, _e;
590
618
  onLogMessage == null ? void 0 : onLogMessage(["info", 300, "GROUP", { name, take }]);
591
619
  try {
592
620
  const control = (_a = context.storage.data.controlGroup) != null ? _a : false;
593
621
  const results = [];
594
622
  let personalized = false;
595
623
  const scores = context.scores;
624
+ let index = 0;
625
+ const defaultVariants = [];
626
+ for (const variant of variations) {
627
+ if (!((_b = variant.pz) == null ? void 0 : _b.crit.length)) {
628
+ defaultVariants.push(variant);
629
+ }
630
+ }
596
631
  for (const variant of variations) {
632
+ const currentIndex = index++;
597
633
  if (results.length === take) {
598
634
  break;
599
635
  }
600
- if (!((_b = variant.pz) == null ? void 0 : _b.crit.length)) {
601
- onLogMessage == null ? void 0 : onLogMessage(["info", 301, "GROUP", { id: variant.id, op: (_c = variant.pz) == null ? void 0 : _c.op }]);
636
+ if (!((_c = variant.pz) == null ? void 0 : _c.crit.length)) {
637
+ onLogMessage == null ? void 0 : onLogMessage(["info", 301, "GROUP", { id: variant.id, op: (_d = variant.pz) == null ? void 0 : _d.op }]);
602
638
  onLogMessage == null ? void 0 : onLogMessage(["info", 302, { matched: true, description: "default variation" }]);
603
639
  onLogMessage == null ? void 0 : onLogMessage(["info", 303, true]);
604
640
  onLogMessage == null ? void 0 : onLogMessage(["info", 301, "ENDGROUP"]);
605
- results.push(variant);
641
+ results.push({
642
+ ...variant,
643
+ control: false
644
+ });
606
645
  continue;
607
646
  }
608
647
  if (control) {
609
648
  continue;
610
649
  }
611
650
  if (evaluateVariantMatch(variant.id, variant.pz, scores, onLogMessage)) {
612
- personalized = true;
613
- results.push(variant);
651
+ let variantToAdd = variant;
652
+ let isControl = false;
653
+ if (take === 1 && defaultVariants.length && typeof variant.pz.control === "number") {
654
+ const testVariants = (_e = context.storage.data.personalizeVariants) == null ? void 0 : _e[name];
655
+ const entry = testVariants == null ? void 0 : testVariants.find((v) => v.index === currentIndex);
656
+ if (typeof entry !== "undefined") {
657
+ isControl = entry.control;
658
+ } else {
659
+ isControl = rollForControlGroup(variant.pz.control);
660
+ context.storage.updateData([
661
+ {
662
+ type: "setpersonalizecontrol",
663
+ data: {
664
+ personlizationName: name,
665
+ index: currentIndex,
666
+ control: isControl
667
+ }
668
+ }
669
+ ]);
670
+ }
671
+ if (isControl) {
672
+ variantToAdd = defaultVariants[0];
673
+ }
674
+ }
675
+ personalized = variant.id === variantToAdd.id;
676
+ results.push({
677
+ ...variantToAdd,
678
+ control: isControl
679
+ });
614
680
  }
615
681
  }
616
682
  return {
@@ -857,16 +923,19 @@ function parseScoreCookie(cookieValue) {
857
923
  if (!cookieValue)
858
924
  return;
859
925
  const types = cookieValue.split(TYPE_SEP);
860
- if (types.length > 3)
926
+ if (types.length > 5)
861
927
  return;
862
- const [abTestData, sessionScores, visitorScores] = types;
863
- return {
928
+ const [abTestData, sessionScores, visitorScores, controlGroup, personalizeVariants] = types;
929
+ const data = {
864
930
  // this is true since we're reading a cookie, which wouldn't exist if consent wasn't given
865
931
  consent: true,
866
932
  sessionScores: decodeCookieType(parseCookieType(sessionScores)),
867
933
  scores: decodeCookieType(parseCookieType(visitorScores)),
868
- tests: parseCookieType(abTestData)
934
+ tests: parseCookieType(abTestData),
935
+ controlGroup: controlGroup === "1",
936
+ personalizeVariants: decodePersonalizeVariants(personalizeVariants)
869
937
  };
938
+ return data;
870
939
  }
871
940
  function parseCookieType(type) {
872
941
  if (!type) {
@@ -890,9 +959,47 @@ function serializeCookie(data) {
890
959
  return [
891
960
  serializeCookieType(data.tests),
892
961
  serializeCookieType(encodeCookieType(data.sessionScores)),
893
- serializeCookieType(encodeCookieType(data.scores))
962
+ serializeCookieType(encodeCookieType(data.scores)),
963
+ data.controlGroup ? "1" : "0",
964
+ serializePersonalizeVariants(data)
894
965
  ].join(TYPE_SEP);
895
966
  }
967
+ function serializePersonalizeVariants({
968
+ personalizeVariants
969
+ }) {
970
+ const data = {};
971
+ if (typeof personalizeVariants === "object") {
972
+ Object.keys(personalizeVariants).forEach((personalizationName) => {
973
+ const results = [];
974
+ const variants = personalizeVariants[personalizationName];
975
+ variants.forEach((variant) => {
976
+ results.push(`${variant.index}:${variant.control ? "1" : "0"}`);
977
+ });
978
+ data[personalizationName] = results.join(",");
979
+ });
980
+ }
981
+ const serialized = serializeCookieType(data);
982
+ return serialized;
983
+ }
984
+ function decodePersonalizeVariants(data) {
985
+ const parsed = parseCookieType(data);
986
+ const keys = Object.keys(parsed);
987
+ if (!keys.length) {
988
+ return void 0;
989
+ }
990
+ const results = {};
991
+ Object.keys(parsed).forEach((key) => {
992
+ const variants = parsed[key].split(",");
993
+ results[key] = variants.map((variant) => {
994
+ const [index, control] = variant.split(":");
995
+ return {
996
+ index: parseInt(index, 10),
997
+ control: control === "1"
998
+ };
999
+ });
1000
+ });
1001
+ return results;
1002
+ }
896
1003
  function encodeCookieType(type) {
897
1004
  return Object.entries(type).reduce((acc, [key, value]) => {
898
1005
  acc[key] = ntob(value);
@@ -980,7 +1087,8 @@ var emptyVisitorData = () => ({
980
1087
  sessionScores: {},
981
1088
  tests: {},
982
1089
  consent: false,
983
- controlGroup: false
1090
+ controlGroup: false,
1091
+ personalizeVariants: {}
984
1092
  });
985
1093
 
986
1094
  // src/storage/VisitorDataStore.ts
@@ -1029,6 +1137,26 @@ function applyCommandsToData(commands, state, inControlGroup) {
1029
1137
  case "setcontrol":
1030
1138
  newData.controlGroup = command.data;
1031
1139
  break;
1140
+ case "setpersonalizecontrol":
1141
+ if (!newData.personalizeVariants) {
1142
+ newData.personalizeVariants = {};
1143
+ }
1144
+ if (!newData.personalizeVariants[command.data.personlizationName]) {
1145
+ newData.personalizeVariants[command.data.personlizationName] = [];
1146
+ }
1147
+ const existingDef = newData.personalizeVariants[command.data.personlizationName].find(
1148
+ (i) => i.index === command.data.index
1149
+ );
1150
+ if (!existingDef) {
1151
+ const newDef = {
1152
+ index: command.data.index,
1153
+ control: command.data.control
1154
+ };
1155
+ newData.personalizeVariants[command.data.personlizationName].push(newDef);
1156
+ } else if (existingDef.control !== command.data.control) {
1157
+ existingDef.control = command.data.control;
1158
+ }
1159
+ break;
1032
1160
  default:
1033
1161
  throw new Error(`Unknown command`);
1034
1162
  }
@@ -1553,10 +1681,10 @@ var Context = class {
1553
1681
  const previousPlacement = __privateGet(this, _pzCache)[options.name];
1554
1682
  const eventData = {
1555
1683
  name: options.name,
1556
- variantIds: value.variations.map((variation) => {
1557
- var _a;
1558
- return (_a = variation.id) != null ? _a : "Unknown";
1559
- }),
1684
+ variantIds: value.variations.map((variation) => ({
1685
+ id: variation.id || "Unknown",
1686
+ control: variation.control
1687
+ })),
1560
1688
  control: this.storage.data.controlGroup,
1561
1689
  changed: true
1562
1690
  };
@@ -1584,7 +1712,8 @@ var Context = class {
1584
1712
  const transitionState = {
1585
1713
  quirks: this.storage.data.quirks,
1586
1714
  ssv: __privateGet(this, _scores),
1587
- tests: {}
1715
+ tests: {},
1716
+ personalizeVariants: this.storage.data.personalizeVariants
1588
1717
  };
1589
1718
  const allTests = this.storage.data.tests;
1590
1719
  Object.entries(allTests).map(([testName, testValue]) => {
@@ -17,6 +17,13 @@ type EnrichmentData = {
17
17
  /** Strength value (amount of score added when viewing content) */
18
18
  str: number;
19
19
  };
20
+ type PersonalizeControlVariant = {
21
+ index: number;
22
+ control: boolean;
23
+ };
24
+ type PersonalizeVariants = {
25
+ [key: string]: PersonalizeControlVariant[];
26
+ };
20
27
  /** An event that has occurred (i.e. an analytics track) which may trigger an Event signal */
21
28
  type EventData = {
22
29
  /** The event name that has been fired */
@@ -55,6 +62,10 @@ type VisitorData = {
55
62
  * based on the control group size.
56
63
  */
57
64
  controlGroup?: boolean;
65
+ /**
66
+ * Records of personalized variants that have been shown to the visitor and their control group status
67
+ */
68
+ personalizeVariants?: PersonalizeVariants;
58
69
  };
59
70
  declare const emptyVisitorData: () => VisitorData;
60
71
  /**
@@ -79,7 +90,7 @@ type StorageCommand<TID extends string = string, TData = unknown> = {
79
90
  data: TData;
80
91
  };
81
92
  /** Commands that can be issued to alter the storage of Uniform Context data */
82
- type StorageCommands = ModifyScoreCommand | ModifySessionScoreCommand | SetConsentCommand | SetQuirkCommand | SetTestCommand | IdentifyCommand | SetControlGroupCommand;
93
+ type StorageCommands = ModifyScoreCommand | ModifySessionScoreCommand | SetConsentCommand | SetQuirkCommand | SetTestCommand | IdentifyCommand | SetControlGroupCommand | SetPersonalizeVariantControlCommand;
83
94
  /**
84
95
  * Changes the visitor's permanent score for a given dimension
85
96
  */
@@ -125,11 +136,16 @@ type IdentifyCommand = StorageCommand<'identify', {
125
136
  * this command is intended mostly for diagnostics and testing purposes.
126
137
  */
127
138
  type SetControlGroupCommand = StorageCommand<'setcontrol', boolean>;
139
+ type SetPersonalizeVariantControlCommand = StorageCommand<'setpersonalizecontrol', {
140
+ personlizationName: string;
141
+ index: number;
142
+ control: boolean;
143
+ }>;
128
144
 
129
145
  type TransitionDataStoreOptions = {
130
146
  initialData?: Partial<VisitorData>;
131
147
  };
132
- type ServerToClientTransitionState = Pick<Partial<VisitorData>, 'quirks' | 'tests'> & {
148
+ type ServerToClientTransitionState = Pick<Partial<VisitorData>, 'quirks' | 'tests' | 'personalizeVariants'> & {
133
149
  /**
134
150
  * Server Score Vector - the resultant scores _on the server side_ after the server/edge render completes
135
151
  * Note that the client side does not trust these scores; they are only used until it's done with initial
@@ -826,6 +842,10 @@ type VariantMatchCriteria = {
826
842
  * Name of the variant for analytics tracking.
827
843
  */
828
844
  name?: string;
845
+ /**
846
+ * Control group percentage for the variant.
847
+ */
848
+ control?: number;
829
849
  };
830
850
  type DimensionMatch = {
831
851
  /**
@@ -836,7 +856,8 @@ type DimensionMatch = {
836
856
  /**
837
857
  * Operator of the match expression
838
858
  * Whole-vector (RHS only) operators - these do not require a `r` or `rDim` set:
839
- * +: `l` is the strongest dimension in the score vector
859
+ * +: `l` is the strongest dimension in the score vector across all categories
860
+ * ^: `l` is the strongest dimension in the specified category
840
861
  * -: `l` is the weakest dimension in the score vector. This does not match if the dimension has no score at all.
841
862
  *
842
863
  * Comparison operators:
@@ -847,7 +868,7 @@ type DimensionMatch = {
847
868
  * =: `l` is equal to the right hand side expression
848
869
  * !=: `l` is not equal to the right hand side expression
849
870
  */
850
- op: '+' | '-' | '>' | '>=' | '<' | '<=' | '=' | '!=';
871
+ op: '+' | '-' | '>' | '>=' | '<' | '<=' | '=' | '!=' | '^';
851
872
  /**
852
873
  * Right hand side of the match expression (not required for op = + or - which have no right side)
853
874
  * This value is treated as a constant value, if it is present. If it's a string, it is parsed to an integer.
@@ -881,7 +902,9 @@ type PersonalizedResult<TVariant> = {
881
902
  /** Whether or not this result contains a personalized result */
882
903
  personalized: boolean;
883
904
  /** Matching variations */
884
- variations: Array<TVariant>;
905
+ variations: Array<TVariant & {
906
+ control: boolean;
907
+ }>;
885
908
  };
886
909
  /** Defines the shape of a A/B test variant */
887
910
  type TestVariant = {
@@ -957,7 +980,10 @@ type PersonalizationEvent = {
957
980
  /** Name of the personalized placement */
958
981
  name: string;
959
982
  /** Selected variant ID(s) */
960
- variantIds: string[];
983
+ variantIds: {
984
+ id: string;
985
+ control: boolean;
986
+ }[];
961
987
  /** Whether the user was part of the control group (and did not receive any personalization) */
962
988
  control: boolean | undefined;
963
989
  /**
@@ -1146,4 +1172,4 @@ declare global {
1146
1172
  }
1147
1173
  }
1148
1174
 
1149
- export { type TestOptions as $, type AggregateDimension as A, type MessageFunc as B, type ContextPlugin as C, type DecayFunction as D, type LogMessageSingle as E, type LogMessageGroup as F, ManifestInstance as G, GroupCriteriaEvaluator as H, type CriteriaEvaluatorResult as I, type CriteriaEvaluatorParameters as J, type SignalData as K, type LogDrain as L, type MessageCategory as M, type ManifestV2 as N, type OutputSeverity as O, type PersonalizationEvent as P, type PersonalizationManifest as Q, type Signal as R, type ScoreVector as S, TransitionDataStore as T, type SignalCriteriaGroup as U, type VisitorData as V, type SignalCriteria as W, type EnrichmentCategory as X, type NumberMatch as Y, type TestDefinition as Z, type AggregateDimensionInput as _, type StorageCommands as a, testVariations as a0, type DimensionMatch as a1, type PersonalizeOptions as a2, personalizeVariations as a3, type BehaviorTag as a4, type PersonalizedVariant as a5, type PersonalizedResult as a6, type TestVariant as a7, type TestResult as a8, type StorageCommand as a9, type ModifyScoreCommand as aa, type ModifySessionScoreCommand as ab, type SetConsentCommand as ac, type SetQuirkCommand as ad, type SetTestCommand as ae, type IdentifyCommand as af, type SetControlGroupCommand as ag, type ServerToClientTransitionState as ah, SERVER_STATE_ID as ai, type TransitionDataStoreEvents as aj, type DecayOptions as ak, type VisitorDataStoreOptions as al, type VisitorDataStoreEvents as am, VisitorDataStore as an, type Quirks as ao, type Tests as ap, type EnrichmentData as aq, type EventData as ar, emptyVisitorData as as, type ContextState as at, type ContextStateUpdate as au, type paths as av, type TransitionDataStoreOptions as b, type CriteriaEvaluator as c, type StringMatch as d, type VariantMatchCriteria as e, type LogMessage as f, type DevToolsEvents as g, CONTEXTUAL_EDITING_TEST_NAME as h, CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID as i, type ContextOptions as j, type TestEvent as k, type ContextEvents as l, type ContextInstance as m, Context as n, type DevToolsUiVersion as o, type DevToolsState as p, type DevToolsActions as q, type DevToolsEvent as r, type DevToolsLogEvent as s, type DevToolsDataEvent as t, type DevToolsHelloEvent as u, type DevToolsUpdateEvent as v, type DevToolsRawCommandsEvent as w, type DevToolsForgetEvent as x, type LogMessages as y, type Severity as z };
1175
+ export { type TestOptions as $, type AggregateDimension as A, type MessageFunc as B, type ContextPlugin as C, type DecayFunction as D, type LogMessageSingle as E, type LogMessageGroup as F, ManifestInstance as G, GroupCriteriaEvaluator as H, type CriteriaEvaluatorResult as I, type CriteriaEvaluatorParameters as J, type SignalData as K, type LogDrain as L, type MessageCategory as M, type ManifestV2 as N, type OutputSeverity as O, type PersonalizationEvent as P, type PersonalizationManifest as Q, type Signal as R, type ScoreVector as S, TransitionDataStore as T, type SignalCriteriaGroup as U, type VisitorData as V, type SignalCriteria as W, type EnrichmentCategory as X, type NumberMatch as Y, type TestDefinition as Z, type AggregateDimensionInput as _, type StorageCommands as a, testVariations as a0, type DimensionMatch as a1, type PersonalizeOptions as a2, personalizeVariations as a3, type BehaviorTag as a4, type PersonalizedVariant as a5, type PersonalizedResult as a6, type TestVariant as a7, type TestResult as a8, type StorageCommand as a9, type ModifyScoreCommand as aa, type ModifySessionScoreCommand as ab, type SetConsentCommand as ac, type SetQuirkCommand as ad, type SetTestCommand as ae, type IdentifyCommand as af, type SetControlGroupCommand as ag, type SetPersonalizeVariantControlCommand as ah, type ServerToClientTransitionState as ai, SERVER_STATE_ID as aj, type TransitionDataStoreEvents as ak, type DecayOptions as al, type VisitorDataStoreOptions as am, type VisitorDataStoreEvents as an, VisitorDataStore as ao, type Quirks as ap, type Tests as aq, type EnrichmentData as ar, type PersonalizeControlVariant as as, type PersonalizeVariants as at, type EventData as au, emptyVisitorData as av, type ContextState as aw, type ContextStateUpdate as ax, type paths as ay, type TransitionDataStoreOptions as b, type CriteriaEvaluator as c, type StringMatch as d, type VariantMatchCriteria as e, type LogMessage as f, type DevToolsEvents as g, CONTEXTUAL_EDITING_TEST_NAME as h, CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID as i, type ContextOptions as j, type TestEvent as k, type ContextEvents as l, type ContextInstance as m, Context as n, type DevToolsUiVersion as o, type DevToolsState as p, type DevToolsActions as q, type DevToolsEvent as r, type DevToolsLogEvent as s, type DevToolsDataEvent as t, type DevToolsHelloEvent as u, type DevToolsUpdateEvent as v, type DevToolsRawCommandsEvent as w, type DevToolsForgetEvent as x, type LogMessages as y, type Severity as z };
@@ -17,6 +17,13 @@ type EnrichmentData = {
17
17
  /** Strength value (amount of score added when viewing content) */
18
18
  str: number;
19
19
  };
20
+ type PersonalizeControlVariant = {
21
+ index: number;
22
+ control: boolean;
23
+ };
24
+ type PersonalizeVariants = {
25
+ [key: string]: PersonalizeControlVariant[];
26
+ };
20
27
  /** An event that has occurred (i.e. an analytics track) which may trigger an Event signal */
21
28
  type EventData = {
22
29
  /** The event name that has been fired */
@@ -55,6 +62,10 @@ type VisitorData = {
55
62
  * based on the control group size.
56
63
  */
57
64
  controlGroup?: boolean;
65
+ /**
66
+ * Records of personalized variants that have been shown to the visitor and their control group status
67
+ */
68
+ personalizeVariants?: PersonalizeVariants;
58
69
  };
59
70
  declare const emptyVisitorData: () => VisitorData;
60
71
  /**
@@ -79,7 +90,7 @@ type StorageCommand<TID extends string = string, TData = unknown> = {
79
90
  data: TData;
80
91
  };
81
92
  /** Commands that can be issued to alter the storage of Uniform Context data */
82
- type StorageCommands = ModifyScoreCommand | ModifySessionScoreCommand | SetConsentCommand | SetQuirkCommand | SetTestCommand | IdentifyCommand | SetControlGroupCommand;
93
+ type StorageCommands = ModifyScoreCommand | ModifySessionScoreCommand | SetConsentCommand | SetQuirkCommand | SetTestCommand | IdentifyCommand | SetControlGroupCommand | SetPersonalizeVariantControlCommand;
83
94
  /**
84
95
  * Changes the visitor's permanent score for a given dimension
85
96
  */
@@ -125,11 +136,16 @@ type IdentifyCommand = StorageCommand<'identify', {
125
136
  * this command is intended mostly for diagnostics and testing purposes.
126
137
  */
127
138
  type SetControlGroupCommand = StorageCommand<'setcontrol', boolean>;
139
+ type SetPersonalizeVariantControlCommand = StorageCommand<'setpersonalizecontrol', {
140
+ personlizationName: string;
141
+ index: number;
142
+ control: boolean;
143
+ }>;
128
144
 
129
145
  type TransitionDataStoreOptions = {
130
146
  initialData?: Partial<VisitorData>;
131
147
  };
132
- type ServerToClientTransitionState = Pick<Partial<VisitorData>, 'quirks' | 'tests'> & {
148
+ type ServerToClientTransitionState = Pick<Partial<VisitorData>, 'quirks' | 'tests' | 'personalizeVariants'> & {
133
149
  /**
134
150
  * Server Score Vector - the resultant scores _on the server side_ after the server/edge render completes
135
151
  * Note that the client side does not trust these scores; they are only used until it's done with initial
@@ -826,6 +842,10 @@ type VariantMatchCriteria = {
826
842
  * Name of the variant for analytics tracking.
827
843
  */
828
844
  name?: string;
845
+ /**
846
+ * Control group percentage for the variant.
847
+ */
848
+ control?: number;
829
849
  };
830
850
  type DimensionMatch = {
831
851
  /**
@@ -836,7 +856,8 @@ type DimensionMatch = {
836
856
  /**
837
857
  * Operator of the match expression
838
858
  * Whole-vector (RHS only) operators - these do not require a `r` or `rDim` set:
839
- * +: `l` is the strongest dimension in the score vector
859
+ * +: `l` is the strongest dimension in the score vector across all categories
860
+ * ^: `l` is the strongest dimension in the specified category
840
861
  * -: `l` is the weakest dimension in the score vector. This does not match if the dimension has no score at all.
841
862
  *
842
863
  * Comparison operators:
@@ -847,7 +868,7 @@ type DimensionMatch = {
847
868
  * =: `l` is equal to the right hand side expression
848
869
  * !=: `l` is not equal to the right hand side expression
849
870
  */
850
- op: '+' | '-' | '>' | '>=' | '<' | '<=' | '=' | '!=';
871
+ op: '+' | '-' | '>' | '>=' | '<' | '<=' | '=' | '!=' | '^';
851
872
  /**
852
873
  * Right hand side of the match expression (not required for op = + or - which have no right side)
853
874
  * This value is treated as a constant value, if it is present. If it's a string, it is parsed to an integer.
@@ -881,7 +902,9 @@ type PersonalizedResult<TVariant> = {
881
902
  /** Whether or not this result contains a personalized result */
882
903
  personalized: boolean;
883
904
  /** Matching variations */
884
- variations: Array<TVariant>;
905
+ variations: Array<TVariant & {
906
+ control: boolean;
907
+ }>;
885
908
  };
886
909
  /** Defines the shape of a A/B test variant */
887
910
  type TestVariant = {
@@ -957,7 +980,10 @@ type PersonalizationEvent = {
957
980
  /** Name of the personalized placement */
958
981
  name: string;
959
982
  /** Selected variant ID(s) */
960
- variantIds: string[];
983
+ variantIds: {
984
+ id: string;
985
+ control: boolean;
986
+ }[];
961
987
  /** Whether the user was part of the control group (and did not receive any personalization) */
962
988
  control: boolean | undefined;
963
989
  /**
@@ -1146,4 +1172,4 @@ declare global {
1146
1172
  }
1147
1173
  }
1148
1174
 
1149
- export { type TestOptions as $, type AggregateDimension as A, type MessageFunc as B, type ContextPlugin as C, type DecayFunction as D, type LogMessageSingle as E, type LogMessageGroup as F, ManifestInstance as G, GroupCriteriaEvaluator as H, type CriteriaEvaluatorResult as I, type CriteriaEvaluatorParameters as J, type SignalData as K, type LogDrain as L, type MessageCategory as M, type ManifestV2 as N, type OutputSeverity as O, type PersonalizationEvent as P, type PersonalizationManifest as Q, type Signal as R, type ScoreVector as S, TransitionDataStore as T, type SignalCriteriaGroup as U, type VisitorData as V, type SignalCriteria as W, type EnrichmentCategory as X, type NumberMatch as Y, type TestDefinition as Z, type AggregateDimensionInput as _, type StorageCommands as a, testVariations as a0, type DimensionMatch as a1, type PersonalizeOptions as a2, personalizeVariations as a3, type BehaviorTag as a4, type PersonalizedVariant as a5, type PersonalizedResult as a6, type TestVariant as a7, type TestResult as a8, type StorageCommand as a9, type ModifyScoreCommand as aa, type ModifySessionScoreCommand as ab, type SetConsentCommand as ac, type SetQuirkCommand as ad, type SetTestCommand as ae, type IdentifyCommand as af, type SetControlGroupCommand as ag, type ServerToClientTransitionState as ah, SERVER_STATE_ID as ai, type TransitionDataStoreEvents as aj, type DecayOptions as ak, type VisitorDataStoreOptions as al, type VisitorDataStoreEvents as am, VisitorDataStore as an, type Quirks as ao, type Tests as ap, type EnrichmentData as aq, type EventData as ar, emptyVisitorData as as, type ContextState as at, type ContextStateUpdate as au, type paths as av, type TransitionDataStoreOptions as b, type CriteriaEvaluator as c, type StringMatch as d, type VariantMatchCriteria as e, type LogMessage as f, type DevToolsEvents as g, CONTEXTUAL_EDITING_TEST_NAME as h, CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID as i, type ContextOptions as j, type TestEvent as k, type ContextEvents as l, type ContextInstance as m, Context as n, type DevToolsUiVersion as o, type DevToolsState as p, type DevToolsActions as q, type DevToolsEvent as r, type DevToolsLogEvent as s, type DevToolsDataEvent as t, type DevToolsHelloEvent as u, type DevToolsUpdateEvent as v, type DevToolsRawCommandsEvent as w, type DevToolsForgetEvent as x, type LogMessages as y, type Severity as z };
1175
+ export { type TestOptions as $, type AggregateDimension as A, type MessageFunc as B, type ContextPlugin as C, type DecayFunction as D, type LogMessageSingle as E, type LogMessageGroup as F, ManifestInstance as G, GroupCriteriaEvaluator as H, type CriteriaEvaluatorResult as I, type CriteriaEvaluatorParameters as J, type SignalData as K, type LogDrain as L, type MessageCategory as M, type ManifestV2 as N, type OutputSeverity as O, type PersonalizationEvent as P, type PersonalizationManifest as Q, type Signal as R, type ScoreVector as S, TransitionDataStore as T, type SignalCriteriaGroup as U, type VisitorData as V, type SignalCriteria as W, type EnrichmentCategory as X, type NumberMatch as Y, type TestDefinition as Z, type AggregateDimensionInput as _, type StorageCommands as a, testVariations as a0, type DimensionMatch as a1, type PersonalizeOptions as a2, personalizeVariations as a3, type BehaviorTag as a4, type PersonalizedVariant as a5, type PersonalizedResult as a6, type TestVariant as a7, type TestResult as a8, type StorageCommand as a9, type ModifyScoreCommand as aa, type ModifySessionScoreCommand as ab, type SetConsentCommand as ac, type SetQuirkCommand as ad, type SetTestCommand as ae, type IdentifyCommand as af, type SetControlGroupCommand as ag, type SetPersonalizeVariantControlCommand as ah, type ServerToClientTransitionState as ai, SERVER_STATE_ID as aj, type TransitionDataStoreEvents as ak, type DecayOptions as al, type VisitorDataStoreOptions as am, type VisitorDataStoreEvents as an, VisitorDataStore as ao, type Quirks as ap, type Tests as aq, type EnrichmentData as ar, type PersonalizeControlVariant as as, type PersonalizeVariants as at, type EventData as au, emptyVisitorData as av, type ContextState as aw, type ContextStateUpdate as ax, type paths as ay, type TransitionDataStoreOptions as b, type CriteriaEvaluator as c, type StringMatch as d, type VariantMatchCriteria as e, type LogMessage as f, type DevToolsEvents as g, CONTEXTUAL_EDITING_TEST_NAME as h, CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID as i, type ContextOptions as j, type TestEvent as k, type ContextEvents as l, type ContextInstance as m, Context as n, type DevToolsUiVersion as o, type DevToolsState as p, type DevToolsActions as q, type DevToolsEvent as r, type DevToolsLogEvent as s, type DevToolsDataEvent as t, type DevToolsHelloEvent as u, type DevToolsUpdateEvent as v, type DevToolsRawCommandsEvent as w, type DevToolsForgetEvent as x, type LogMessages as y, type Severity as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/context",
3
- "version": "19.127.0",
3
+ "version": "19.128.1-alpha.11+11cc55c0a1",
4
4
  "description": "Uniform Context core package",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -66,5 +66,5 @@
66
66
  "publishConfig": {
67
67
  "access": "public"
68
68
  },
69
- "gitHead": "3757cfe081cf40d019cb9f65d0a26e2a4fbdb1f6"
69
+ "gitHead": "11cc55c0a1f62ac84634af6734dac6168a140161"
70
70
  }