@uniformdev/context 19.62.0 → 19.62.1-alpha.127
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/LICENSE.txt +1 -1
- package/dist/api/api.d.mts +2 -2
- package/dist/api/api.d.ts +2 -2
- package/dist/index.d.mts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.esm.js +204 -27
- package/dist/index.js +204 -27
- package/dist/index.mjs +204 -27
- package/dist/{types-012db0cb.d.ts → types-WtfxfDct.d.mts} +56 -8
- package/dist/types-WtfxfDct.d.ts +1176 -0
- package/package.json +3 -3
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,8 +155,8 @@ var ManifestInstance = class {
|
|
146
155
|
__privateSet(this, _onLogMessage2, onLogMessage);
|
147
156
|
}
|
148
157
|
rollForControlGroup() {
|
149
|
-
var _a
|
150
|
-
return
|
158
|
+
var _a;
|
159
|
+
return rollForControlGroup(((_a = __privateGet(this, _mf).pz) == null ? void 0 : _a.control) || 0);
|
151
160
|
}
|
152
161
|
getTest(name) {
|
153
162
|
var _a;
|
@@ -495,7 +504,30 @@ function evaluateDimensionMatch(crit, vec, onLogMessage) {
|
|
495
504
|
var _a, _b;
|
496
505
|
const { op, l: lhs } = crit;
|
497
506
|
const lhsScore = (_a = vec[lhs]) != null ? _a : 0;
|
498
|
-
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 === "+") {
|
499
531
|
const result = Math.max(...Object.values(vec)) === lhsScore && lhsScore > 0;
|
500
532
|
onLogMessage == null ? void 0 : onLogMessage([
|
501
533
|
"info",
|
@@ -582,31 +614,70 @@ function personalizeVariations({
|
|
582
614
|
take = 1,
|
583
615
|
onLogMessage
|
584
616
|
}) {
|
585
|
-
var _a, _b, _c;
|
617
|
+
var _a, _b, _c, _d;
|
586
618
|
onLogMessage == null ? void 0 : onLogMessage(["info", 300, "GROUP", { name, take }]);
|
587
619
|
try {
|
588
620
|
const control = (_a = context.storage.data.controlGroup) != null ? _a : false;
|
589
621
|
const results = [];
|
590
622
|
let personalized = false;
|
591
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
|
+
}
|
592
631
|
for (const variant of variations) {
|
632
|
+
const currentIndex = index++;
|
593
633
|
if (results.length === take) {
|
594
634
|
break;
|
595
635
|
}
|
596
|
-
if (!((
|
597
|
-
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 }]);
|
598
638
|
onLogMessage == null ? void 0 : onLogMessage(["info", 302, { matched: true, description: "default variation" }]);
|
599
639
|
onLogMessage == null ? void 0 : onLogMessage(["info", 303, true]);
|
600
640
|
onLogMessage == null ? void 0 : onLogMessage(["info", 301, "ENDGROUP"]);
|
601
|
-
results.push(
|
641
|
+
results.push({
|
642
|
+
...variant,
|
643
|
+
control: false
|
644
|
+
});
|
602
645
|
continue;
|
603
646
|
}
|
604
647
|
if (control) {
|
605
648
|
continue;
|
606
649
|
}
|
607
650
|
if (evaluateVariantMatch(variant.id, variant.pz, scores, onLogMessage)) {
|
608
|
-
|
609
|
-
|
651
|
+
let variantToAdd = variant;
|
652
|
+
let isControl = false;
|
653
|
+
const isDefault = defaultVariants.find((v) => v.id === variant.id);
|
654
|
+
if (take === 1 && !isDefault && defaultVariants.length && typeof variant.pz.control === "number") {
|
655
|
+
isControl = context.getPersonalizeVariantControl(name, currentIndex);
|
656
|
+
if (typeof isControl === "undefined") {
|
657
|
+
isControl = rollForControlGroup(variant.pz.control);
|
658
|
+
context.storage.updateData([
|
659
|
+
{
|
660
|
+
type: "setpersonalizecontrol",
|
661
|
+
data: {
|
662
|
+
personlizationName: name,
|
663
|
+
index: currentIndex,
|
664
|
+
control: isControl
|
665
|
+
}
|
666
|
+
}
|
667
|
+
]);
|
668
|
+
}
|
669
|
+
if (isControl) {
|
670
|
+
variantToAdd = {
|
671
|
+
...defaultVariants[0],
|
672
|
+
id: variant.id
|
673
|
+
};
|
674
|
+
}
|
675
|
+
}
|
676
|
+
personalized = personalized || typeof variantToAdd.pz !== "undefined";
|
677
|
+
results.push({
|
678
|
+
...variantToAdd,
|
679
|
+
control: isControl
|
680
|
+
});
|
610
681
|
}
|
611
682
|
}
|
612
683
|
return {
|
@@ -853,16 +924,19 @@ function parseScoreCookie(cookieValue) {
|
|
853
924
|
if (!cookieValue)
|
854
925
|
return;
|
855
926
|
const types = cookieValue.split(TYPE_SEP);
|
856
|
-
if (types.length >
|
927
|
+
if (types.length > 5)
|
857
928
|
return;
|
858
|
-
const [abTestData, sessionScores, visitorScores] = types;
|
859
|
-
|
929
|
+
const [abTestData, sessionScores, visitorScores, controlGroup, personalizeVariants] = types;
|
930
|
+
const data = {
|
860
931
|
// this is true since we're reading a cookie, which wouldn't exist if consent wasn't given
|
861
932
|
consent: true,
|
862
933
|
sessionScores: decodeCookieType(parseCookieType(sessionScores)),
|
863
934
|
scores: decodeCookieType(parseCookieType(visitorScores)),
|
864
|
-
tests: parseCookieType(abTestData)
|
935
|
+
tests: parseCookieType(abTestData),
|
936
|
+
controlGroup: controlGroup === "1",
|
937
|
+
personalizeVariants: decodePersonalizeVariants(personalizeVariants)
|
865
938
|
};
|
939
|
+
return data;
|
866
940
|
}
|
867
941
|
function parseCookieType(type) {
|
868
942
|
if (!type) {
|
@@ -886,9 +960,48 @@ function serializeCookie(data) {
|
|
886
960
|
return [
|
887
961
|
serializeCookieType(data.tests),
|
888
962
|
serializeCookieType(encodeCookieType(data.sessionScores)),
|
889
|
-
serializeCookieType(encodeCookieType(data.scores))
|
963
|
+
serializeCookieType(encodeCookieType(data.scores)),
|
964
|
+
data.controlGroup ? "1" : "0",
|
965
|
+
serializePersonalizeVariants(data)
|
890
966
|
].join(TYPE_SEP);
|
891
967
|
}
|
968
|
+
function serializePersonalizeVariants({
|
969
|
+
personalizeVariants
|
970
|
+
}) {
|
971
|
+
const data = {};
|
972
|
+
if (typeof personalizeVariants === "object") {
|
973
|
+
Object.keys(personalizeVariants).forEach((personalizationName) => {
|
974
|
+
const results = [];
|
975
|
+
const variants = personalizeVariants[personalizationName];
|
976
|
+
variants.forEach((variant) => {
|
977
|
+
results.push(`${variant.index}:${variant.control ? "1" : "0"}`);
|
978
|
+
});
|
979
|
+
data[personalizationName] = results.join(",");
|
980
|
+
});
|
981
|
+
}
|
982
|
+
const serialized = serializeCookieType(data);
|
983
|
+
return serialized;
|
984
|
+
}
|
985
|
+
function decodePersonalizeVariants(data) {
|
986
|
+
const parsed = parseCookieType(data);
|
987
|
+
const keys = Object.keys(parsed);
|
988
|
+
if (!keys.length) {
|
989
|
+
return void 0;
|
990
|
+
}
|
991
|
+
const results = {};
|
992
|
+
Object.keys(parsed).forEach((k) => {
|
993
|
+
const variants = parsed[k].split(",");
|
994
|
+
const key = decodeURIComponent(k);
|
995
|
+
results[key] = variants.map((variant) => {
|
996
|
+
const [index, control] = variant.split(":");
|
997
|
+
return {
|
998
|
+
index: parseInt(index, 10),
|
999
|
+
control: control === "1"
|
1000
|
+
};
|
1001
|
+
});
|
1002
|
+
});
|
1003
|
+
return results;
|
1004
|
+
}
|
892
1005
|
function encodeCookieType(type) {
|
893
1006
|
return Object.entries(type).reduce((acc, [key, value]) => {
|
894
1007
|
acc[key] = ntob(value);
|
@@ -976,7 +1089,8 @@ var emptyVisitorData = () => ({
|
|
976
1089
|
sessionScores: {},
|
977
1090
|
tests: {},
|
978
1091
|
consent: false,
|
979
|
-
controlGroup: false
|
1092
|
+
controlGroup: false,
|
1093
|
+
personalizeVariants: {}
|
980
1094
|
});
|
981
1095
|
|
982
1096
|
// src/storage/VisitorDataStore.ts
|
@@ -1025,6 +1139,25 @@ function applyCommandsToData(commands, state, inControlGroup) {
|
|
1025
1139
|
case "setcontrol":
|
1026
1140
|
newData.controlGroup = command.data;
|
1027
1141
|
break;
|
1142
|
+
case "setpersonalizecontrol":
|
1143
|
+
if (!newData.personalizeVariants) {
|
1144
|
+
newData.personalizeVariants = {};
|
1145
|
+
}
|
1146
|
+
if (!newData.personalizeVariants[command.data.personlizationName]) {
|
1147
|
+
newData.personalizeVariants[command.data.personlizationName] = [];
|
1148
|
+
}
|
1149
|
+
const existingDef = newData.personalizeVariants[command.data.personlizationName].find(
|
1150
|
+
(i) => i.index === command.data.index
|
1151
|
+
);
|
1152
|
+
if (!existingDef) {
|
1153
|
+
newData.personalizeVariants[command.data.personlizationName].push({
|
1154
|
+
index: command.data.index,
|
1155
|
+
control: command.data.control
|
1156
|
+
});
|
1157
|
+
} else {
|
1158
|
+
console.warn("Overwriting existing control group definition is not allowed");
|
1159
|
+
}
|
1160
|
+
break;
|
1028
1161
|
default:
|
1029
1162
|
throw new Error(`Unknown command`);
|
1030
1163
|
}
|
@@ -1386,7 +1519,7 @@ var Context = class {
|
|
1386
1519
|
* will NOT result in a recomputation of signal state.
|
1387
1520
|
*/
|
1388
1521
|
async update(newData) {
|
1389
|
-
var _a, _b, _c;
|
1522
|
+
var _a, _b, _c, _d;
|
1390
1523
|
const commands = [];
|
1391
1524
|
const newServerSideTests = {};
|
1392
1525
|
if ((_a = __privateGet(this, _serverTransitionState)) == null ? void 0 : _a.quirks) {
|
@@ -1416,6 +1549,17 @@ var Context = class {
|
|
1416
1549
|
);
|
1417
1550
|
}
|
1418
1551
|
}
|
1552
|
+
if ((_c = __privateGet(this, _serverTransitionState)) == null ? void 0 : _c.personalizeVariants) {
|
1553
|
+
Object.keys(__privateGet(this, _serverTransitionState).personalizeVariants).forEach((personalizationName) => {
|
1554
|
+
const variants = __privateGet(this, _serverTransitionState).personalizeVariants[personalizationName];
|
1555
|
+
variants.forEach((e) => {
|
1556
|
+
commands.push({
|
1557
|
+
type: "setpersonalizecontrol",
|
1558
|
+
data: { personlizationName: personalizationName, index: e.index, control: e.control }
|
1559
|
+
});
|
1560
|
+
});
|
1561
|
+
});
|
1562
|
+
}
|
1419
1563
|
try {
|
1420
1564
|
__privateGet(this, _mitt3).emit("log", [
|
1421
1565
|
"info",
|
@@ -1425,7 +1569,7 @@ var Context = class {
|
|
1425
1569
|
...newData,
|
1426
1570
|
// need to convert url to string so it can be json serialized
|
1427
1571
|
// to go over postMessage to chrome extension
|
1428
|
-
url: (
|
1572
|
+
url: (_d = newData.url) == null ? void 0 : _d.toString()
|
1429
1573
|
}
|
1430
1574
|
]);
|
1431
1575
|
if (newData.quirks) {
|
@@ -1507,6 +1651,13 @@ var Context = class {
|
|
1507
1651
|
}
|
1508
1652
|
]);
|
1509
1653
|
}
|
1654
|
+
getPersonalizeVariantControl(name, index) {
|
1655
|
+
var _a, _b, _c;
|
1656
|
+
const source = (_b = (_a = __privateGet(this, _serverTransitionState)) == null ? void 0 : _a.personalizeVariants) != null ? _b : this.storage.data.personalizeVariants;
|
1657
|
+
const variants = (_c = source == null ? void 0 : source[name]) != null ? _c : [];
|
1658
|
+
const variant = variants.find((v) => v.index === index);
|
1659
|
+
return variant == null ? void 0 : variant.control;
|
1660
|
+
}
|
1510
1661
|
/**
|
1511
1662
|
* Writes a message to the Context log sink.
|
1512
1663
|
* Used by Uniform internal SDK; not intended for public use.
|
@@ -1549,10 +1700,10 @@ var Context = class {
|
|
1549
1700
|
const previousPlacement = __privateGet(this, _pzCache)[options.name];
|
1550
1701
|
const eventData = {
|
1551
1702
|
name: options.name,
|
1552
|
-
variantIds: value.variations.map((variation) => {
|
1553
|
-
|
1554
|
-
|
1555
|
-
}),
|
1703
|
+
variantIds: value.variations.map((variation) => ({
|
1704
|
+
id: variation.id || "Unknown",
|
1705
|
+
control: variation.control
|
1706
|
+
})),
|
1556
1707
|
control: this.storage.data.controlGroup,
|
1557
1708
|
changed: true
|
1558
1709
|
};
|
@@ -1580,7 +1731,8 @@ var Context = class {
|
|
1580
1731
|
const transitionState = {
|
1581
1732
|
quirks: this.storage.data.quirks,
|
1582
1733
|
ssv: __privateGet(this, _scores),
|
1583
|
-
tests: {}
|
1734
|
+
tests: {},
|
1735
|
+
personalizeVariants: this.storage.data.personalizeVariants
|
1584
1736
|
};
|
1585
1737
|
const allTests = this.storage.data.tests;
|
1586
1738
|
Object.entries(allTests).map(([testName, testValue]) => {
|
@@ -1591,6 +1743,18 @@ var Context = class {
|
|
1591
1743
|
});
|
1592
1744
|
return transitionState;
|
1593
1745
|
}
|
1746
|
+
/** @deprecated */
|
1747
|
+
internal_processTestEvent(event) {
|
1748
|
+
if (event.variantId) {
|
1749
|
+
this.setTestVariantId(event.name, event.variantId);
|
1750
|
+
__privateMethod(this, _emitTest, emitTest_fn).call(this, event);
|
1751
|
+
}
|
1752
|
+
}
|
1753
|
+
/** @deprecated */
|
1754
|
+
internal_processPersonalizationEvent(event) {
|
1755
|
+
__privateGet(this, _pzCache)[event.name] = event.variantIds;
|
1756
|
+
__privateGet(this, _mitt3).emit("personalizationResult", event);
|
1757
|
+
}
|
1594
1758
|
};
|
1595
1759
|
_serverTransitionState = new WeakMap();
|
1596
1760
|
_scores = new WeakMap();
|
@@ -1624,7 +1788,7 @@ calculateScores_fn = function(newData) {
|
|
1624
1788
|
|
1625
1789
|
// src/devTools/enableContextDevTools.ts
|
1626
1790
|
var isBrowser = typeof top !== "undefined";
|
1627
|
-
function enableContextDevTools() {
|
1791
|
+
function enableContextDevTools(options) {
|
1628
1792
|
return {
|
1629
1793
|
logDrain: (message) => {
|
1630
1794
|
if (!isBrowser) {
|
@@ -1677,7 +1841,11 @@ function enableContextDevTools() {
|
|
1677
1841
|
return;
|
1678
1842
|
}
|
1679
1843
|
const message = event.data;
|
1680
|
-
await handleMessageFromDevTools(
|
1844
|
+
await handleMessageFromDevTools({
|
1845
|
+
message,
|
1846
|
+
context,
|
1847
|
+
afterMessageReceived: options == null ? void 0 : options.onAfterMessageReceived
|
1848
|
+
});
|
1681
1849
|
});
|
1682
1850
|
} catch (e) {
|
1683
1851
|
console.warn(
|
@@ -1697,26 +1865,35 @@ function enableContextDevTools() {
|
|
1697
1865
|
context.events.on("personalizationResult", onPersonalizationResult);
|
1698
1866
|
context.events.on("testResult", onTestResult);
|
1699
1867
|
context.events.on("scoresUpdated", onContextDataUpdated);
|
1700
|
-
context.storage.events.on("*", onContextDataUpdated);
|
1701
1868
|
return () => {
|
1702
1869
|
context.events.off("scoresUpdated", onContextDataUpdated);
|
1703
|
-
context.storage.events.off("*", onContextDataUpdated);
|
1704
1870
|
context.events.off("personalizationResult", onPersonalizationResult);
|
1705
1871
|
context.events.off("testResult", onTestResult);
|
1706
1872
|
};
|
1707
1873
|
}
|
1708
1874
|
};
|
1709
1875
|
}
|
1710
|
-
async function handleMessageFromDevTools(
|
1876
|
+
async function handleMessageFromDevTools({
|
1877
|
+
message,
|
1878
|
+
context,
|
1879
|
+
afterMessageReceived
|
1880
|
+
}) {
|
1881
|
+
let receivedUniformMessage = false;
|
1711
1882
|
if (message.type === "uniform-in:context:update" && message.newData) {
|
1883
|
+
receivedUniformMessage = true;
|
1712
1884
|
await context.update(message.newData);
|
1713
1885
|
}
|
1714
1886
|
if (message.type === "uniform-in:context:commands" && message.commands && Array.isArray(message.commands)) {
|
1887
|
+
receivedUniformMessage = true;
|
1715
1888
|
await context.storage.updateData(message.commands);
|
1716
1889
|
}
|
1717
1890
|
if (message.type === "uniform-in:context:forget") {
|
1891
|
+
receivedUniformMessage = true;
|
1718
1892
|
await context.forget(false);
|
1719
1893
|
}
|
1894
|
+
if (receivedUniformMessage && typeof afterMessageReceived === "function") {
|
1895
|
+
afterMessageReceived(message);
|
1896
|
+
}
|
1720
1897
|
}
|
1721
1898
|
|
1722
1899
|
// src/edge/index.ts
|
@@ -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:
|
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
|
/**
|
@@ -1003,7 +1029,24 @@ type ContextEvents = {
|
|
1003
1029
|
/** Personalization variants have been selected */
|
1004
1030
|
personalizationResult: PersonalizationEvent;
|
1005
1031
|
};
|
1006
|
-
|
1032
|
+
interface ContextInstance {
|
1033
|
+
get scores(): Readonly<ScoreVector>;
|
1034
|
+
get quirks(): Readonly<Quirks>;
|
1035
|
+
update(newData: Partial<ContextState>): Promise<void>;
|
1036
|
+
getTestVariantId(testName: string): string | null | undefined;
|
1037
|
+
setTestVariantId(testName: string, variantId: string): void;
|
1038
|
+
log(...message: LogMessage): void;
|
1039
|
+
test<TVariant extends TestVariant>(options: TestOptions<TVariant>): TestResult<TVariant>;
|
1040
|
+
personalize<TVariant extends PersonalizedVariant>(options: PersonalizeOptions<TVariant>): PersonalizedResult<TVariant>;
|
1041
|
+
forget(fromAllDevices: boolean): Promise<void>;
|
1042
|
+
getServerToClientTransitionState(): ServerToClientTransitionState;
|
1043
|
+
readonly manifest: ManifestInstance;
|
1044
|
+
/** @deprecated */
|
1045
|
+
internal_processTestEvent(event: TestEvent): void;
|
1046
|
+
/** @deprecated */
|
1047
|
+
internal_processPersonalizationEvent(event: PersonalizationEvent): void;
|
1048
|
+
}
|
1049
|
+
declare class Context implements ContextInstance {
|
1007
1050
|
#private;
|
1008
1051
|
readonly manifest: ManifestInstance;
|
1009
1052
|
constructor(options: ContextOptions);
|
@@ -1039,6 +1082,7 @@ declare class Context implements Context {
|
|
1039
1082
|
getTestVariantId(testName: string): string | null | undefined;
|
1040
1083
|
/** use test() instead */
|
1041
1084
|
setTestVariantId(testName: string, variantId: string): void;
|
1085
|
+
getPersonalizeVariantControl(name: string, index: number): boolean | undefined;
|
1042
1086
|
/**
|
1043
1087
|
* Writes a message to the Context log sink.
|
1044
1088
|
* Used by Uniform internal SDK; not intended for public use.
|
@@ -1059,6 +1103,10 @@ declare class Context implements Context {
|
|
1059
1103
|
* Removes state from server-to-client if it came in initial state (cookies) to avoid double tracking on the client.
|
1060
1104
|
*/
|
1061
1105
|
getServerToClientTransitionState(): ServerToClientTransitionState;
|
1106
|
+
/** @deprecated */
|
1107
|
+
internal_processTestEvent(event: TestEvent): void;
|
1108
|
+
/** @deprecated */
|
1109
|
+
internal_processPersonalizationEvent(event: PersonalizationEvent): void;
|
1062
1110
|
}
|
1063
1111
|
|
1064
1112
|
/**
|
@@ -1125,4 +1173,4 @@ declare global {
|
|
1125
1173
|
}
|
1126
1174
|
}
|
1127
1175
|
|
1128
|
-
export {
|
1176
|
+
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 };
|