@uniformdev/context 20.6.2-alpha.11 → 20.7.1-alpha.14
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 +8 -1
- package/dist/api/api.d.ts +8 -1
- package/dist/api/api.js +8 -2
- package/dist/api/api.mjs +8 -2
- package/dist/index.d.mts +4 -33
- package/dist/index.d.ts +4 -33
- package/dist/index.esm.js +39 -216
- package/dist/index.js +40 -221
- package/dist/index.mjs +39 -216
- package/dist/{types-CzIkFCDD.d.mts → types-EJl31yuP.d.mts} +24 -96
- package/dist/{types-CzIkFCDD.d.ts → types-EJl31yuP.d.ts} +24 -96
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
@@ -516,7 +516,7 @@ var GroupCriteriaEvaluator = class {
|
|
516
516
|
_evaluators = new WeakMap();
|
517
517
|
|
518
518
|
// src/placement/criteria/evaluateVariantMatch.ts
|
519
|
-
function evaluateVariantMatch(variantId, match, vec, onLogMessage
|
519
|
+
function evaluateVariantMatch(variantId, match, vec, onLogMessage) {
|
520
520
|
onLogMessage == null ? void 0 : onLogMessage(["info", 301, "GROUP", { id: variantId, op: match == null ? void 0 : match.op }]);
|
521
521
|
let result;
|
522
522
|
try {
|
@@ -524,9 +524,9 @@ function evaluateVariantMatch(variantId, match, vec, onLogMessage, quirks) {
|
|
524
524
|
onLogMessage == null ? void 0 : onLogMessage(["info", 302, { matched: true, description: "default variation" }]);
|
525
525
|
result = true;
|
526
526
|
} else if (!match.op || match.op === "&") {
|
527
|
-
result = match.crit.every((c) =>
|
527
|
+
result = match.crit.every((c) => evaluateDimensionMatch(c, vec, onLogMessage));
|
528
528
|
} else {
|
529
|
-
result = match.crit.some((c) =>
|
529
|
+
result = match.crit.some((c) => evaluateDimensionMatch(c, vec, onLogMessage));
|
530
530
|
}
|
531
531
|
onLogMessage == null ? void 0 : onLogMessage(["info", 303, result]);
|
532
532
|
} finally {
|
@@ -534,16 +534,9 @@ function evaluateVariantMatch(variantId, match, vec, onLogMessage, quirks) {
|
|
534
534
|
}
|
535
535
|
return result;
|
536
536
|
}
|
537
|
-
function evaluateMatch(crit, vec, quirks, onLogMessage) {
|
538
|
-
if ("t" in crit && crit.t === "q") {
|
539
|
-
return evaluateQuirkMatch(crit, quirks, onLogMessage);
|
540
|
-
} else {
|
541
|
-
return evaluateDimensionMatch(crit, vec, onLogMessage);
|
542
|
-
}
|
543
|
-
}
|
544
537
|
function evaluateDimensionMatch(crit, vec, onLogMessage) {
|
545
538
|
var _a, _b;
|
546
|
-
const { l: lhs
|
539
|
+
const { op, l: lhs } = crit;
|
547
540
|
const lhsScore = (_a = vec[lhs]) != null ? _a : 0;
|
548
541
|
if (op === "^") {
|
549
542
|
const [cat] = lhs.split(ENR_SEPARATOR);
|
@@ -610,65 +603,33 @@ function evaluateDimensionMatch(crit, vec, onLogMessage) {
|
|
610
603
|
}
|
611
604
|
if (op === ">") {
|
612
605
|
const result = lhsScore > rhsScore;
|
613
|
-
|
606
|
+
explain(onLogMessage, result, crit, lhsScore, rhsScore);
|
614
607
|
return result;
|
615
608
|
} else if (op === ">=") {
|
616
609
|
const result = lhsScore >= rhsScore;
|
617
|
-
|
610
|
+
explain(onLogMessage, result, crit, lhsScore, rhsScore);
|
618
611
|
return result;
|
619
612
|
} else if (op === "<") {
|
620
613
|
const result = lhsScore < rhsScore;
|
621
|
-
|
614
|
+
explain(onLogMessage, result, crit, lhsScore, rhsScore);
|
622
615
|
return result;
|
623
616
|
} else if (op === "<=") {
|
624
617
|
const result = lhsScore <= rhsScore;
|
625
|
-
|
618
|
+
explain(onLogMessage, result, crit, lhsScore, rhsScore);
|
626
619
|
return result;
|
627
620
|
} else if (op === "=") {
|
628
621
|
const result = lhsScore === rhsScore;
|
629
|
-
|
622
|
+
explain(onLogMessage, result, crit, lhsScore, rhsScore);
|
630
623
|
return result;
|
631
624
|
} else if (op === "!=") {
|
632
625
|
const result = lhsScore !== rhsScore;
|
633
|
-
|
626
|
+
explain(onLogMessage, result, crit, lhsScore, rhsScore);
|
634
627
|
return result;
|
635
628
|
} else {
|
636
|
-
|
637
|
-
"error",
|
638
|
-
302,
|
639
|
-
{
|
640
|
-
matched: false,
|
641
|
-
description: `${crit.l} ${crit.op} ${crit.rDim ? `${crit.rDim}` : crit.r}: Unknown op ${crit.op}.`
|
642
|
-
}
|
643
|
-
]);
|
644
|
-
return false;
|
645
|
-
}
|
646
|
-
}
|
647
|
-
function evaluateQuirkMatch(crit, quirks, onLogMessage) {
|
648
|
-
var _a;
|
649
|
-
const { l: targetQuirk, op, r: targetValue } = crit;
|
650
|
-
const targetQuirkValue = (_a = quirks[targetQuirk]) != null ? _a : "";
|
651
|
-
if (op === "=") {
|
652
|
-
const result = targetQuirkValue === targetValue;
|
653
|
-
explainQuirk(onLogMessage, result, crit, targetQuirkValue);
|
654
|
-
return result;
|
655
|
-
} else if (op === "!=") {
|
656
|
-
const result = targetQuirkValue !== targetValue;
|
657
|
-
explainQuirk(onLogMessage, result, crit, targetQuirkValue);
|
658
|
-
return result;
|
659
|
-
} else {
|
660
|
-
onLogMessage == null ? void 0 : onLogMessage([
|
661
|
-
"error",
|
662
|
-
302,
|
663
|
-
{
|
664
|
-
matched: false,
|
665
|
-
description: `Quirk ${crit.l} ${crit.op} ${crit.r}: Unknown quirk op ${crit.op}.`
|
666
|
-
}
|
667
|
-
]);
|
668
|
-
return false;
|
629
|
+
throw new Error(`Unknown op: ${op}`);
|
669
630
|
}
|
670
631
|
}
|
671
|
-
function
|
632
|
+
function explain(onLogMessage, result, crit, lhsScore, rhsScore) {
|
672
633
|
onLogMessage == null ? void 0 : onLogMessage([
|
673
634
|
"info",
|
674
635
|
302,
|
@@ -678,20 +639,9 @@ function explainScore(onLogMessage, result, crit, lhsScore, rhsScore) {
|
|
678
639
|
}
|
679
640
|
]);
|
680
641
|
}
|
681
|
-
function explainQuirk(onLogMessage, result, crit, lhs) {
|
682
|
-
onLogMessage == null ? void 0 : onLogMessage([
|
683
|
-
"info",
|
684
|
-
302,
|
685
|
-
{
|
686
|
-
matched: result,
|
687
|
-
description: `Quirk ${crit.l}[${lhs}] ${crit.op} ${crit.r}`
|
688
|
-
}
|
689
|
-
]);
|
690
|
-
}
|
691
642
|
|
692
|
-
// src/placement/
|
693
|
-
|
694
|
-
function topDownCriteriaPersonalizationSelectionAlgorithm({
|
643
|
+
// src/placement/personalize.ts
|
644
|
+
function personalizeVariations({
|
695
645
|
name,
|
696
646
|
context,
|
697
647
|
variations,
|
@@ -701,35 +651,27 @@ function topDownCriteriaPersonalizationSelectionAlgorithm({
|
|
701
651
|
var _a, _b, _c;
|
702
652
|
onLogMessage == null ? void 0 : onLogMessage(["info", 300, "GROUP", { name, take }]);
|
703
653
|
try {
|
704
|
-
const
|
705
|
-
const
|
706
|
-
const
|
707
|
-
const
|
708
|
-
for (const
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
const { pz, ...validParts } = variation;
|
713
|
-
validVariation = validParts;
|
714
|
-
} else {
|
715
|
-
validVariation = variation;
|
716
|
-
}
|
717
|
-
if ((_a = validVariation.pz) == null ? void 0 : _a.crit.length) {
|
718
|
-
if (personalizationAllowed && variationMatches.length !== take && evaluateVariantMatch(variation.id, validVariation.pz, context.scores, onLogMessage, context.quirks)) {
|
719
|
-
variationMatches.push(validVariation);
|
654
|
+
const variantMatches = [];
|
655
|
+
const defaultVariants = [];
|
656
|
+
const needsConsent = context.requireConsentForPersonalization;
|
657
|
+
const canEvaluate = !needsConsent || context.storage.data.consent;
|
658
|
+
for (const variant of variations) {
|
659
|
+
if ((_a = variant.pz) == null ? void 0 : _a.crit.length) {
|
660
|
+
if (canEvaluate && variantMatches.length !== take && evaluateVariantMatch(variant.id, variant.pz, context.scores, onLogMessage)) {
|
661
|
+
variantMatches.push(variant);
|
720
662
|
}
|
721
663
|
} else {
|
722
|
-
|
664
|
+
defaultVariants.push(variant);
|
723
665
|
}
|
724
666
|
}
|
725
667
|
const result = [];
|
726
|
-
for (let i = 0; i <
|
668
|
+
for (let i = 0; i < variantMatches.length; i++) {
|
727
669
|
let isControl = (_b = context.storage.data.controlGroup) != null ? _b : false;
|
728
|
-
const
|
729
|
-
if (!isControl && typeof ((_c =
|
670
|
+
const variant = variantMatches[i];
|
671
|
+
if (!isControl && typeof ((_c = variant.pz) == null ? void 0 : _c.control) === "number") {
|
730
672
|
isControl = context.getPersonalizeVariantControl(name, i);
|
731
673
|
if (typeof isControl === "undefined") {
|
732
|
-
isControl = rollForControlGroup(
|
674
|
+
isControl = rollForControlGroup(variant.pz.control);
|
733
675
|
context.storage.updateData([
|
734
676
|
{
|
735
677
|
type: "setpersonalizecontrol",
|
@@ -742,13 +684,13 @@ function topDownCriteriaPersonalizationSelectionAlgorithm({
|
|
742
684
|
]);
|
743
685
|
}
|
744
686
|
}
|
745
|
-
let variantToAdd =
|
687
|
+
let variantToAdd = variant;
|
746
688
|
if (isControl) {
|
747
|
-
const defaultReplacement =
|
689
|
+
const defaultReplacement = defaultVariants.shift();
|
748
690
|
if (defaultReplacement) {
|
749
691
|
variantToAdd = {
|
750
692
|
...defaultReplacement,
|
751
|
-
id:
|
693
|
+
id: variant.id
|
752
694
|
};
|
753
695
|
} else {
|
754
696
|
variantToAdd = void 0;
|
@@ -758,8 +700,8 @@ function topDownCriteriaPersonalizationSelectionAlgorithm({
|
|
758
700
|
result.push({ ...variantToAdd, control: isControl });
|
759
701
|
}
|
760
702
|
}
|
761
|
-
while (result.length < take &&
|
762
|
-
result.push({ ...
|
703
|
+
while (result.length < take && defaultVariants.length) {
|
704
|
+
result.push({ ...defaultVariants.shift(), control: false });
|
763
705
|
}
|
764
706
|
const personalized = result.some((v) => {
|
765
707
|
var _a2;
|
@@ -774,86 +716,7 @@ function topDownCriteriaPersonalizationSelectionAlgorithm({
|
|
774
716
|
}
|
775
717
|
}
|
776
718
|
|
777
|
-
// src/placement/
|
778
|
-
function personalizeVariations(options) {
|
779
|
-
return topDownCriteriaPersonalizationSelectionAlgorithm(options);
|
780
|
-
}
|
781
|
-
|
782
|
-
// src/placement/strongestScorePersonalizationSelectionAlgorithm.ts
|
783
|
-
var STRONGEST_SCORE_PERSONALIZATION_ALGORITHM = "ssc";
|
784
|
-
function strongestScorePersonalizationSelectionAlgorithm({
|
785
|
-
name,
|
786
|
-
context,
|
787
|
-
variations,
|
788
|
-
take = 1,
|
789
|
-
onLogMessage
|
790
|
-
}) {
|
791
|
-
var _a, _b;
|
792
|
-
onLogMessage == null ? void 0 : onLogMessage(["info", 300, "GROUP", { name, take }]);
|
793
|
-
try {
|
794
|
-
const variationMatches = [];
|
795
|
-
const defaultVariations = [];
|
796
|
-
const needsConsentToPersonalize = context.requireConsentForPersonalization;
|
797
|
-
const isInGlobalControlGroup = (_a = context.storage.data.controlGroup) != null ? _a : false;
|
798
|
-
const personalizationAllowed = !needsConsentToPersonalize || context.storage.data.consent;
|
799
|
-
for (const variation of variations) {
|
800
|
-
const isInvalidFormat = variation.pz && typeof variation.pz !== "object";
|
801
|
-
let validVariation;
|
802
|
-
if (isInvalidFormat) {
|
803
|
-
const { pz, ...validParts } = variation;
|
804
|
-
validVariation = validParts;
|
805
|
-
} else {
|
806
|
-
validVariation = variation;
|
807
|
-
}
|
808
|
-
if ((_b = validVariation.pz) == null ? void 0 : _b.dim) {
|
809
|
-
if (!personalizationAllowed) {
|
810
|
-
continue;
|
811
|
-
}
|
812
|
-
const score = context.scores[validVariation.pz.dim];
|
813
|
-
if (score === void 0 || score <= 0) {
|
814
|
-
continue;
|
815
|
-
}
|
816
|
-
variationMatches.push({ variation: validVariation, score });
|
817
|
-
} else {
|
818
|
-
defaultVariations.push(validVariation);
|
819
|
-
}
|
820
|
-
}
|
821
|
-
variationMatches.sort((a, b) => b.score - a.score);
|
822
|
-
const result = [];
|
823
|
-
for (let i = 0; i < variationMatches.length; i++) {
|
824
|
-
const variationMatch = variationMatches[i];
|
825
|
-
let variantToAdd = variationMatch.variation;
|
826
|
-
if (i >= take) {
|
827
|
-
continue;
|
828
|
-
}
|
829
|
-
if (isInGlobalControlGroup) {
|
830
|
-
const defaultReplacement = defaultVariations.shift();
|
831
|
-
if (defaultReplacement) {
|
832
|
-
variantToAdd = {
|
833
|
-
...defaultReplacement,
|
834
|
-
id: variationMatch.variation.id
|
835
|
-
};
|
836
|
-
} else {
|
837
|
-
variantToAdd = void 0;
|
838
|
-
}
|
839
|
-
}
|
840
|
-
if (variantToAdd) {
|
841
|
-
result.push({ ...variantToAdd, control: isInGlobalControlGroup });
|
842
|
-
}
|
843
|
-
}
|
844
|
-
while (result.length < take && defaultVariations.length) {
|
845
|
-
result.push({ ...defaultVariations.shift(), control: false });
|
846
|
-
}
|
847
|
-
return {
|
848
|
-
personalized: variationMatches.length > 0 && !isInGlobalControlGroup,
|
849
|
-
variations: result
|
850
|
-
};
|
851
|
-
} finally {
|
852
|
-
onLogMessage == null ? void 0 : onLogMessage(["info", 300, "ENDGROUP"]);
|
853
|
-
}
|
854
|
-
}
|
855
|
-
|
856
|
-
// src/placement/normalizeVariationDistributions.ts
|
719
|
+
// src/placement/test.ts
|
857
720
|
var normalizeVariationDistributions = (variations) => {
|
858
721
|
const { values, total, missingDistribution } = variations.reduce(
|
859
722
|
(previous, current) => {
|
@@ -872,12 +735,7 @@ var normalizeVariationDistributions = (variations) => {
|
|
872
735
|
}
|
873
736
|
);
|
874
737
|
if (total > 100) {
|
875
|
-
|
876
|
-
values.forEach((value, index) => {
|
877
|
-
if (typeof value === "number") {
|
878
|
-
values[index] = value * autoScaleFactor;
|
879
|
-
}
|
880
|
-
});
|
738
|
+
throw new Error(`Total distribution ${total} is over the maximum 100.`);
|
881
739
|
} else if (total < 100) {
|
882
740
|
const remainder = 100 - total;
|
883
741
|
const missingSlice = remainder / missingDistribution;
|
@@ -889,8 +747,6 @@ var normalizeVariationDistributions = (variations) => {
|
|
889
747
|
}
|
890
748
|
return values;
|
891
749
|
};
|
892
|
-
|
893
|
-
// src/placement/testVariations.ts
|
894
750
|
var testVariations = ({
|
895
751
|
name,
|
896
752
|
context,
|
@@ -1657,12 +1513,11 @@ import { dequal as dequal5 } from "dequal/lite";
|
|
1657
1513
|
import mitt3 from "mitt";
|
1658
1514
|
var CONTEXTUAL_EDITING_TEST_NAME = "contextual_editing_test";
|
1659
1515
|
var CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID = "contextual_editing_test_selected_variant";
|
1660
|
-
var
|
1516
|
+
var _serverTransitionState, _scores, _state, _pzCache, _plugins, _commands, _requireConsentForPersonalization, _mitt3, _Context_instances, emitTest_fn, updateGoals_fn, updateComputedScores_fn, calculateScores_fn;
|
1661
1517
|
var Context = class {
|
1662
1518
|
constructor(options) {
|
1663
1519
|
__privateAdd(this, _Context_instances);
|
1664
1520
|
__publicField(this, "manifest");
|
1665
|
-
__privateAdd(this, _personalizationSelectionAlgorithms);
|
1666
1521
|
__privateAdd(this, _serverTransitionState);
|
1667
1522
|
__privateAdd(this, _scores, {});
|
1668
1523
|
__privateAdd(this, _state);
|
@@ -1679,7 +1534,7 @@ var Context = class {
|
|
1679
1534
|
off: __privateGet(this, _mitt3).off
|
1680
1535
|
});
|
1681
1536
|
__publicField(this, "storage");
|
1682
|
-
var _a, _b
|
1537
|
+
var _a, _b;
|
1683
1538
|
const { manifest, ...storageOptions } = options;
|
1684
1539
|
__privateSet(this, _state, {});
|
1685
1540
|
__privateSet(this, _plugins, options.plugins);
|
@@ -1687,20 +1542,7 @@ var Context = class {
|
|
1687
1542
|
if (typeof options.transitionStore !== "undefined") {
|
1688
1543
|
__privateSet(this, _commands, []);
|
1689
1544
|
}
|
1690
|
-
__privateSet(this, _personalizationSelectionAlgorithms, {
|
1691
|
-
[TOP_DOWN_CRITERIA_PERSONALIZATION_ALGORITHM]: topDownCriteriaPersonalizationSelectionAlgorithm,
|
1692
|
-
[STRONGEST_SCORE_PERSONALIZATION_ALGORITHM]: strongestScorePersonalizationSelectionAlgorithm
|
1693
|
-
});
|
1694
1545
|
(_a = __privateGet(this, _plugins)) == null ? void 0 : _a.forEach((plugin) => {
|
1695
|
-
if (!plugin.personalizationSelectionAlgorithms) {
|
1696
|
-
return;
|
1697
|
-
}
|
1698
|
-
__privateSet(this, _personalizationSelectionAlgorithms, {
|
1699
|
-
...__privateGet(this, _personalizationSelectionAlgorithms),
|
1700
|
-
...plugin.personalizationSelectionAlgorithms
|
1701
|
-
});
|
1702
|
-
});
|
1703
|
-
(_b = __privateGet(this, _plugins)) == null ? void 0 : _b.forEach((plugin) => {
|
1704
1546
|
if (!plugin.logDrain) {
|
1705
1547
|
return;
|
1706
1548
|
}
|
@@ -1751,7 +1593,7 @@ var Context = class {
|
|
1751
1593
|
__privateGet(this, _mitt3).emit("quirksUpdated", quirks.quirks);
|
1752
1594
|
__privateGet(this, _mitt3).emit("log", ["info", 4, quirks.quirks]);
|
1753
1595
|
});
|
1754
|
-
(
|
1596
|
+
(_b = __privateGet(this, _plugins)) == null ? void 0 : _b.forEach((plugin) => {
|
1755
1597
|
if (!plugin.init) {
|
1756
1598
|
return;
|
1757
1599
|
}
|
@@ -2001,17 +1843,7 @@ var Context = class {
|
|
2001
1843
|
}
|
2002
1844
|
/** Executes a personalized placement with a given set of variants */
|
2003
1845
|
personalize(options) {
|
2004
|
-
|
2005
|
-
const algorithmName = (_a = options.algorithm) != null ? _a : TOP_DOWN_CRITERIA_PERSONALIZATION_ALGORITHM;
|
2006
|
-
const algorithm = __privateGet(this, _personalizationSelectionAlgorithms)[algorithmName];
|
2007
|
-
if (!algorithm) {
|
2008
|
-
__privateGet(this, _mitt3).emit("log", ["warn", 304, { algorithm: algorithmName }]);
|
2009
|
-
return {
|
2010
|
-
personalized: false,
|
2011
|
-
variations: []
|
2012
|
-
};
|
2013
|
-
}
|
2014
|
-
const value = algorithm({
|
1846
|
+
const value = personalizeVariations({
|
2015
1847
|
...options,
|
2016
1848
|
context: this,
|
2017
1849
|
onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message)
|
@@ -2085,7 +1917,6 @@ var Context = class {
|
|
2085
1917
|
__privateGet(this, _mitt3).emit("personalizationResult", event);
|
2086
1918
|
}
|
2087
1919
|
};
|
2088
|
-
_personalizationSelectionAlgorithms = new WeakMap();
|
2089
1920
|
_serverTransitionState = new WeakMap();
|
2090
1921
|
_scores = new WeakMap();
|
2091
1922
|
_state = new WeakMap();
|
@@ -2681,10 +2512,6 @@ var messageContent = {
|
|
2681
2512
|
301: ({ id, op }) => ["personalization", `testing variation ${id} (${op === "|" ? "OR" : "AND"})`],
|
2682
2513
|
302: ({ matched, description }) => ["personalization", `${description} is ${matched}`],
|
2683
2514
|
303: (selected) => ["personalization", selected ? "selected variation" : "did not select variation"],
|
2684
|
-
304: ({ algorithm }) => [
|
2685
|
-
"personalization",
|
2686
|
-
`personalization selection algorithm '${algorithm}' not found. Hiding placement.`
|
2687
|
-
],
|
2688
2515
|
// TESTING
|
2689
2516
|
400: (name) => ["testing", `executing A/B test '${name}'`],
|
2690
2517
|
401: (testName) => ["testing", `${testName} is not registered in the manifest; it will not be run.`],
|
@@ -2789,9 +2616,7 @@ export {
|
|
2789
2616
|
PAIR_SEP,
|
2790
2617
|
QUIRK_SEP,
|
2791
2618
|
SERVER_STATE_ID,
|
2792
|
-
STRONGEST_SCORE_PERSONALIZATION_ALGORITHM,
|
2793
2619
|
ScriptType,
|
2794
|
-
TOP_DOWN_CRITERIA_PERSONALIZATION_ALGORITHM,
|
2795
2620
|
TYPE_SEP,
|
2796
2621
|
TransitionDataStore,
|
2797
2622
|
UNIFORM_DEFAULT_COOKIE_NAME,
|
@@ -2833,7 +2658,5 @@ export {
|
|
2833
2658
|
serializePersonalizeVariants,
|
2834
2659
|
serializeQuickConnect,
|
2835
2660
|
serializeQuirks,
|
2836
|
-
|
2837
|
-
testVariations,
|
2838
|
-
topDownCriteriaPersonalizationSelectionAlgorithm
|
2661
|
+
testVariations
|
2839
2662
|
};
|
@@ -859,10 +859,6 @@ type LogMessages = {
|
|
859
859
|
}>;
|
860
860
|
/** Final result for a personalized variation */
|
861
861
|
303: MessageFunc<boolean>;
|
862
|
-
/** Personalization algorithm not found */
|
863
|
-
304: MessageFunc<{
|
864
|
-
algorithm: string;
|
865
|
-
}>;
|
866
862
|
/** A/B test placement executing */
|
867
863
|
400: MessageFunc<string>;
|
868
864
|
/** A/B Test definition did not exist */
|
@@ -902,34 +898,23 @@ type LogMessageSingle<TID extends keyof LogMessages = keyof LogMessages> = [
|
|
902
898
|
type LogMessageGroup<TID extends keyof LogMessages = keyof LogMessages> = [severity: Severity, id: TID, group: 'GROUP', ...args: Parameters<LogMessages[TID]>] | [severity: Severity, id: TID, group: 'ENDGROUP'];
|
903
899
|
type LogDrain = (message: LogMessage) => void;
|
904
900
|
|
905
|
-
|
906
|
-
interface VariantMatchCriteria extends VariationMatchMetadata {
|
901
|
+
type VariantMatchCriteria = {
|
907
902
|
/**
|
908
903
|
* Operation for match criteria
|
909
904
|
*
|
910
905
|
* @defaultValue `&`
|
911
906
|
*/
|
912
907
|
op?: '&' | '|';
|
913
|
-
crit:
|
908
|
+
crit: DimensionMatch[];
|
914
909
|
/**
|
915
|
-
*
|
910
|
+
* Name of the variant for analytics tracking.
|
916
911
|
*/
|
917
|
-
|
918
|
-
}
|
919
|
-
/** Data for a personalization variation using the TODO selection algorithm */
|
920
|
-
interface VariationMatchDimensionCriteria extends VariationMatchMetadata {
|
921
|
-
/** The dimension this content is relevant to */
|
922
|
-
dim: string | undefined;
|
923
|
-
}
|
924
|
-
/** Data that must exist on a personalization variation regardless of selection algorithm */
|
925
|
-
interface VariationMatchMetadata {
|
912
|
+
name?: string;
|
926
913
|
/**
|
927
|
-
*
|
928
|
-
* NOTE: name is optional for backwards compatibility, but it is HIGHLY recommended to specify a name
|
929
|
-
* as the default fallback is not helpfully named and is reliant on the order of the variations array.
|
914
|
+
* Control group percentage for the variant.
|
930
915
|
*/
|
931
|
-
|
932
|
-
}
|
916
|
+
control?: number;
|
917
|
+
};
|
933
918
|
type DimensionMatch = {
|
934
919
|
/**
|
935
920
|
* Left hand side of the match expression (name of dimension in score vector)
|
@@ -968,48 +953,17 @@ type DimensionMatch = {
|
|
968
953
|
*/
|
969
954
|
rDim?: string;
|
970
955
|
};
|
971
|
-
type QuirkMatch = {
|
972
|
-
/**
|
973
|
-
* Type of match expression; 'q' discriminates quirk matches from dimension matches
|
974
|
-
*/
|
975
|
-
t: 'q';
|
976
|
-
/**
|
977
|
-
* Left hand side of the match expression (name of quirk)
|
978
|
-
* NOTE: if the quirk is not present
|
979
|
-
*/
|
980
|
-
l: string;
|
981
|
-
/**
|
982
|
-
* Operator of the match expression
|
983
|
-
* Comparison operators:
|
984
|
-
* =: `l` is equal to the right hand side expression
|
985
|
-
* !=: `l` is not equal to the right hand side expression
|
986
|
-
*/
|
987
|
-
op: '=' | '!=';
|
988
|
-
/**
|
989
|
-
* Right hand side of the match expression
|
990
|
-
* This value is treated as a constant value, if it is present. If it's a string, it is parsed to an integer.
|
991
|
-
* To reference another score dimension as the RHS, use the `rDim` property instead.
|
992
|
-
* `r` and `rDim` are mutually exclusive; if both are specified, then `rDim` wins.
|
993
|
-
*/
|
994
|
-
r: string;
|
995
|
-
/**
|
996
|
-
* Only here to maintain object compatibility with DimensionMatch.
|
997
|
-
* Completely ignored.
|
998
|
-
* @deprecated this is not used with QuirkMatch.
|
999
|
-
*/
|
1000
|
-
rDim?: string;
|
1001
|
-
};
|
1002
956
|
|
1003
957
|
/** Content that is tagged for adding enrichment score when triggered by behavior (i.e. being shown that content) */
|
1004
958
|
type BehaviorTag = {
|
1005
959
|
beh?: EnrichmentData[];
|
1006
960
|
};
|
1007
961
|
/** Defines the shape of a personalized content variant */
|
1008
|
-
type PersonalizedVariant
|
962
|
+
type PersonalizedVariant = {
|
1009
963
|
/** A unique identifier for this variation */
|
1010
964
|
id: string;
|
1011
965
|
/** Match criteria for this variation */
|
1012
|
-
pz?:
|
966
|
+
pz?: VariantMatchCriteria;
|
1013
967
|
};
|
1014
968
|
/** The result of computing personalized content from variations */
|
1015
969
|
type PersonalizedResult<TVariant> = {
|
@@ -1017,7 +971,6 @@ type PersonalizedResult<TVariant> = {
|
|
1017
971
|
personalized: boolean;
|
1018
972
|
/** Matching variations */
|
1019
973
|
variations: Array<TVariant & {
|
1020
|
-
/** Whether the visitor is part of this variation's local control group (also true if part of global control group) */
|
1021
974
|
control: boolean;
|
1022
975
|
}>;
|
1023
976
|
};
|
@@ -1042,28 +995,19 @@ type TestResult<TVariant> = {
|
|
1042
995
|
*/
|
1043
996
|
variantAssigned: boolean;
|
1044
997
|
};
|
1045
|
-
|
1046
|
-
|
1047
|
-
name: string;
|
1048
|
-
/** Possible variations to place */
|
1049
|
-
variations: Iterable<TVariant>;
|
1050
|
-
/** Maximum number of variants to place (default: 1) */
|
1051
|
-
take?: number;
|
1052
|
-
/** Name of the personalization selection algorithm to use. Defaults to top-down criteria when not specified. */
|
1053
|
-
algorithm?: string;
|
1054
|
-
}
|
1055
|
-
interface PersonalizationSelectionAlgorithmOptions<TCriteria, TVariant extends PersonalizedVariant<TCriteria> = PersonalizedVariant<TCriteria>> {
|
998
|
+
|
999
|
+
type PersonalizeOptions<TVariant> = {
|
1056
1000
|
/** Name of placement (sent to analytics) */
|
1057
1001
|
name: string;
|
1058
|
-
/** Possible
|
1002
|
+
/** Possible variants to place */
|
1059
1003
|
variations: Iterable<TVariant>;
|
1060
1004
|
/** Maximum number of variants to place (default: 1) */
|
1061
1005
|
take?: number;
|
1062
|
-
/** Callback for logging messages */
|
1063
1006
|
onLogMessage?: (message: LogMessage) => void;
|
1064
|
-
|
1007
|
+
};
|
1008
|
+
declare function personalizeVariations<TVariant extends PersonalizedVariant>({ name, context, variations, take, onLogMessage, }: PersonalizeOptions<TVariant> & {
|
1065
1009
|
context: Context;
|
1066
|
-
}
|
1010
|
+
}): PersonalizedResult<TVariant>;
|
1067
1011
|
|
1068
1012
|
type TestOptions<TVariant extends TestVariant> = {
|
1069
1013
|
/** The name of the test that is being run, must be included in the manifest. */
|
@@ -1078,31 +1022,18 @@ declare const testVariations: <TVariant extends TestVariant>({ name, context, va
|
|
1078
1022
|
|
1079
1023
|
declare const CONTEXTUAL_EDITING_TEST_NAME = "contextual_editing_test";
|
1080
1024
|
declare const CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID = "contextual_editing_test_selected_variant";
|
1081
|
-
type PersonalizationSelectionAlgorithm<TCriteria = unknown> = (options: PersonalizationSelectionAlgorithmOptions<TCriteria>) => PersonalizedResult<PersonalizedVariant<TCriteria>>;
|
1082
|
-
type PersonalizationSelectionAlgorithms<TCriteria = unknown> = Record<string, PersonalizationSelectionAlgorithm<TCriteria>>;
|
1083
1025
|
/**
|
1084
1026
|
* Defines a plugin for Uniform Context.
|
1085
1027
|
* The plugin should attach event handlers in its creation function.
|
1086
1028
|
* @returns A function that detaches any event handlers when called
|
1087
1029
|
*/
|
1088
1030
|
type ContextPlugin = {
|
1089
|
-
/** Defines a log drain for the plugin, which all log messages are sent to */
|
1090
1031
|
logDrain?: LogDrain;
|
1091
|
-
/** Initializes the plugin (attach event handlers here if needed) */
|
1092
1032
|
init?: (context: Context) => () => void;
|
1093
|
-
/** Plugin-specific actions to perform when a user is forgotten */
|
1094
1033
|
forget?: () => Promise<void> | void;
|
1095
|
-
/** Plugin-specific actions to perform when the visitor context is updated */
|
1096
1034
|
update?: (newData: Partial<ContextState>) => Promise<void> | void;
|
1097
|
-
/**
|
1098
|
-
* Allows the plugin to register named personalization selection algorithms
|
1099
|
-
*
|
1100
|
-
* Important: the `default` and `strongestMatch` algorithms are automatically registered.
|
1101
|
-
* We strongly advise against replacing these.
|
1102
|
-
*/
|
1103
|
-
personalizationSelectionAlgorithms?: PersonalizationSelectionAlgorithms<any>;
|
1104
1035
|
};
|
1105
|
-
|
1036
|
+
type ContextOptions = {
|
1106
1037
|
/** The Context Manifest to load (from the Context API) */
|
1107
1038
|
manifest: ManifestV2;
|
1108
1039
|
/**
|
@@ -1119,19 +1050,16 @@ interface ContextOptions extends Omit<VisitorDataStoreOptions, 'manifest' | 'onS
|
|
1119
1050
|
* `true`: personalization is not run at all unless storage consent is given
|
1120
1051
|
*/
|
1121
1052
|
requireConsentForPersonalization?: boolean;
|
1122
|
-
}
|
1123
|
-
type PersonalizationEventVariantId = {
|
1124
|
-
/** The variant ID that was selected */
|
1125
|
-
id: string;
|
1126
|
-
/** Whether the visitor is part of this variant's local control group (also true if part of global control group) */
|
1127
|
-
control: boolean;
|
1128
|
-
};
|
1053
|
+
} & Omit<VisitorDataStoreOptions, 'manifest' | 'onServerTransitionScoresReceived'>;
|
1129
1054
|
/** Emitted when a personalization runs */
|
1130
1055
|
type PersonalizationEvent = {
|
1131
1056
|
/** Name of the personalized placement */
|
1132
1057
|
name: string;
|
1133
1058
|
/** Selected variant ID(s) */
|
1134
|
-
variantIds:
|
1059
|
+
variantIds: {
|
1060
|
+
id: string;
|
1061
|
+
control: boolean;
|
1062
|
+
}[];
|
1135
1063
|
/** Whether the user was part of the control group (and did not receive any personalization) */
|
1136
1064
|
control: boolean | undefined;
|
1137
1065
|
/**
|
@@ -1185,7 +1113,7 @@ interface ContextInstance {
|
|
1185
1113
|
setTestVariantId(testName: string, variantId: string): void;
|
1186
1114
|
log(...message: LogMessage): void;
|
1187
1115
|
test<TVariant extends TestVariant>(options: TestOptions<TVariant>): TestResult<TVariant>;
|
1188
|
-
personalize<TVariant extends PersonalizedVariant
|
1116
|
+
personalize<TVariant extends PersonalizedVariant>(options: PersonalizeOptions<TVariant>): PersonalizedResult<TVariant>;
|
1189
1117
|
forget(fromAllDevices: boolean): Promise<void>;
|
1190
1118
|
getServerToClientTransitionState(): ServerToClientTransitionState;
|
1191
1119
|
readonly manifest: ManifestInstance;
|
@@ -1250,7 +1178,7 @@ declare class Context implements ContextInstance {
|
|
1250
1178
|
/** Executes an A/B test with a given set of variants, showing the visitor's assigned variant (or selecting one to assign, if none is set yet) */
|
1251
1179
|
test<TVariant extends TestVariant>(options: TestOptions<TVariant>): TestResult<TVariant>;
|
1252
1180
|
/** Executes a personalized placement with a given set of variants */
|
1253
|
-
personalize<TVariant extends PersonalizedVariant
|
1181
|
+
personalize<TVariant extends PersonalizedVariant>(options: PersonalizeOptions<TVariant>): PersonalizedResult<TVariant>;
|
1254
1182
|
/**
|
1255
1183
|
* Forgets the visitor's data and resets the Context to its initial state.
|
1256
1184
|
* @param fromAllDevices for an identified user, whether to delete all their data (for the entire account) - true, or data for this device (sign out) - false
|
@@ -1337,4 +1265,4 @@ declare global {
|
|
1337
1265
|
}
|
1338
1266
|
}
|
1339
1267
|
|
1340
|
-
export { type
|
1268
|
+
export { type AggregateDimensionInput 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 Quirks as Q, type PersonalizationManifest as R, type ScoreVector as S, TransitionDataStore as T, type Signal as U, type VisitorData as V, type SignalCriteriaGroup as W, type SignalCriteria as X, type EnrichmentCategory as Y, type NumberMatch as Z, type TestDefinition as _, type StorageCommands as a, type TestOptions as a0, testVariations as a1, type DimensionMatch as a2, type PersonalizeOptions as a3, personalizeVariations as a4, type BehaviorTag as a5, type PersonalizedVariant as a6, type PersonalizedResult as a7, type TestVariant as a8, type TestResult as a9, type ContextStateUpdate as aA, type GoalStateUpdate as aB, type paths as aC, type StorageCommand as aa, type SetGoalCommand as ab, type ModifyScoreCommand as ac, type ModifySessionScoreCommand as ad, type SetConsentCommand as ae, type SetQuirkCommand as af, type SetTestCommand as ag, type IdentifyCommand as ah, type SetControlGroupCommand as ai, type SetPersonalizeVariantControlCommand as aj, areCommandsEqual as ak, type ServerToClientTransitionState as al, SERVER_STATE_ID as am, type TransitionDataStoreEvents as an, type DecayOptions as ao, type VisitorDataStoreOptions as ap, type VisitorDataStoreEvents as aq, VisitorDataStore as ar, type Tests as as, type Goals as at, type EnrichmentData as au, type PersonalizeControlVariant as av, type PersonalizeVariants as aw, type EventData as ax, emptyVisitorData as ay, type ContextState as az, 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 };
|