@uniformdev/context 19.127.0 → 19.128.1-alpha.8
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/api/api.d.mts +1 -1
- package/dist/api/api.d.ts +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.esm.js +147 -18
- package/dist/index.js +147 -18
- package/dist/index.mjs +147 -18
- package/dist/{types-R41eD1zH.d.mts → types-zhN7Sdp3.d.mts} +25 -4
- package/dist/{types-R41eD1zH.d.ts → types-zhN7Sdp3.d.ts} +25 -4
- package/package.json +2 -2
package/dist/api/api.d.mts
CHANGED
package/dist/api/api.d.ts
CHANGED
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-
|
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,
|
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-zhN7Sdp3.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-zhN7Sdp3.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-
|
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,
|
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-zhN7Sdp3.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-zhN7Sdp3.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
|
150
|
-
|
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,19 +614,27 @@ 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 = [];
|
596
626
|
for (const variant of variations) {
|
627
|
+
if (!((_b = variant.pz) == null ? void 0 : _b.crit.length)) {
|
628
|
+
defaultVariants.push(variant);
|
629
|
+
}
|
630
|
+
}
|
631
|
+
for (const variant of variations) {
|
632
|
+
const currentIndex = index++;
|
597
633
|
if (results.length === take) {
|
598
634
|
break;
|
599
635
|
}
|
600
|
-
if (!((
|
601
|
-
onLogMessage == null ? void 0 : onLogMessage(["info", 301, "GROUP", { id: variant.id, 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"]);
|
@@ -609,8 +645,32 @@ function personalizeVariations({
|
|
609
645
|
continue;
|
610
646
|
}
|
611
647
|
if (evaluateVariantMatch(variant.id, variant.pz, scores, onLogMessage)) {
|
612
|
-
|
613
|
-
|
648
|
+
let variantToAdd = variant;
|
649
|
+
if (take === 1 && defaultVariants.length && typeof variant.pz.control === "number") {
|
650
|
+
const testVariants = (_e = context.storage.data.personalizeVariants) == null ? void 0 : _e[name];
|
651
|
+
const entry = testVariants == null ? void 0 : testVariants.find((v) => v.index === currentIndex);
|
652
|
+
let isControl = false;
|
653
|
+
if (typeof entry !== "undefined") {
|
654
|
+
isControl = entry.control;
|
655
|
+
} else {
|
656
|
+
isControl = rollForControlGroup(variant.pz.control);
|
657
|
+
context.storage.updateData([
|
658
|
+
{
|
659
|
+
type: "setpersonalizecontrol",
|
660
|
+
data: {
|
661
|
+
personlizationName: name,
|
662
|
+
index: currentIndex,
|
663
|
+
control: isControl
|
664
|
+
}
|
665
|
+
}
|
666
|
+
]);
|
667
|
+
}
|
668
|
+
if (isControl) {
|
669
|
+
variantToAdd = defaultVariants[0];
|
670
|
+
}
|
671
|
+
}
|
672
|
+
personalized = variant.id === variantToAdd.id;
|
673
|
+
results.push(variantToAdd);
|
614
674
|
}
|
615
675
|
}
|
616
676
|
return {
|
@@ -857,16 +917,19 @@ function parseScoreCookie(cookieValue) {
|
|
857
917
|
if (!cookieValue)
|
858
918
|
return;
|
859
919
|
const types = cookieValue.split(TYPE_SEP);
|
860
|
-
if (types.length >
|
920
|
+
if (types.length > 5)
|
861
921
|
return;
|
862
|
-
const [abTestData, sessionScores, visitorScores] = types;
|
863
|
-
|
922
|
+
const [abTestData, sessionScores, visitorScores, controlGroup, personalizeVariants] = types;
|
923
|
+
const data = {
|
864
924
|
// this is true since we're reading a cookie, which wouldn't exist if consent wasn't given
|
865
925
|
consent: true,
|
866
926
|
sessionScores: decodeCookieType(parseCookieType(sessionScores)),
|
867
927
|
scores: decodeCookieType(parseCookieType(visitorScores)),
|
868
|
-
tests: parseCookieType(abTestData)
|
928
|
+
tests: parseCookieType(abTestData),
|
929
|
+
controlGroup: controlGroup === "1",
|
930
|
+
personalizeVariants: decodePersonalizeVariants(personalizeVariants)
|
869
931
|
};
|
932
|
+
return data;
|
870
933
|
}
|
871
934
|
function parseCookieType(type) {
|
872
935
|
if (!type) {
|
@@ -890,9 +953,51 @@ function serializeCookie(data) {
|
|
890
953
|
return [
|
891
954
|
serializeCookieType(data.tests),
|
892
955
|
serializeCookieType(encodeCookieType(data.sessionScores)),
|
893
|
-
serializeCookieType(encodeCookieType(data.scores))
|
956
|
+
serializeCookieType(encodeCookieType(data.scores)),
|
957
|
+
data.controlGroup ? "1" : "0",
|
958
|
+
serializePersonalizeVariants(data)
|
894
959
|
].join(TYPE_SEP);
|
895
960
|
}
|
961
|
+
function serializePersonalizeVariants({
|
962
|
+
personalizeVariants
|
963
|
+
}) {
|
964
|
+
const data = {};
|
965
|
+
if (typeof personalizeVariants === "object") {
|
966
|
+
Object.keys(personalizeVariants).forEach((personalizationName) => {
|
967
|
+
let number = BigInt(0);
|
968
|
+
const variants = personalizeVariants[personalizationName];
|
969
|
+
variants.forEach((variant) => {
|
970
|
+
if (variant.control) {
|
971
|
+
number = flipNthBitTo1BigInt(number, variant.index);
|
972
|
+
}
|
973
|
+
});
|
974
|
+
data[personalizationName] = number.toString(10);
|
975
|
+
});
|
976
|
+
}
|
977
|
+
return serializeCookieType(data);
|
978
|
+
}
|
979
|
+
function decodePersonalizeVariants(data) {
|
980
|
+
const parsed = parseCookieType(data);
|
981
|
+
const keys = Object.keys(parsed);
|
982
|
+
if (!keys.length) {
|
983
|
+
return void 0;
|
984
|
+
}
|
985
|
+
const personalizeVariants = {};
|
986
|
+
keys.forEach((personalizationName) => {
|
987
|
+
personalizeVariants[personalizationName] = [];
|
988
|
+
const value = BigInt(parsed[personalizationName]);
|
989
|
+
const asBinary = value.toString(2);
|
990
|
+
for (let i = 0; i < asBinary.length; i++) {
|
991
|
+
if (asBinary[i] === "1") {
|
992
|
+
personalizeVariants[personalizationName].push({
|
993
|
+
index: asBinary.length - i,
|
994
|
+
control: true
|
995
|
+
});
|
996
|
+
}
|
997
|
+
}
|
998
|
+
});
|
999
|
+
return personalizeVariants;
|
1000
|
+
}
|
896
1001
|
function encodeCookieType(type) {
|
897
1002
|
return Object.entries(type).reduce((acc, [key, value]) => {
|
898
1003
|
acc[key] = ntob(value);
|
@@ -902,6 +1007,9 @@ function encodeCookieType(type) {
|
|
902
1007
|
function serializeCookieType(type) {
|
903
1008
|
return Object.entries(type).map((kv) => kv.join(KV_SEP)).join(PAIR_SEP);
|
904
1009
|
}
|
1010
|
+
function flipNthBitTo1BigInt(number, n) {
|
1011
|
+
return number | BigInt(1) << BigInt(n - 1);
|
1012
|
+
}
|
905
1013
|
|
906
1014
|
// src/storage/EdgeTransitionDataStore.ts
|
907
1015
|
var _fetchData, fetchData_fn;
|
@@ -980,7 +1088,8 @@ var emptyVisitorData = () => ({
|
|
980
1088
|
sessionScores: {},
|
981
1089
|
tests: {},
|
982
1090
|
consent: false,
|
983
|
-
controlGroup: false
|
1091
|
+
controlGroup: false,
|
1092
|
+
personalizeVariants: {}
|
984
1093
|
});
|
985
1094
|
|
986
1095
|
// src/storage/VisitorDataStore.ts
|
@@ -1029,6 +1138,26 @@ function applyCommandsToData(commands, state, inControlGroup) {
|
|
1029
1138
|
case "setcontrol":
|
1030
1139
|
newData.controlGroup = command.data;
|
1031
1140
|
break;
|
1141
|
+
case "setpersonalizecontrol":
|
1142
|
+
if (!newData.personalizeVariants) {
|
1143
|
+
newData.personalizeVariants = {};
|
1144
|
+
}
|
1145
|
+
if (!newData.personalizeVariants[command.data.personlizationName]) {
|
1146
|
+
newData.personalizeVariants[command.data.personlizationName] = [];
|
1147
|
+
}
|
1148
|
+
const existingDef = newData.personalizeVariants[command.data.personlizationName].find(
|
1149
|
+
(i) => i.index === command.data.index
|
1150
|
+
);
|
1151
|
+
if (!existingDef) {
|
1152
|
+
const newDef = {
|
1153
|
+
index: command.data.index,
|
1154
|
+
control: command.data.control
|
1155
|
+
};
|
1156
|
+
newData.personalizeVariants[command.data.personlizationName].push(newDef);
|
1157
|
+
} else if (existingDef.control !== command.data.control) {
|
1158
|
+
existingDef.control = command.data.control;
|
1159
|
+
}
|
1160
|
+
break;
|
1032
1161
|
default:
|
1033
1162
|
throw new Error(`Unknown command`);
|
1034
1163
|
}
|
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
|
220
|
-
|
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,19 +684,27 @@ 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 = [];
|
666
696
|
for (const variant of variations) {
|
697
|
+
if (!((_b = variant.pz) == null ? void 0 : _b.crit.length)) {
|
698
|
+
defaultVariants.push(variant);
|
699
|
+
}
|
700
|
+
}
|
701
|
+
for (const variant of variations) {
|
702
|
+
const currentIndex = index++;
|
667
703
|
if (results.length === take) {
|
668
704
|
break;
|
669
705
|
}
|
670
|
-
if (!((
|
671
|
-
onLogMessage == null ? void 0 : onLogMessage(["info", 301, "GROUP", { id: variant.id, 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"]);
|
@@ -679,8 +715,32 @@ function personalizeVariations({
|
|
679
715
|
continue;
|
680
716
|
}
|
681
717
|
if (evaluateVariantMatch(variant.id, variant.pz, scores, onLogMessage)) {
|
682
|
-
|
683
|
-
|
718
|
+
let variantToAdd = variant;
|
719
|
+
if (take === 1 && defaultVariants.length && typeof variant.pz.control === "number") {
|
720
|
+
const testVariants = (_e = context.storage.data.personalizeVariants) == null ? void 0 : _e[name];
|
721
|
+
const entry = testVariants == null ? void 0 : testVariants.find((v) => v.index === currentIndex);
|
722
|
+
let isControl = false;
|
723
|
+
if (typeof entry !== "undefined") {
|
724
|
+
isControl = entry.control;
|
725
|
+
} else {
|
726
|
+
isControl = rollForControlGroup(variant.pz.control);
|
727
|
+
context.storage.updateData([
|
728
|
+
{
|
729
|
+
type: "setpersonalizecontrol",
|
730
|
+
data: {
|
731
|
+
personlizationName: name,
|
732
|
+
index: currentIndex,
|
733
|
+
control: isControl
|
734
|
+
}
|
735
|
+
}
|
736
|
+
]);
|
737
|
+
}
|
738
|
+
if (isControl) {
|
739
|
+
variantToAdd = defaultVariants[0];
|
740
|
+
}
|
741
|
+
}
|
742
|
+
personalized = variant.id === variantToAdd.id;
|
743
|
+
results.push(variantToAdd);
|
684
744
|
}
|
685
745
|
}
|
686
746
|
return {
|
@@ -927,16 +987,19 @@ function parseScoreCookie(cookieValue) {
|
|
927
987
|
if (!cookieValue)
|
928
988
|
return;
|
929
989
|
const types = cookieValue.split(TYPE_SEP);
|
930
|
-
if (types.length >
|
990
|
+
if (types.length > 5)
|
931
991
|
return;
|
932
|
-
const [abTestData, sessionScores, visitorScores] = types;
|
933
|
-
|
992
|
+
const [abTestData, sessionScores, visitorScores, controlGroup, personalizeVariants] = types;
|
993
|
+
const data = {
|
934
994
|
// this is true since we're reading a cookie, which wouldn't exist if consent wasn't given
|
935
995
|
consent: true,
|
936
996
|
sessionScores: decodeCookieType(parseCookieType(sessionScores)),
|
937
997
|
scores: decodeCookieType(parseCookieType(visitorScores)),
|
938
|
-
tests: parseCookieType(abTestData)
|
998
|
+
tests: parseCookieType(abTestData),
|
999
|
+
controlGroup: controlGroup === "1",
|
1000
|
+
personalizeVariants: decodePersonalizeVariants(personalizeVariants)
|
939
1001
|
};
|
1002
|
+
return data;
|
940
1003
|
}
|
941
1004
|
function parseCookieType(type) {
|
942
1005
|
if (!type) {
|
@@ -960,9 +1023,51 @@ function serializeCookie(data) {
|
|
960
1023
|
return [
|
961
1024
|
serializeCookieType(data.tests),
|
962
1025
|
serializeCookieType(encodeCookieType(data.sessionScores)),
|
963
|
-
serializeCookieType(encodeCookieType(data.scores))
|
1026
|
+
serializeCookieType(encodeCookieType(data.scores)),
|
1027
|
+
data.controlGroup ? "1" : "0",
|
1028
|
+
serializePersonalizeVariants(data)
|
964
1029
|
].join(TYPE_SEP);
|
965
1030
|
}
|
1031
|
+
function serializePersonalizeVariants({
|
1032
|
+
personalizeVariants
|
1033
|
+
}) {
|
1034
|
+
const data = {};
|
1035
|
+
if (typeof personalizeVariants === "object") {
|
1036
|
+
Object.keys(personalizeVariants).forEach((personalizationName) => {
|
1037
|
+
let number = BigInt(0);
|
1038
|
+
const variants = personalizeVariants[personalizationName];
|
1039
|
+
variants.forEach((variant) => {
|
1040
|
+
if (variant.control) {
|
1041
|
+
number = flipNthBitTo1BigInt(number, variant.index);
|
1042
|
+
}
|
1043
|
+
});
|
1044
|
+
data[personalizationName] = number.toString(10);
|
1045
|
+
});
|
1046
|
+
}
|
1047
|
+
return serializeCookieType(data);
|
1048
|
+
}
|
1049
|
+
function decodePersonalizeVariants(data) {
|
1050
|
+
const parsed = parseCookieType(data);
|
1051
|
+
const keys = Object.keys(parsed);
|
1052
|
+
if (!keys.length) {
|
1053
|
+
return void 0;
|
1054
|
+
}
|
1055
|
+
const personalizeVariants = {};
|
1056
|
+
keys.forEach((personalizationName) => {
|
1057
|
+
personalizeVariants[personalizationName] = [];
|
1058
|
+
const value = BigInt(parsed[personalizationName]);
|
1059
|
+
const asBinary = value.toString(2);
|
1060
|
+
for (let i = 0; i < asBinary.length; i++) {
|
1061
|
+
if (asBinary[i] === "1") {
|
1062
|
+
personalizeVariants[personalizationName].push({
|
1063
|
+
index: asBinary.length - i,
|
1064
|
+
control: true
|
1065
|
+
});
|
1066
|
+
}
|
1067
|
+
}
|
1068
|
+
});
|
1069
|
+
return personalizeVariants;
|
1070
|
+
}
|
966
1071
|
function encodeCookieType(type) {
|
967
1072
|
return Object.entries(type).reduce((acc, [key, value]) => {
|
968
1073
|
acc[key] = ntob(value);
|
@@ -972,6 +1077,9 @@ function encodeCookieType(type) {
|
|
972
1077
|
function serializeCookieType(type) {
|
973
1078
|
return Object.entries(type).map((kv) => kv.join(KV_SEP)).join(PAIR_SEP);
|
974
1079
|
}
|
1080
|
+
function flipNthBitTo1BigInt(number, n) {
|
1081
|
+
return number | BigInt(1) << BigInt(n - 1);
|
1082
|
+
}
|
975
1083
|
|
976
1084
|
// src/storage/EdgeTransitionDataStore.ts
|
977
1085
|
var _fetchData, fetchData_fn;
|
@@ -1050,7 +1158,8 @@ var emptyVisitorData = () => ({
|
|
1050
1158
|
sessionScores: {},
|
1051
1159
|
tests: {},
|
1052
1160
|
consent: false,
|
1053
|
-
controlGroup: false
|
1161
|
+
controlGroup: false,
|
1162
|
+
personalizeVariants: {}
|
1054
1163
|
});
|
1055
1164
|
|
1056
1165
|
// src/storage/VisitorDataStore.ts
|
@@ -1099,6 +1208,26 @@ function applyCommandsToData(commands, state, inControlGroup) {
|
|
1099
1208
|
case "setcontrol":
|
1100
1209
|
newData.controlGroup = command.data;
|
1101
1210
|
break;
|
1211
|
+
case "setpersonalizecontrol":
|
1212
|
+
if (!newData.personalizeVariants) {
|
1213
|
+
newData.personalizeVariants = {};
|
1214
|
+
}
|
1215
|
+
if (!newData.personalizeVariants[command.data.personlizationName]) {
|
1216
|
+
newData.personalizeVariants[command.data.personlizationName] = [];
|
1217
|
+
}
|
1218
|
+
const existingDef = newData.personalizeVariants[command.data.personlizationName].find(
|
1219
|
+
(i) => i.index === command.data.index
|
1220
|
+
);
|
1221
|
+
if (!existingDef) {
|
1222
|
+
const newDef = {
|
1223
|
+
index: command.data.index,
|
1224
|
+
control: command.data.control
|
1225
|
+
};
|
1226
|
+
newData.personalizeVariants[command.data.personlizationName].push(newDef);
|
1227
|
+
} else if (existingDef.control !== command.data.control) {
|
1228
|
+
existingDef.control = command.data.control;
|
1229
|
+
}
|
1230
|
+
break;
|
1102
1231
|
default:
|
1103
1232
|
throw new Error(`Unknown command`);
|
1104
1233
|
}
|
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
|
150
|
-
|
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,19 +614,27 @@ 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 = [];
|
596
626
|
for (const variant of variations) {
|
627
|
+
if (!((_b = variant.pz) == null ? void 0 : _b.crit.length)) {
|
628
|
+
defaultVariants.push(variant);
|
629
|
+
}
|
630
|
+
}
|
631
|
+
for (const variant of variations) {
|
632
|
+
const currentIndex = index++;
|
597
633
|
if (results.length === take) {
|
598
634
|
break;
|
599
635
|
}
|
600
|
-
if (!((
|
601
|
-
onLogMessage == null ? void 0 : onLogMessage(["info", 301, "GROUP", { id: variant.id, 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"]);
|
@@ -609,8 +645,32 @@ function personalizeVariations({
|
|
609
645
|
continue;
|
610
646
|
}
|
611
647
|
if (evaluateVariantMatch(variant.id, variant.pz, scores, onLogMessage)) {
|
612
|
-
|
613
|
-
|
648
|
+
let variantToAdd = variant;
|
649
|
+
if (take === 1 && defaultVariants.length && typeof variant.pz.control === "number") {
|
650
|
+
const testVariants = (_e = context.storage.data.personalizeVariants) == null ? void 0 : _e[name];
|
651
|
+
const entry = testVariants == null ? void 0 : testVariants.find((v) => v.index === currentIndex);
|
652
|
+
let isControl = false;
|
653
|
+
if (typeof entry !== "undefined") {
|
654
|
+
isControl = entry.control;
|
655
|
+
} else {
|
656
|
+
isControl = rollForControlGroup(variant.pz.control);
|
657
|
+
context.storage.updateData([
|
658
|
+
{
|
659
|
+
type: "setpersonalizecontrol",
|
660
|
+
data: {
|
661
|
+
personlizationName: name,
|
662
|
+
index: currentIndex,
|
663
|
+
control: isControl
|
664
|
+
}
|
665
|
+
}
|
666
|
+
]);
|
667
|
+
}
|
668
|
+
if (isControl) {
|
669
|
+
variantToAdd = defaultVariants[0];
|
670
|
+
}
|
671
|
+
}
|
672
|
+
personalized = variant.id === variantToAdd.id;
|
673
|
+
results.push(variantToAdd);
|
614
674
|
}
|
615
675
|
}
|
616
676
|
return {
|
@@ -857,16 +917,19 @@ function parseScoreCookie(cookieValue) {
|
|
857
917
|
if (!cookieValue)
|
858
918
|
return;
|
859
919
|
const types = cookieValue.split(TYPE_SEP);
|
860
|
-
if (types.length >
|
920
|
+
if (types.length > 5)
|
861
921
|
return;
|
862
|
-
const [abTestData, sessionScores, visitorScores] = types;
|
863
|
-
|
922
|
+
const [abTestData, sessionScores, visitorScores, controlGroup, personalizeVariants] = types;
|
923
|
+
const data = {
|
864
924
|
// this is true since we're reading a cookie, which wouldn't exist if consent wasn't given
|
865
925
|
consent: true,
|
866
926
|
sessionScores: decodeCookieType(parseCookieType(sessionScores)),
|
867
927
|
scores: decodeCookieType(parseCookieType(visitorScores)),
|
868
|
-
tests: parseCookieType(abTestData)
|
928
|
+
tests: parseCookieType(abTestData),
|
929
|
+
controlGroup: controlGroup === "1",
|
930
|
+
personalizeVariants: decodePersonalizeVariants(personalizeVariants)
|
869
931
|
};
|
932
|
+
return data;
|
870
933
|
}
|
871
934
|
function parseCookieType(type) {
|
872
935
|
if (!type) {
|
@@ -890,9 +953,51 @@ function serializeCookie(data) {
|
|
890
953
|
return [
|
891
954
|
serializeCookieType(data.tests),
|
892
955
|
serializeCookieType(encodeCookieType(data.sessionScores)),
|
893
|
-
serializeCookieType(encodeCookieType(data.scores))
|
956
|
+
serializeCookieType(encodeCookieType(data.scores)),
|
957
|
+
data.controlGroup ? "1" : "0",
|
958
|
+
serializePersonalizeVariants(data)
|
894
959
|
].join(TYPE_SEP);
|
895
960
|
}
|
961
|
+
function serializePersonalizeVariants({
|
962
|
+
personalizeVariants
|
963
|
+
}) {
|
964
|
+
const data = {};
|
965
|
+
if (typeof personalizeVariants === "object") {
|
966
|
+
Object.keys(personalizeVariants).forEach((personalizationName) => {
|
967
|
+
let number = BigInt(0);
|
968
|
+
const variants = personalizeVariants[personalizationName];
|
969
|
+
variants.forEach((variant) => {
|
970
|
+
if (variant.control) {
|
971
|
+
number = flipNthBitTo1BigInt(number, variant.index);
|
972
|
+
}
|
973
|
+
});
|
974
|
+
data[personalizationName] = number.toString(10);
|
975
|
+
});
|
976
|
+
}
|
977
|
+
return serializeCookieType(data);
|
978
|
+
}
|
979
|
+
function decodePersonalizeVariants(data) {
|
980
|
+
const parsed = parseCookieType(data);
|
981
|
+
const keys = Object.keys(parsed);
|
982
|
+
if (!keys.length) {
|
983
|
+
return void 0;
|
984
|
+
}
|
985
|
+
const personalizeVariants = {};
|
986
|
+
keys.forEach((personalizationName) => {
|
987
|
+
personalizeVariants[personalizationName] = [];
|
988
|
+
const value = BigInt(parsed[personalizationName]);
|
989
|
+
const asBinary = value.toString(2);
|
990
|
+
for (let i = 0; i < asBinary.length; i++) {
|
991
|
+
if (asBinary[i] === "1") {
|
992
|
+
personalizeVariants[personalizationName].push({
|
993
|
+
index: asBinary.length - i,
|
994
|
+
control: true
|
995
|
+
});
|
996
|
+
}
|
997
|
+
}
|
998
|
+
});
|
999
|
+
return personalizeVariants;
|
1000
|
+
}
|
896
1001
|
function encodeCookieType(type) {
|
897
1002
|
return Object.entries(type).reduce((acc, [key, value]) => {
|
898
1003
|
acc[key] = ntob(value);
|
@@ -902,6 +1007,9 @@ function encodeCookieType(type) {
|
|
902
1007
|
function serializeCookieType(type) {
|
903
1008
|
return Object.entries(type).map((kv) => kv.join(KV_SEP)).join(PAIR_SEP);
|
904
1009
|
}
|
1010
|
+
function flipNthBitTo1BigInt(number, n) {
|
1011
|
+
return number | BigInt(1) << BigInt(n - 1);
|
1012
|
+
}
|
905
1013
|
|
906
1014
|
// src/storage/EdgeTransitionDataStore.ts
|
907
1015
|
var _fetchData, fetchData_fn;
|
@@ -980,7 +1088,8 @@ var emptyVisitorData = () => ({
|
|
980
1088
|
sessionScores: {},
|
981
1089
|
tests: {},
|
982
1090
|
consent: false,
|
983
|
-
controlGroup: false
|
1091
|
+
controlGroup: false,
|
1092
|
+
personalizeVariants: {}
|
984
1093
|
});
|
985
1094
|
|
986
1095
|
// src/storage/VisitorDataStore.ts
|
@@ -1029,6 +1138,26 @@ function applyCommandsToData(commands, state, inControlGroup) {
|
|
1029
1138
|
case "setcontrol":
|
1030
1139
|
newData.controlGroup = command.data;
|
1031
1140
|
break;
|
1141
|
+
case "setpersonalizecontrol":
|
1142
|
+
if (!newData.personalizeVariants) {
|
1143
|
+
newData.personalizeVariants = {};
|
1144
|
+
}
|
1145
|
+
if (!newData.personalizeVariants[command.data.personlizationName]) {
|
1146
|
+
newData.personalizeVariants[command.data.personlizationName] = [];
|
1147
|
+
}
|
1148
|
+
const existingDef = newData.personalizeVariants[command.data.personlizationName].find(
|
1149
|
+
(i) => i.index === command.data.index
|
1150
|
+
);
|
1151
|
+
if (!existingDef) {
|
1152
|
+
const newDef = {
|
1153
|
+
index: command.data.index,
|
1154
|
+
control: command.data.control
|
1155
|
+
};
|
1156
|
+
newData.personalizeVariants[command.data.personlizationName].push(newDef);
|
1157
|
+
} else if (existingDef.control !== command.data.control) {
|
1158
|
+
existingDef.control = command.data.control;
|
1159
|
+
}
|
1160
|
+
break;
|
1032
1161
|
default:
|
1033
1162
|
throw new Error(`Unknown command`);
|
1034
1163
|
}
|
@@ -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,6 +136,11 @@ 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>;
|
@@ -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.
|
@@ -1146,4 +1167,4 @@ declare global {
|
|
1146
1167
|
}
|
1147
1168
|
}
|
1148
1169
|
|
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
|
1170
|
+
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,6 +136,11 @@ 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>;
|
@@ -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.
|
@@ -1146,4 +1167,4 @@ declare global {
|
|
1146
1167
|
}
|
1147
1168
|
}
|
1148
1169
|
|
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
|
1170
|
+
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.
|
3
|
+
"version": "19.128.1-alpha.8+63ab00ff70",
|
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": "
|
69
|
+
"gitHead": "63ab00ff70176d970c6ba1e265c50b9767dcaa9b"
|
70
70
|
}
|