@uniformdev/context 20.3.1-alpha.7 → 20.4.1-alpha.3
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 +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.esm.js +50 -53
- package/dist/index.js +50 -53
- package/dist/index.mjs +50 -53
- package/dist/{types-gu4PVkDD.d.mts → types-C9cSPjHd.d.mts} +29 -34
- package/dist/{types-gu4PVkDD.d.ts → types-C9cSPjHd.d.ts} +29 -34
- 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, Q as Quirks, 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 {
|
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, Q as Quirks, b as TransitionDataStoreOptions, D as DecayFunction, c as CriteriaEvaluator, d as StringMatch, e as VariantMatchCriteria, f as LogMessage, g as DevToolsEvents } from './types-C9cSPjHd.mjs';
|
2
|
+
export { a0 as AggregateDimensionInput, a6 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, aA as ContextState, aB as ContextStateUpdate, J as CriteriaEvaluatorParameters, I as CriteriaEvaluatorResult, ap 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, a3 as DimensionMatch, Z as EnrichmentCategory, av as EnrichmentData, ay as EventData, aC as GoalStateUpdate, au as Goals, H as GroupCriteriaEvaluator, ai as IdentifyCommand, F as LogMessageGroup, E as LogMessageSingle, y as LogMessages, G as ManifestInstance, N as ManifestV2, M as MessageCategory, B as MessageFunc, ad as ModifyScoreCommand, ae as ModifySessionScoreCommand, _ as NumberMatch, P as PersonalizationEvent, U as PersonalizationManifest, aw as PersonalizeControlVariant, a4 as PersonalizeOptions, ax as PersonalizeVariants, a8 as PersonalizedResult, a7 as PersonalizedVariant, R as RankPersonalizationVariantOptions, an as SERVER_STATE_ID, am as ServerToClientTransitionState, af as SetConsentCommand, aj as SetControlGroupCommand, ac as SetGoalCommand, ak as SetPersonalizeVariantControlCommand, ag as SetQuirkCommand, ah as SetTestCommand, z as Severity, W as Signal, Y as SignalCriteria, X as SignalCriteriaGroup, K as SignalData, ab as StorageCommand, $ as TestDefinition, k as TestEvent, a1 as TestOptions, aa as TestResult, a9 as TestVariant, at as Tests, ao as TransitionDataStoreEvents, as as VisitorDataStore, ar as VisitorDataStoreEvents, aq as VisitorDataStoreOptions, al as areCommandsEqual, az as emptyVisitorData, a5 as personalizeVariations, a2 as testVariations } from './types-C9cSPjHd.mjs';
|
3
3
|
import Cookies from 'js-cookie';
|
4
4
|
import 'mitt';
|
5
5
|
|
@@ -158,7 +158,7 @@ declare function createDebugConsoleLogDrain(level: OutputSeverity, options?: Con
|
|
158
158
|
*/
|
159
159
|
declare function enableDebugConsoleLogDrain(level: OutputSeverity, options?: ConsoleDebugLogDrainOptions): ContextPlugin;
|
160
160
|
|
161
|
-
declare function evaluateVariantMatch(variantId: string, match: VariantMatchCriteria | undefined | null, vec: ScoreVector, onLogMessage?: (message: LogMessage) => void
|
161
|
+
declare function evaluateVariantMatch(variantId: string, match: VariantMatchCriteria | undefined | null, vec: ScoreVector, onLogMessage?: (message: LogMessage) => void): boolean;
|
162
162
|
|
163
163
|
type ContextDevToolOptions = {
|
164
164
|
onAfterMessageReceived?: (message: DevToolsEvents) => void;
|
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, Q as Quirks, 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 {
|
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, Q as Quirks, b as TransitionDataStoreOptions, D as DecayFunction, c as CriteriaEvaluator, d as StringMatch, e as VariantMatchCriteria, f as LogMessage, g as DevToolsEvents } from './types-C9cSPjHd.js';
|
2
|
+
export { a0 as AggregateDimensionInput, a6 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, aA as ContextState, aB as ContextStateUpdate, J as CriteriaEvaluatorParameters, I as CriteriaEvaluatorResult, ap 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, a3 as DimensionMatch, Z as EnrichmentCategory, av as EnrichmentData, ay as EventData, aC as GoalStateUpdate, au as Goals, H as GroupCriteriaEvaluator, ai as IdentifyCommand, F as LogMessageGroup, E as LogMessageSingle, y as LogMessages, G as ManifestInstance, N as ManifestV2, M as MessageCategory, B as MessageFunc, ad as ModifyScoreCommand, ae as ModifySessionScoreCommand, _ as NumberMatch, P as PersonalizationEvent, U as PersonalizationManifest, aw as PersonalizeControlVariant, a4 as PersonalizeOptions, ax as PersonalizeVariants, a8 as PersonalizedResult, a7 as PersonalizedVariant, R as RankPersonalizationVariantOptions, an as SERVER_STATE_ID, am as ServerToClientTransitionState, af as SetConsentCommand, aj as SetControlGroupCommand, ac as SetGoalCommand, ak as SetPersonalizeVariantControlCommand, ag as SetQuirkCommand, ah as SetTestCommand, z as Severity, W as Signal, Y as SignalCriteria, X as SignalCriteriaGroup, K as SignalData, ab as StorageCommand, $ as TestDefinition, k as TestEvent, a1 as TestOptions, aa as TestResult, a9 as TestVariant, at as Tests, ao as TransitionDataStoreEvents, as as VisitorDataStore, ar as VisitorDataStoreEvents, aq as VisitorDataStoreOptions, al as areCommandsEqual, az as emptyVisitorData, a5 as personalizeVariations, a2 as testVariations } from './types-C9cSPjHd.js';
|
3
3
|
import Cookies from 'js-cookie';
|
4
4
|
import 'mitt';
|
5
5
|
|
@@ -158,7 +158,7 @@ declare function createDebugConsoleLogDrain(level: OutputSeverity, options?: Con
|
|
158
158
|
*/
|
159
159
|
declare function enableDebugConsoleLogDrain(level: OutputSeverity, options?: ConsoleDebugLogDrainOptions): ContextPlugin;
|
160
160
|
|
161
|
-
declare function evaluateVariantMatch(variantId: string, match: VariantMatchCriteria | undefined | null, vec: ScoreVector, onLogMessage?: (message: LogMessage) => void
|
161
|
+
declare function evaluateVariantMatch(variantId: string, match: VariantMatchCriteria | undefined | null, vec: ScoreVector, onLogMessage?: (message: LogMessage) => void): boolean;
|
162
162
|
|
163
163
|
type ContextDevToolOptions = {
|
164
164
|
onAfterMessageReceived?: (message: DevToolsEvents) => void;
|
package/dist/index.esm.js
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,49 +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
629
|
throw new Error(`Unknown op: ${op}`);
|
637
630
|
}
|
638
631
|
}
|
639
|
-
function
|
640
|
-
var _a;
|
641
|
-
const { l: targetQuirk, op, r: targetValue } = crit;
|
642
|
-
const targetQuirkValue = (_a = quirks[targetQuirk]) != null ? _a : "";
|
643
|
-
if (op === "=") {
|
644
|
-
const result = targetQuirkValue === targetValue;
|
645
|
-
explainQuirk(onLogMessage, result, crit, targetQuirkValue);
|
646
|
-
return result;
|
647
|
-
} else if (op === "!=") {
|
648
|
-
const result = targetQuirkValue !== targetValue;
|
649
|
-
explainQuirk(onLogMessage, result, crit, targetQuirkValue);
|
650
|
-
return result;
|
651
|
-
} else {
|
652
|
-
throw new Error(`Unknown quirk op: ${op}`);
|
653
|
-
}
|
654
|
-
}
|
655
|
-
function explainScore(onLogMessage, result, crit, lhsScore, rhsScore) {
|
632
|
+
function explain(onLogMessage, result, crit, lhsScore, rhsScore) {
|
656
633
|
onLogMessage == null ? void 0 : onLogMessage([
|
657
634
|
"info",
|
658
635
|
302,
|
@@ -662,24 +639,36 @@ function explainScore(onLogMessage, result, crit, lhsScore, rhsScore) {
|
|
662
639
|
}
|
663
640
|
]);
|
664
641
|
}
|
665
|
-
function explainQuirk(onLogMessage, result, crit, lhs) {
|
666
|
-
onLogMessage == null ? void 0 : onLogMessage([
|
667
|
-
"info",
|
668
|
-
302,
|
669
|
-
{
|
670
|
-
matched: result,
|
671
|
-
description: `Quirk ${crit.l}[${lhs}] ${crit.op} ${crit.r}`
|
672
|
-
}
|
673
|
-
]);
|
674
|
-
}
|
675
642
|
|
676
|
-
// src/placement/
|
643
|
+
// src/placement/personalize.ts
|
644
|
+
var sortVariations = ({
|
645
|
+
variations,
|
646
|
+
rankVariant
|
647
|
+
}) => {
|
648
|
+
const variationsWithScores = Array.from(variations).map((variant) => {
|
649
|
+
const score = rankVariant == null ? void 0 : rankVariant(variant);
|
650
|
+
return {
|
651
|
+
variant,
|
652
|
+
score
|
653
|
+
};
|
654
|
+
});
|
655
|
+
const variantsWithDefinedScores = variationsWithScores.filter((v) => v.score !== void 0);
|
656
|
+
const variantsWithUndefinedScores = variationsWithScores.filter((v) => v.score === void 0);
|
657
|
+
return [
|
658
|
+
...variantsWithDefinedScores.sort((a, b) => {
|
659
|
+
var _a, _b;
|
660
|
+
return ((_a = b.score) != null ? _a : 0) - ((_b = a.score) != null ? _b : 0);
|
661
|
+
}).map((v) => v.variant),
|
662
|
+
...variantsWithUndefinedScores.map((v) => v.variant)
|
663
|
+
];
|
664
|
+
};
|
677
665
|
function personalizeVariations({
|
678
666
|
name,
|
679
667
|
context,
|
680
|
-
variations,
|
668
|
+
variations: providedVariations,
|
681
669
|
take = 1,
|
682
|
-
onLogMessage
|
670
|
+
onLogMessage,
|
671
|
+
rankVariant
|
683
672
|
}) {
|
684
673
|
var _a, _b, _c;
|
685
674
|
onLogMessage == null ? void 0 : onLogMessage(["info", 300, "GROUP", { name, take }]);
|
@@ -688,9 +677,10 @@ function personalizeVariations({
|
|
688
677
|
const defaultVariants = [];
|
689
678
|
const needsConsent = context.requireConsentForPersonalization;
|
690
679
|
const canEvaluate = !needsConsent || context.storage.data.consent;
|
680
|
+
const variations = rankVariant ? sortVariations({ variations: providedVariations, rankVariant }) : providedVariations;
|
691
681
|
for (const variant of variations) {
|
692
682
|
if ((_a = variant.pz) == null ? void 0 : _a.crit.length) {
|
693
|
-
if (canEvaluate && variantMatches.length !== take && evaluateVariantMatch(variant.id, variant.pz, context.scores, onLogMessage
|
683
|
+
if (canEvaluate && variantMatches.length !== take && evaluateVariantMatch(variant.id, variant.pz, context.scores, onLogMessage)) {
|
694
684
|
variantMatches.push(variant);
|
695
685
|
}
|
696
686
|
} else {
|
@@ -749,7 +739,7 @@ function personalizeVariations({
|
|
749
739
|
}
|
750
740
|
}
|
751
741
|
|
752
|
-
// src/placement/
|
742
|
+
// src/placement/test.ts
|
753
743
|
var normalizeVariationDistributions = (variations) => {
|
754
744
|
const { values, total, missingDistribution } = variations.reduce(
|
755
745
|
(previous, current) => {
|
@@ -780,8 +770,6 @@ var normalizeVariationDistributions = (variations) => {
|
|
780
770
|
}
|
781
771
|
return values;
|
782
772
|
};
|
783
|
-
|
784
|
-
// src/placement/testVariations.ts
|
785
773
|
var testVariations = ({
|
786
774
|
name,
|
787
775
|
context,
|
@@ -1548,7 +1536,7 @@ import { dequal as dequal5 } from "dequal/lite";
|
|
1548
1536
|
import mitt3 from "mitt";
|
1549
1537
|
var CONTEXTUAL_EDITING_TEST_NAME = "contextual_editing_test";
|
1550
1538
|
var CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID = "contextual_editing_test_selected_variant";
|
1551
|
-
var _serverTransitionState, _scores, _state, _pzCache, _plugins, _commands, _requireConsentForPersonalization, _mitt3, _Context_instances, emitTest_fn, updateGoals_fn, updateComputedScores_fn, calculateScores_fn;
|
1539
|
+
var _serverTransitionState, _scores, _state, _pzCache, _plugins, _commands, _requireConsentForPersonalization, _rankPersonalizationVariant, _mitt3, _Context_instances, emitTest_fn, updateGoals_fn, updateComputedScores_fn, calculateScores_fn;
|
1552
1540
|
var Context = class {
|
1553
1541
|
constructor(options) {
|
1554
1542
|
__privateAdd(this, _Context_instances);
|
@@ -1560,6 +1548,7 @@ var Context = class {
|
|
1560
1548
|
__privateAdd(this, _plugins);
|
1561
1549
|
__privateAdd(this, _commands);
|
1562
1550
|
__privateAdd(this, _requireConsentForPersonalization);
|
1551
|
+
__privateAdd(this, _rankPersonalizationVariant);
|
1563
1552
|
__privateAdd(this, _mitt3, mitt3());
|
1564
1553
|
/**
|
1565
1554
|
* Subscribe to events
|
@@ -1574,6 +1563,7 @@ var Context = class {
|
|
1574
1563
|
__privateSet(this, _state, {});
|
1575
1564
|
__privateSet(this, _plugins, options.plugins);
|
1576
1565
|
__privateSet(this, _requireConsentForPersonalization, options.requireConsentForPersonalization);
|
1566
|
+
__privateSet(this, _rankPersonalizationVariant, options.rankPersonalizationVariant);
|
1577
1567
|
if (typeof options.transitionStore !== "undefined") {
|
1578
1568
|
__privateSet(this, _commands, []);
|
1579
1569
|
}
|
@@ -1881,7 +1871,13 @@ var Context = class {
|
|
1881
1871
|
const value = personalizeVariations({
|
1882
1872
|
...options,
|
1883
1873
|
context: this,
|
1884
|
-
onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message)
|
1874
|
+
onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message),
|
1875
|
+
rankVariant: __privateGet(this, _rankPersonalizationVariant) ? (variant) => __privateGet(this, _rankPersonalizationVariant).call(this, {
|
1876
|
+
placementName: options.name,
|
1877
|
+
variant,
|
1878
|
+
scores: __privateGet(this, _scores),
|
1879
|
+
quirks: this.storage.data.quirks
|
1880
|
+
}) : void 0
|
1885
1881
|
});
|
1886
1882
|
const previousPlacement = __privateGet(this, _pzCache)[options.name];
|
1887
1883
|
const eventData = {
|
@@ -1959,6 +1955,7 @@ _pzCache = new WeakMap();
|
|
1959
1955
|
_plugins = new WeakMap();
|
1960
1956
|
_commands = new WeakMap();
|
1961
1957
|
_requireConsentForPersonalization = new WeakMap();
|
1958
|
+
_rankPersonalizationVariant = new WeakMap();
|
1962
1959
|
_mitt3 = new WeakMap();
|
1963
1960
|
_Context_instances = new WeakSet();
|
1964
1961
|
emitTest_fn = function(event) {
|
package/dist/index.js
CHANGED
@@ -605,7 +605,7 @@ var GroupCriteriaEvaluator = class {
|
|
605
605
|
_evaluators = new WeakMap();
|
606
606
|
|
607
607
|
// src/placement/criteria/evaluateVariantMatch.ts
|
608
|
-
function evaluateVariantMatch(variantId, match, vec, onLogMessage
|
608
|
+
function evaluateVariantMatch(variantId, match, vec, onLogMessage) {
|
609
609
|
onLogMessage == null ? void 0 : onLogMessage(["info", 301, "GROUP", { id: variantId, op: match == null ? void 0 : match.op }]);
|
610
610
|
let result;
|
611
611
|
try {
|
@@ -613,9 +613,9 @@ function evaluateVariantMatch(variantId, match, vec, onLogMessage, quirks) {
|
|
613
613
|
onLogMessage == null ? void 0 : onLogMessage(["info", 302, { matched: true, description: "default variation" }]);
|
614
614
|
result = true;
|
615
615
|
} else if (!match.op || match.op === "&") {
|
616
|
-
result = match.crit.every((c) =>
|
616
|
+
result = match.crit.every((c) => evaluateDimensionMatch(c, vec, onLogMessage));
|
617
617
|
} else {
|
618
|
-
result = match.crit.some((c) =>
|
618
|
+
result = match.crit.some((c) => evaluateDimensionMatch(c, vec, onLogMessage));
|
619
619
|
}
|
620
620
|
onLogMessage == null ? void 0 : onLogMessage(["info", 303, result]);
|
621
621
|
} finally {
|
@@ -623,16 +623,9 @@ function evaluateVariantMatch(variantId, match, vec, onLogMessage, quirks) {
|
|
623
623
|
}
|
624
624
|
return result;
|
625
625
|
}
|
626
|
-
function evaluateMatch(crit, vec, quirks, onLogMessage) {
|
627
|
-
if ("t" in crit && crit.t === "q") {
|
628
|
-
return evaluateQuirkMatch(crit, quirks, onLogMessage);
|
629
|
-
} else {
|
630
|
-
return evaluateDimensionMatch(crit, vec, onLogMessage);
|
631
|
-
}
|
632
|
-
}
|
633
626
|
function evaluateDimensionMatch(crit, vec, onLogMessage) {
|
634
627
|
var _a, _b;
|
635
|
-
const { l: lhs
|
628
|
+
const { op, l: lhs } = crit;
|
636
629
|
const lhsScore = (_a = vec[lhs]) != null ? _a : 0;
|
637
630
|
if (op === "^") {
|
638
631
|
const [cat] = lhs.split(ENR_SEPARATOR);
|
@@ -699,49 +692,33 @@ function evaluateDimensionMatch(crit, vec, onLogMessage) {
|
|
699
692
|
}
|
700
693
|
if (op === ">") {
|
701
694
|
const result = lhsScore > rhsScore;
|
702
|
-
|
695
|
+
explain(onLogMessage, result, crit, lhsScore, rhsScore);
|
703
696
|
return result;
|
704
697
|
} else if (op === ">=") {
|
705
698
|
const result = lhsScore >= rhsScore;
|
706
|
-
|
699
|
+
explain(onLogMessage, result, crit, lhsScore, rhsScore);
|
707
700
|
return result;
|
708
701
|
} else if (op === "<") {
|
709
702
|
const result = lhsScore < rhsScore;
|
710
|
-
|
703
|
+
explain(onLogMessage, result, crit, lhsScore, rhsScore);
|
711
704
|
return result;
|
712
705
|
} else if (op === "<=") {
|
713
706
|
const result = lhsScore <= rhsScore;
|
714
|
-
|
707
|
+
explain(onLogMessage, result, crit, lhsScore, rhsScore);
|
715
708
|
return result;
|
716
709
|
} else if (op === "=") {
|
717
710
|
const result = lhsScore === rhsScore;
|
718
|
-
|
711
|
+
explain(onLogMessage, result, crit, lhsScore, rhsScore);
|
719
712
|
return result;
|
720
713
|
} else if (op === "!=") {
|
721
714
|
const result = lhsScore !== rhsScore;
|
722
|
-
|
715
|
+
explain(onLogMessage, result, crit, lhsScore, rhsScore);
|
723
716
|
return result;
|
724
717
|
} else {
|
725
718
|
throw new Error(`Unknown op: ${op}`);
|
726
719
|
}
|
727
720
|
}
|
728
|
-
function
|
729
|
-
var _a;
|
730
|
-
const { l: targetQuirk, op, r: targetValue } = crit;
|
731
|
-
const targetQuirkValue = (_a = quirks[targetQuirk]) != null ? _a : "";
|
732
|
-
if (op === "=") {
|
733
|
-
const result = targetQuirkValue === targetValue;
|
734
|
-
explainQuirk(onLogMessage, result, crit, targetQuirkValue);
|
735
|
-
return result;
|
736
|
-
} else if (op === "!=") {
|
737
|
-
const result = targetQuirkValue !== targetValue;
|
738
|
-
explainQuirk(onLogMessage, result, crit, targetQuirkValue);
|
739
|
-
return result;
|
740
|
-
} else {
|
741
|
-
throw new Error(`Unknown quirk op: ${op}`);
|
742
|
-
}
|
743
|
-
}
|
744
|
-
function explainScore(onLogMessage, result, crit, lhsScore, rhsScore) {
|
721
|
+
function explain(onLogMessage, result, crit, lhsScore, rhsScore) {
|
745
722
|
onLogMessage == null ? void 0 : onLogMessage([
|
746
723
|
"info",
|
747
724
|
302,
|
@@ -751,24 +728,36 @@ function explainScore(onLogMessage, result, crit, lhsScore, rhsScore) {
|
|
751
728
|
}
|
752
729
|
]);
|
753
730
|
}
|
754
|
-
function explainQuirk(onLogMessage, result, crit, lhs) {
|
755
|
-
onLogMessage == null ? void 0 : onLogMessage([
|
756
|
-
"info",
|
757
|
-
302,
|
758
|
-
{
|
759
|
-
matched: result,
|
760
|
-
description: `Quirk ${crit.l}[${lhs}] ${crit.op} ${crit.r}`
|
761
|
-
}
|
762
|
-
]);
|
763
|
-
}
|
764
731
|
|
765
|
-
// src/placement/
|
732
|
+
// src/placement/personalize.ts
|
733
|
+
var sortVariations = ({
|
734
|
+
variations,
|
735
|
+
rankVariant
|
736
|
+
}) => {
|
737
|
+
const variationsWithScores = Array.from(variations).map((variant) => {
|
738
|
+
const score = rankVariant == null ? void 0 : rankVariant(variant);
|
739
|
+
return {
|
740
|
+
variant,
|
741
|
+
score
|
742
|
+
};
|
743
|
+
});
|
744
|
+
const variantsWithDefinedScores = variationsWithScores.filter((v) => v.score !== void 0);
|
745
|
+
const variantsWithUndefinedScores = variationsWithScores.filter((v) => v.score === void 0);
|
746
|
+
return [
|
747
|
+
...variantsWithDefinedScores.sort((a, b) => {
|
748
|
+
var _a, _b;
|
749
|
+
return ((_a = b.score) != null ? _a : 0) - ((_b = a.score) != null ? _b : 0);
|
750
|
+
}).map((v) => v.variant),
|
751
|
+
...variantsWithUndefinedScores.map((v) => v.variant)
|
752
|
+
];
|
753
|
+
};
|
766
754
|
function personalizeVariations({
|
767
755
|
name,
|
768
756
|
context,
|
769
|
-
variations,
|
757
|
+
variations: providedVariations,
|
770
758
|
take = 1,
|
771
|
-
onLogMessage
|
759
|
+
onLogMessage,
|
760
|
+
rankVariant
|
772
761
|
}) {
|
773
762
|
var _a, _b, _c;
|
774
763
|
onLogMessage == null ? void 0 : onLogMessage(["info", 300, "GROUP", { name, take }]);
|
@@ -777,9 +766,10 @@ function personalizeVariations({
|
|
777
766
|
const defaultVariants = [];
|
778
767
|
const needsConsent = context.requireConsentForPersonalization;
|
779
768
|
const canEvaluate = !needsConsent || context.storage.data.consent;
|
769
|
+
const variations = rankVariant ? sortVariations({ variations: providedVariations, rankVariant }) : providedVariations;
|
780
770
|
for (const variant of variations) {
|
781
771
|
if ((_a = variant.pz) == null ? void 0 : _a.crit.length) {
|
782
|
-
if (canEvaluate && variantMatches.length !== take && evaluateVariantMatch(variant.id, variant.pz, context.scores, onLogMessage
|
772
|
+
if (canEvaluate && variantMatches.length !== take && evaluateVariantMatch(variant.id, variant.pz, context.scores, onLogMessage)) {
|
783
773
|
variantMatches.push(variant);
|
784
774
|
}
|
785
775
|
} else {
|
@@ -838,7 +828,7 @@ function personalizeVariations({
|
|
838
828
|
}
|
839
829
|
}
|
840
830
|
|
841
|
-
// src/placement/
|
831
|
+
// src/placement/test.ts
|
842
832
|
var normalizeVariationDistributions = (variations) => {
|
843
833
|
const { values, total, missingDistribution } = variations.reduce(
|
844
834
|
(previous, current) => {
|
@@ -869,8 +859,6 @@ var normalizeVariationDistributions = (variations) => {
|
|
869
859
|
}
|
870
860
|
return values;
|
871
861
|
};
|
872
|
-
|
873
|
-
// src/placement/testVariations.ts
|
874
862
|
var testVariations = ({
|
875
863
|
name,
|
876
864
|
context,
|
@@ -1637,7 +1625,7 @@ var import_lite5 = require("dequal/lite");
|
|
1637
1625
|
var import_mitt3 = __toESM(require("mitt"));
|
1638
1626
|
var CONTEXTUAL_EDITING_TEST_NAME = "contextual_editing_test";
|
1639
1627
|
var CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID = "contextual_editing_test_selected_variant";
|
1640
|
-
var _serverTransitionState, _scores, _state, _pzCache, _plugins, _commands, _requireConsentForPersonalization, _mitt3, _Context_instances, emitTest_fn, updateGoals_fn, updateComputedScores_fn, calculateScores_fn;
|
1628
|
+
var _serverTransitionState, _scores, _state, _pzCache, _plugins, _commands, _requireConsentForPersonalization, _rankPersonalizationVariant, _mitt3, _Context_instances, emitTest_fn, updateGoals_fn, updateComputedScores_fn, calculateScores_fn;
|
1641
1629
|
var Context = class {
|
1642
1630
|
constructor(options) {
|
1643
1631
|
__privateAdd(this, _Context_instances);
|
@@ -1649,6 +1637,7 @@ var Context = class {
|
|
1649
1637
|
__privateAdd(this, _plugins);
|
1650
1638
|
__privateAdd(this, _commands);
|
1651
1639
|
__privateAdd(this, _requireConsentForPersonalization);
|
1640
|
+
__privateAdd(this, _rankPersonalizationVariant);
|
1652
1641
|
__privateAdd(this, _mitt3, (0, import_mitt3.default)());
|
1653
1642
|
/**
|
1654
1643
|
* Subscribe to events
|
@@ -1663,6 +1652,7 @@ var Context = class {
|
|
1663
1652
|
__privateSet(this, _state, {});
|
1664
1653
|
__privateSet(this, _plugins, options.plugins);
|
1665
1654
|
__privateSet(this, _requireConsentForPersonalization, options.requireConsentForPersonalization);
|
1655
|
+
__privateSet(this, _rankPersonalizationVariant, options.rankPersonalizationVariant);
|
1666
1656
|
if (typeof options.transitionStore !== "undefined") {
|
1667
1657
|
__privateSet(this, _commands, []);
|
1668
1658
|
}
|
@@ -1970,7 +1960,13 @@ var Context = class {
|
|
1970
1960
|
const value = personalizeVariations({
|
1971
1961
|
...options,
|
1972
1962
|
context: this,
|
1973
|
-
onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message)
|
1963
|
+
onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message),
|
1964
|
+
rankVariant: __privateGet(this, _rankPersonalizationVariant) ? (variant) => __privateGet(this, _rankPersonalizationVariant).call(this, {
|
1965
|
+
placementName: options.name,
|
1966
|
+
variant,
|
1967
|
+
scores: __privateGet(this, _scores),
|
1968
|
+
quirks: this.storage.data.quirks
|
1969
|
+
}) : void 0
|
1974
1970
|
});
|
1975
1971
|
const previousPlacement = __privateGet(this, _pzCache)[options.name];
|
1976
1972
|
const eventData = {
|
@@ -2048,6 +2044,7 @@ _pzCache = new WeakMap();
|
|
2048
2044
|
_plugins = new WeakMap();
|
2049
2045
|
_commands = new WeakMap();
|
2050
2046
|
_requireConsentForPersonalization = new WeakMap();
|
2047
|
+
_rankPersonalizationVariant = new WeakMap();
|
2051
2048
|
_mitt3 = new WeakMap();
|
2052
2049
|
_Context_instances = new WeakSet();
|
2053
2050
|
emitTest_fn = function(event) {
|
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,49 +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
629
|
throw new Error(`Unknown op: ${op}`);
|
637
630
|
}
|
638
631
|
}
|
639
|
-
function
|
640
|
-
var _a;
|
641
|
-
const { l: targetQuirk, op, r: targetValue } = crit;
|
642
|
-
const targetQuirkValue = (_a = quirks[targetQuirk]) != null ? _a : "";
|
643
|
-
if (op === "=") {
|
644
|
-
const result = targetQuirkValue === targetValue;
|
645
|
-
explainQuirk(onLogMessage, result, crit, targetQuirkValue);
|
646
|
-
return result;
|
647
|
-
} else if (op === "!=") {
|
648
|
-
const result = targetQuirkValue !== targetValue;
|
649
|
-
explainQuirk(onLogMessage, result, crit, targetQuirkValue);
|
650
|
-
return result;
|
651
|
-
} else {
|
652
|
-
throw new Error(`Unknown quirk op: ${op}`);
|
653
|
-
}
|
654
|
-
}
|
655
|
-
function explainScore(onLogMessage, result, crit, lhsScore, rhsScore) {
|
632
|
+
function explain(onLogMessage, result, crit, lhsScore, rhsScore) {
|
656
633
|
onLogMessage == null ? void 0 : onLogMessage([
|
657
634
|
"info",
|
658
635
|
302,
|
@@ -662,24 +639,36 @@ function explainScore(onLogMessage, result, crit, lhsScore, rhsScore) {
|
|
662
639
|
}
|
663
640
|
]);
|
664
641
|
}
|
665
|
-
function explainQuirk(onLogMessage, result, crit, lhs) {
|
666
|
-
onLogMessage == null ? void 0 : onLogMessage([
|
667
|
-
"info",
|
668
|
-
302,
|
669
|
-
{
|
670
|
-
matched: result,
|
671
|
-
description: `Quirk ${crit.l}[${lhs}] ${crit.op} ${crit.r}`
|
672
|
-
}
|
673
|
-
]);
|
674
|
-
}
|
675
642
|
|
676
|
-
// src/placement/
|
643
|
+
// src/placement/personalize.ts
|
644
|
+
var sortVariations = ({
|
645
|
+
variations,
|
646
|
+
rankVariant
|
647
|
+
}) => {
|
648
|
+
const variationsWithScores = Array.from(variations).map((variant) => {
|
649
|
+
const score = rankVariant == null ? void 0 : rankVariant(variant);
|
650
|
+
return {
|
651
|
+
variant,
|
652
|
+
score
|
653
|
+
};
|
654
|
+
});
|
655
|
+
const variantsWithDefinedScores = variationsWithScores.filter((v) => v.score !== void 0);
|
656
|
+
const variantsWithUndefinedScores = variationsWithScores.filter((v) => v.score === void 0);
|
657
|
+
return [
|
658
|
+
...variantsWithDefinedScores.sort((a, b) => {
|
659
|
+
var _a, _b;
|
660
|
+
return ((_a = b.score) != null ? _a : 0) - ((_b = a.score) != null ? _b : 0);
|
661
|
+
}).map((v) => v.variant),
|
662
|
+
...variantsWithUndefinedScores.map((v) => v.variant)
|
663
|
+
];
|
664
|
+
};
|
677
665
|
function personalizeVariations({
|
678
666
|
name,
|
679
667
|
context,
|
680
|
-
variations,
|
668
|
+
variations: providedVariations,
|
681
669
|
take = 1,
|
682
|
-
onLogMessage
|
670
|
+
onLogMessage,
|
671
|
+
rankVariant
|
683
672
|
}) {
|
684
673
|
var _a, _b, _c;
|
685
674
|
onLogMessage == null ? void 0 : onLogMessage(["info", 300, "GROUP", { name, take }]);
|
@@ -688,9 +677,10 @@ function personalizeVariations({
|
|
688
677
|
const defaultVariants = [];
|
689
678
|
const needsConsent = context.requireConsentForPersonalization;
|
690
679
|
const canEvaluate = !needsConsent || context.storage.data.consent;
|
680
|
+
const variations = rankVariant ? sortVariations({ variations: providedVariations, rankVariant }) : providedVariations;
|
691
681
|
for (const variant of variations) {
|
692
682
|
if ((_a = variant.pz) == null ? void 0 : _a.crit.length) {
|
693
|
-
if (canEvaluate && variantMatches.length !== take && evaluateVariantMatch(variant.id, variant.pz, context.scores, onLogMessage
|
683
|
+
if (canEvaluate && variantMatches.length !== take && evaluateVariantMatch(variant.id, variant.pz, context.scores, onLogMessage)) {
|
694
684
|
variantMatches.push(variant);
|
695
685
|
}
|
696
686
|
} else {
|
@@ -749,7 +739,7 @@ function personalizeVariations({
|
|
749
739
|
}
|
750
740
|
}
|
751
741
|
|
752
|
-
// src/placement/
|
742
|
+
// src/placement/test.ts
|
753
743
|
var normalizeVariationDistributions = (variations) => {
|
754
744
|
const { values, total, missingDistribution } = variations.reduce(
|
755
745
|
(previous, current) => {
|
@@ -780,8 +770,6 @@ var normalizeVariationDistributions = (variations) => {
|
|
780
770
|
}
|
781
771
|
return values;
|
782
772
|
};
|
783
|
-
|
784
|
-
// src/placement/testVariations.ts
|
785
773
|
var testVariations = ({
|
786
774
|
name,
|
787
775
|
context,
|
@@ -1548,7 +1536,7 @@ import { dequal as dequal5 } from "dequal/lite";
|
|
1548
1536
|
import mitt3 from "mitt";
|
1549
1537
|
var CONTEXTUAL_EDITING_TEST_NAME = "contextual_editing_test";
|
1550
1538
|
var CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID = "contextual_editing_test_selected_variant";
|
1551
|
-
var _serverTransitionState, _scores, _state, _pzCache, _plugins, _commands, _requireConsentForPersonalization, _mitt3, _Context_instances, emitTest_fn, updateGoals_fn, updateComputedScores_fn, calculateScores_fn;
|
1539
|
+
var _serverTransitionState, _scores, _state, _pzCache, _plugins, _commands, _requireConsentForPersonalization, _rankPersonalizationVariant, _mitt3, _Context_instances, emitTest_fn, updateGoals_fn, updateComputedScores_fn, calculateScores_fn;
|
1552
1540
|
var Context = class {
|
1553
1541
|
constructor(options) {
|
1554
1542
|
__privateAdd(this, _Context_instances);
|
@@ -1560,6 +1548,7 @@ var Context = class {
|
|
1560
1548
|
__privateAdd(this, _plugins);
|
1561
1549
|
__privateAdd(this, _commands);
|
1562
1550
|
__privateAdd(this, _requireConsentForPersonalization);
|
1551
|
+
__privateAdd(this, _rankPersonalizationVariant);
|
1563
1552
|
__privateAdd(this, _mitt3, mitt3());
|
1564
1553
|
/**
|
1565
1554
|
* Subscribe to events
|
@@ -1574,6 +1563,7 @@ var Context = class {
|
|
1574
1563
|
__privateSet(this, _state, {});
|
1575
1564
|
__privateSet(this, _plugins, options.plugins);
|
1576
1565
|
__privateSet(this, _requireConsentForPersonalization, options.requireConsentForPersonalization);
|
1566
|
+
__privateSet(this, _rankPersonalizationVariant, options.rankPersonalizationVariant);
|
1577
1567
|
if (typeof options.transitionStore !== "undefined") {
|
1578
1568
|
__privateSet(this, _commands, []);
|
1579
1569
|
}
|
@@ -1881,7 +1871,13 @@ var Context = class {
|
|
1881
1871
|
const value = personalizeVariations({
|
1882
1872
|
...options,
|
1883
1873
|
context: this,
|
1884
|
-
onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message)
|
1874
|
+
onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message),
|
1875
|
+
rankVariant: __privateGet(this, _rankPersonalizationVariant) ? (variant) => __privateGet(this, _rankPersonalizationVariant).call(this, {
|
1876
|
+
placementName: options.name,
|
1877
|
+
variant,
|
1878
|
+
scores: __privateGet(this, _scores),
|
1879
|
+
quirks: this.storage.data.quirks
|
1880
|
+
}) : void 0
|
1885
1881
|
});
|
1886
1882
|
const previousPlacement = __privateGet(this, _pzCache)[options.name];
|
1887
1883
|
const eventData = {
|
@@ -1959,6 +1955,7 @@ _pzCache = new WeakMap();
|
|
1959
1955
|
_plugins = new WeakMap();
|
1960
1956
|
_commands = new WeakMap();
|
1961
1957
|
_requireConsentForPersonalization = new WeakMap();
|
1958
|
+
_rankPersonalizationVariant = new WeakMap();
|
1962
1959
|
_mitt3 = new WeakMap();
|
1963
1960
|
_Context_instances = new WeakSet();
|
1964
1961
|
emitTest_fn = function(event) {
|
@@ -905,7 +905,7 @@ type VariantMatchCriteria = {
|
|
905
905
|
* @defaultValue `&`
|
906
906
|
*/
|
907
907
|
op?: '&' | '|';
|
908
|
-
crit:
|
908
|
+
crit: DimensionMatch[];
|
909
909
|
/**
|
910
910
|
* Name of the variant for analytics tracking.
|
911
911
|
*/
|
@@ -953,37 +953,6 @@ type DimensionMatch = {
|
|
953
953
|
*/
|
954
954
|
rDim?: string;
|
955
955
|
};
|
956
|
-
type QuirkMatch = {
|
957
|
-
/**
|
958
|
-
* Type of match expression; 'q' discriminates quirk matches from dimension matches
|
959
|
-
*/
|
960
|
-
t: 'q';
|
961
|
-
/**
|
962
|
-
* Left hand side of the match expression (name of quirk)
|
963
|
-
* NOTE: if the quirk is not present
|
964
|
-
*/
|
965
|
-
l: string;
|
966
|
-
/**
|
967
|
-
* Operator of the match expression
|
968
|
-
* Comparison operators:
|
969
|
-
* =: `l` is equal to the right hand side expression
|
970
|
-
* !=: `l` is not equal to the right hand side expression
|
971
|
-
*/
|
972
|
-
op: '=' | '!=';
|
973
|
-
/**
|
974
|
-
* Right hand side of the match expression
|
975
|
-
* This value is treated as a constant value, if it is present. If it's a string, it is parsed to an integer.
|
976
|
-
* To reference another score dimension as the RHS, use the `rDim` property instead.
|
977
|
-
* `r` and `rDim` are mutually exclusive; if both are specified, then `rDim` wins.
|
978
|
-
*/
|
979
|
-
r: string;
|
980
|
-
/**
|
981
|
-
* Only here to maintain object compatibility with DimensionMatch.
|
982
|
-
* Completely ignored.
|
983
|
-
* @deprecated this is not used with QuirkMatch.
|
984
|
-
*/
|
985
|
-
rDim?: string;
|
986
|
-
};
|
987
956
|
|
988
957
|
/** Content that is tagged for adding enrichment score when triggered by behavior (i.e. being shown that content) */
|
989
958
|
type BehaviorTag = {
|
@@ -1035,8 +1004,9 @@ type PersonalizeOptions<TVariant> = {
|
|
1035
1004
|
/** Maximum number of variants to place (default: 1) */
|
1036
1005
|
take?: number;
|
1037
1006
|
onLogMessage?: (message: LogMessage) => void;
|
1007
|
+
rankVariant?: (variant: TVariant) => number | undefined;
|
1038
1008
|
};
|
1039
|
-
declare function personalizeVariations<TVariant extends PersonalizedVariant>({ name, context, variations, take, onLogMessage, }: PersonalizeOptions<TVariant> & {
|
1009
|
+
declare function personalizeVariations<TVariant extends PersonalizedVariant>({ name, context, variations: providedVariations, take, onLogMessage, rankVariant, }: PersonalizeOptions<TVariant> & {
|
1040
1010
|
context: Context;
|
1041
1011
|
}): PersonalizedResult<TVariant>;
|
1042
1012
|
|
@@ -1081,7 +1051,32 @@ type ContextOptions = {
|
|
1081
1051
|
* `true`: personalization is not run at all unless storage consent is given
|
1082
1052
|
*/
|
1083
1053
|
requireConsentForPersonalization?: boolean;
|
1054
|
+
/**
|
1055
|
+
* Specify a rank for a personalized variant, controlling the order in which variants are considered.
|
1056
|
+
* @param placementName The name of the personalized placement
|
1057
|
+
* @param variant The variant to rank
|
1058
|
+
* @returns A number representing the rank of the variant, where higher numbers are considered first
|
1059
|
+
*/
|
1060
|
+
rankPersonalizationVariant?: (options: RankPersonalizationVariantOptions) => number | undefined;
|
1084
1061
|
} & Omit<VisitorDataStoreOptions, 'manifest' | 'onServerTransitionScoresReceived'>;
|
1062
|
+
type RankPersonalizationVariantOptions = {
|
1063
|
+
/**
|
1064
|
+
* The name of the personalized placement
|
1065
|
+
*/
|
1066
|
+
placementName: string;
|
1067
|
+
/**
|
1068
|
+
* The variant to rank
|
1069
|
+
*/
|
1070
|
+
variant: PersonalizedVariant;
|
1071
|
+
/**
|
1072
|
+
* The current scores of the visitor
|
1073
|
+
*/
|
1074
|
+
scores: Readonly<ScoreVector>;
|
1075
|
+
/**
|
1076
|
+
* The current quirks of the visitor
|
1077
|
+
*/
|
1078
|
+
quirks: Readonly<Quirks>;
|
1079
|
+
};
|
1085
1080
|
/** Emitted when a personalization runs */
|
1086
1081
|
type PersonalizationEvent = {
|
1087
1082
|
/** Name of the personalized placement */
|
@@ -1296,4 +1291,4 @@ declare global {
|
|
1296
1291
|
}
|
1297
1292
|
}
|
1298
1293
|
|
1299
|
-
export { type
|
1294
|
+
export { type TestDefinition 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 RankPersonalizationVariantOptions as R, type ScoreVector as S, TransitionDataStore as T, type PersonalizationManifest as U, type VisitorData as V, type Signal as W, type SignalCriteriaGroup as X, type SignalCriteria as Y, type EnrichmentCategory as Z, type NumberMatch as _, type StorageCommands as a, type AggregateDimensionInput as a0, type TestOptions as a1, testVariations as a2, type DimensionMatch as a3, type PersonalizeOptions as a4, personalizeVariations as a5, type BehaviorTag as a6, type PersonalizedVariant as a7, type PersonalizedResult as a8, type TestVariant as a9, type ContextState as aA, type ContextStateUpdate as aB, type GoalStateUpdate as aC, type paths as aD, type TestResult as aa, type StorageCommand as ab, type SetGoalCommand as ac, type ModifyScoreCommand as ad, type ModifySessionScoreCommand as ae, type SetConsentCommand as af, type SetQuirkCommand as ag, type SetTestCommand as ah, type IdentifyCommand as ai, type SetControlGroupCommand as aj, type SetPersonalizeVariantControlCommand as ak, areCommandsEqual as al, type ServerToClientTransitionState as am, SERVER_STATE_ID as an, type TransitionDataStoreEvents as ao, type DecayOptions as ap, type VisitorDataStoreOptions as aq, type VisitorDataStoreEvents as ar, VisitorDataStore as as, type Tests as at, type Goals as au, type EnrichmentData as av, type PersonalizeControlVariant as aw, type PersonalizeVariants as ax, type EventData as ay, emptyVisitorData 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 };
|
@@ -905,7 +905,7 @@ type VariantMatchCriteria = {
|
|
905
905
|
* @defaultValue `&`
|
906
906
|
*/
|
907
907
|
op?: '&' | '|';
|
908
|
-
crit:
|
908
|
+
crit: DimensionMatch[];
|
909
909
|
/**
|
910
910
|
* Name of the variant for analytics tracking.
|
911
911
|
*/
|
@@ -953,37 +953,6 @@ type DimensionMatch = {
|
|
953
953
|
*/
|
954
954
|
rDim?: string;
|
955
955
|
};
|
956
|
-
type QuirkMatch = {
|
957
|
-
/**
|
958
|
-
* Type of match expression; 'q' discriminates quirk matches from dimension matches
|
959
|
-
*/
|
960
|
-
t: 'q';
|
961
|
-
/**
|
962
|
-
* Left hand side of the match expression (name of quirk)
|
963
|
-
* NOTE: if the quirk is not present
|
964
|
-
*/
|
965
|
-
l: string;
|
966
|
-
/**
|
967
|
-
* Operator of the match expression
|
968
|
-
* Comparison operators:
|
969
|
-
* =: `l` is equal to the right hand side expression
|
970
|
-
* !=: `l` is not equal to the right hand side expression
|
971
|
-
*/
|
972
|
-
op: '=' | '!=';
|
973
|
-
/**
|
974
|
-
* Right hand side of the match expression
|
975
|
-
* This value is treated as a constant value, if it is present. If it's a string, it is parsed to an integer.
|
976
|
-
* To reference another score dimension as the RHS, use the `rDim` property instead.
|
977
|
-
* `r` and `rDim` are mutually exclusive; if both are specified, then `rDim` wins.
|
978
|
-
*/
|
979
|
-
r: string;
|
980
|
-
/**
|
981
|
-
* Only here to maintain object compatibility with DimensionMatch.
|
982
|
-
* Completely ignored.
|
983
|
-
* @deprecated this is not used with QuirkMatch.
|
984
|
-
*/
|
985
|
-
rDim?: string;
|
986
|
-
};
|
987
956
|
|
988
957
|
/** Content that is tagged for adding enrichment score when triggered by behavior (i.e. being shown that content) */
|
989
958
|
type BehaviorTag = {
|
@@ -1035,8 +1004,9 @@ type PersonalizeOptions<TVariant> = {
|
|
1035
1004
|
/** Maximum number of variants to place (default: 1) */
|
1036
1005
|
take?: number;
|
1037
1006
|
onLogMessage?: (message: LogMessage) => void;
|
1007
|
+
rankVariant?: (variant: TVariant) => number | undefined;
|
1038
1008
|
};
|
1039
|
-
declare function personalizeVariations<TVariant extends PersonalizedVariant>({ name, context, variations, take, onLogMessage, }: PersonalizeOptions<TVariant> & {
|
1009
|
+
declare function personalizeVariations<TVariant extends PersonalizedVariant>({ name, context, variations: providedVariations, take, onLogMessage, rankVariant, }: PersonalizeOptions<TVariant> & {
|
1040
1010
|
context: Context;
|
1041
1011
|
}): PersonalizedResult<TVariant>;
|
1042
1012
|
|
@@ -1081,7 +1051,32 @@ type ContextOptions = {
|
|
1081
1051
|
* `true`: personalization is not run at all unless storage consent is given
|
1082
1052
|
*/
|
1083
1053
|
requireConsentForPersonalization?: boolean;
|
1054
|
+
/**
|
1055
|
+
* Specify a rank for a personalized variant, controlling the order in which variants are considered.
|
1056
|
+
* @param placementName The name of the personalized placement
|
1057
|
+
* @param variant The variant to rank
|
1058
|
+
* @returns A number representing the rank of the variant, where higher numbers are considered first
|
1059
|
+
*/
|
1060
|
+
rankPersonalizationVariant?: (options: RankPersonalizationVariantOptions) => number | undefined;
|
1084
1061
|
} & Omit<VisitorDataStoreOptions, 'manifest' | 'onServerTransitionScoresReceived'>;
|
1062
|
+
type RankPersonalizationVariantOptions = {
|
1063
|
+
/**
|
1064
|
+
* The name of the personalized placement
|
1065
|
+
*/
|
1066
|
+
placementName: string;
|
1067
|
+
/**
|
1068
|
+
* The variant to rank
|
1069
|
+
*/
|
1070
|
+
variant: PersonalizedVariant;
|
1071
|
+
/**
|
1072
|
+
* The current scores of the visitor
|
1073
|
+
*/
|
1074
|
+
scores: Readonly<ScoreVector>;
|
1075
|
+
/**
|
1076
|
+
* The current quirks of the visitor
|
1077
|
+
*/
|
1078
|
+
quirks: Readonly<Quirks>;
|
1079
|
+
};
|
1085
1080
|
/** Emitted when a personalization runs */
|
1086
1081
|
type PersonalizationEvent = {
|
1087
1082
|
/** Name of the personalized placement */
|
@@ -1296,4 +1291,4 @@ declare global {
|
|
1296
1291
|
}
|
1297
1292
|
}
|
1298
1293
|
|
1299
|
-
export { type
|
1294
|
+
export { type TestDefinition 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 RankPersonalizationVariantOptions as R, type ScoreVector as S, TransitionDataStore as T, type PersonalizationManifest as U, type VisitorData as V, type Signal as W, type SignalCriteriaGroup as X, type SignalCriteria as Y, type EnrichmentCategory as Z, type NumberMatch as _, type StorageCommands as a, type AggregateDimensionInput as a0, type TestOptions as a1, testVariations as a2, type DimensionMatch as a3, type PersonalizeOptions as a4, personalizeVariations as a5, type BehaviorTag as a6, type PersonalizedVariant as a7, type PersonalizedResult as a8, type TestVariant as a9, type ContextState as aA, type ContextStateUpdate as aB, type GoalStateUpdate as aC, type paths as aD, type TestResult as aa, type StorageCommand as ab, type SetGoalCommand as ac, type ModifyScoreCommand as ad, type ModifySessionScoreCommand as ae, type SetConsentCommand as af, type SetQuirkCommand as ag, type SetTestCommand as ah, type IdentifyCommand as ai, type SetControlGroupCommand as aj, type SetPersonalizeVariantControlCommand as ak, areCommandsEqual as al, type ServerToClientTransitionState as am, SERVER_STATE_ID as an, type TransitionDataStoreEvents as ao, type DecayOptions as ap, type VisitorDataStoreOptions as aq, type VisitorDataStoreEvents as ar, VisitorDataStore as as, type Tests as at, type Goals as au, type EnrichmentData as av, type PersonalizeControlVariant as aw, type PersonalizeVariants as ax, type EventData as ay, emptyVisitorData 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 };
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@uniformdev/context",
|
3
|
-
"version": "20.
|
3
|
+
"version": "20.4.1-alpha.3+bc2e6fc5f7",
|
4
4
|
"description": "Uniform Context core package",
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
6
6
|
"main": "./dist/index.js",
|
@@ -68,5 +68,5 @@
|
|
68
68
|
"publishConfig": {
|
69
69
|
"access": "public"
|
70
70
|
},
|
71
|
-
"gitHead": "
|
71
|
+
"gitHead": "bc2e6fc5f7d2920e46605385db043782f023bbbb"
|
72
72
|
}
|