@uniformdev/context 20.3.1 → 20.4.1-alpha.15
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 +20 -4
- package/dist/index.d.ts +20 -4
- package/dist/index.esm.js +120 -25
- package/dist/index.js +122 -26
- package/dist/index.mjs +120 -25
- package/dist/{types-EJl31yuP.d.mts → types-BPchcX4k.d.mts} +91 -24
- package/dist/{types-EJl31yuP.d.ts → types-BPchcX4k.d.ts} +91 -24
- 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, P as PersonalizedVariant, g as PersonalizeOptions, h as Context, i as PersonalizedResult, j as PersonalizationSelectionAlgorithmOptions, k as DevToolsEvents } from './types-BPchcX4k.mjs';
|
2
|
+
export { a6 as AggregateDimensionInput, ac as BehaviorTag, l as CONTEXTUAL_EDITING_TEST_NAME, m as CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID, t as ContextEvents, u as ContextInstance, p as ContextOptions, aE as ContextState, aF as ContextStateUpdate, Y as CriteriaEvaluatorParameters, X as CriteriaEvaluatorResult, at as DecayOptions, x as DevToolsActions, B as DevToolsDataEvent, y as DevToolsEvent, H as DevToolsForgetEvent, E as DevToolsHelloEvent, z as DevToolsLogEvent, G as DevToolsRawCommandsEvent, w as DevToolsState, v as DevToolsUiVersion, F as DevToolsUpdateEvent, aa as DimensionMatch, a3 as EnrichmentCategory, az as EnrichmentData, aC as EventData, aG as GoalStateUpdate, ay as Goals, W as GroupCriteriaEvaluator, am as IdentifyCommand, R as LogMessageGroup, N as LogMessageSingle, I as LogMessages, U as ManifestInstance, _ as ManifestV2, M as MessageCategory, K as MessageFunc, ah as ModifyScoreCommand, ai as ModifySessionScoreCommand, a4 as NumberMatch, r as PersonalizationEvent, q as PersonalizationEventVariantId, $ as PersonalizationManifest, n as PersonalizationSelectionAlgorithm, o as PersonalizationSelectionAlgorithms, aA as PersonalizeControlVariant, aB as PersonalizeVariants, ab as QuirkMatch, ar as SERVER_STATE_ID, aq as ServerToClientTransitionState, aj as SetConsentCommand, an as SetControlGroupCommand, ag as SetGoalCommand, ao as SetPersonalizeVariantControlCommand, ak as SetQuirkCommand, al as SetTestCommand, J as Severity, a0 as Signal, a2 as SignalCriteria, a1 as SignalCriteriaGroup, Z as SignalData, af as StorageCommand, a5 as TestDefinition, s as TestEvent, a7 as TestOptions, ae as TestResult, ad as TestVariant, ax as Tests, as as TransitionDataStoreEvents, a9 as VariantMatchMetadata, aw as VisitorDataStore, av as VisitorDataStoreEvents, au as VisitorDataStoreOptions, ap as areCommandsEqual, aD as emptyVisitorData, a8 as testVariations } from './types-BPchcX4k.mjs';
|
3
3
|
import Cookies from 'js-cookie';
|
4
4
|
import 'mitt';
|
5
5
|
|
@@ -158,7 +158,22 @@ 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): boolean;
|
161
|
+
declare function evaluateVariantMatch(variantId: string, match: VariantMatchCriteria | undefined | null, vec: ScoreVector, onLogMessage?: (message: LogMessage) => void, quirks?: Quirks): boolean;
|
162
|
+
|
163
|
+
/**
|
164
|
+
* @deprecated Use `topDownCriteriaPersonalizationSelectionAlgorithm` instead
|
165
|
+
*/
|
166
|
+
declare function personalizeVariations<TVariant extends PersonalizedVariant<VariantMatchCriteria>>(options: PersonalizeOptions<TVariant> & {
|
167
|
+
context: Context;
|
168
|
+
}): PersonalizedResult<TVariant>;
|
169
|
+
|
170
|
+
/**
|
171
|
+
* Implementation of the top-down criteria personalization selection algorithm.
|
172
|
+
*
|
173
|
+
* In this mode, we evaluate variations in the order they are declared and the first <take>
|
174
|
+
* variations whose criteria evaluate to true are selected.
|
175
|
+
*/
|
176
|
+
declare function topDownCriteriaPersonalizationSelectionAlgorithm<TCriteria extends VariantMatchCriteria, TVariation extends PersonalizedVariant<TCriteria>>({ name, context, variations, take, onLogMessage, }: PersonalizationSelectionAlgorithmOptions<TCriteria, TVariation>): PersonalizedResult<TVariation>;
|
162
177
|
|
163
178
|
type ContextDevToolOptions = {
|
164
179
|
onAfterMessageReceived?: (message: DevToolsEvents) => void;
|
@@ -183,6 +198,7 @@ declare enum ScriptType {
|
|
183
198
|
type EdgePersonalizeComponentOptions = {
|
184
199
|
name: string;
|
185
200
|
count?: number;
|
201
|
+
algorithm?: string;
|
186
202
|
};
|
187
203
|
type EdgeTestComponentOptions = {
|
188
204
|
name: string;
|
@@ -213,4 +229,4 @@ type QuickConnectConfig = {
|
|
213
229
|
declare function serializeQuickConnect(config: QuickConnectConfig): string;
|
214
230
|
declare function parseQuickConnect(serialized: string): Required<QuickConnectConfig>;
|
215
231
|
|
216
|
-
export { AggregateDimension, type ConsoleDebugLogDrainOptions, type ContextDevToolOptions, ContextPlugin, CookieTransitionDataStore, type CookieTransitionDataStoreOptions, CriteriaEvaluator, DecayFunction, DevToolsEvents, ENR_SEPARATOR, EdgeNodeTagName, type EdgePersonalizeComponentOptions, type EdgeTestComponentOptions, EdgeTransitionDataStore, type EdgeTransitionDataStoreOptions, type EnableUniformInsightsOptions, KV_SEP, type LinearDecayOptions, LogDrain, LogMessage, OutputSeverity, PAIR_SEP, QUIRK_SEP, type QuickConnectConfig, Quirks, ScoreVector, ScriptType, StorageCommands, StringMatch, TYPE_SEP, TransitionDataStore, TransitionDataStoreOptions, UNIFORM_DEFAULT_COOKIE_NAME, UNIFORM_DEFAULT_QUIRK_COOKIE_NAME, VariantMatchCriteria, VisitorData, computeAggregateDimensions, cookieEvaluator, createConsoleLogDrain, createDebugConsoleLogDrain, createLinearDecay, currentPageEvaluator, decodeCookieType, decodePersonalizeVariants, enableConsoleLogDrain, enableContextDevTools, enableDebugConsoleLogDrain, enableUniformInsights, encodeCookieType, evaluateVariantMatch, eventEvaluator, explainStringMatch, explainStringMatchCriteria, getEnrichmentVectorKey, isStringMatch, pageViewCountDimension, pageViewCountEvaluator, parseCookieScores, parseCookieType, parseQuickConnect, parseQuirkCookie, parseScoreCookie, queryStringEvaluator, quirkEvaluator, serializeCookie, serializeCookieType, serializePersonalizeVariants, serializeQuickConnect, serializeQuirks };
|
232
|
+
export { AggregateDimension, type ConsoleDebugLogDrainOptions, Context, type ContextDevToolOptions, ContextPlugin, CookieTransitionDataStore, type CookieTransitionDataStoreOptions, CriteriaEvaluator, DecayFunction, DevToolsEvents, ENR_SEPARATOR, EdgeNodeTagName, type EdgePersonalizeComponentOptions, type EdgeTestComponentOptions, EdgeTransitionDataStore, type EdgeTransitionDataStoreOptions, type EnableUniformInsightsOptions, KV_SEP, type LinearDecayOptions, LogDrain, LogMessage, OutputSeverity, PAIR_SEP, PersonalizationSelectionAlgorithmOptions, PersonalizeOptions, PersonalizedResult, PersonalizedVariant, QUIRK_SEP, type QuickConnectConfig, Quirks, ScoreVector, ScriptType, StorageCommands, StringMatch, TYPE_SEP, TransitionDataStore, TransitionDataStoreOptions, UNIFORM_DEFAULT_COOKIE_NAME, UNIFORM_DEFAULT_QUIRK_COOKIE_NAME, VariantMatchCriteria, VisitorData, computeAggregateDimensions, cookieEvaluator, createConsoleLogDrain, createDebugConsoleLogDrain, createLinearDecay, currentPageEvaluator, decodeCookieType, decodePersonalizeVariants, enableConsoleLogDrain, enableContextDevTools, enableDebugConsoleLogDrain, enableUniformInsights, encodeCookieType, evaluateVariantMatch, eventEvaluator, explainStringMatch, explainStringMatchCriteria, getEnrichmentVectorKey, isStringMatch, pageViewCountDimension, pageViewCountEvaluator, parseCookieScores, parseCookieType, parseQuickConnect, parseQuirkCookie, parseScoreCookie, personalizeVariations, queryStringEvaluator, quirkEvaluator, serializeCookie, serializeCookieType, serializePersonalizeVariants, serializeQuickConnect, serializeQuirks, topDownCriteriaPersonalizationSelectionAlgorithm };
|
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, P as PersonalizedVariant, g as PersonalizeOptions, h as Context, i as PersonalizedResult, j as PersonalizationSelectionAlgorithmOptions, k as DevToolsEvents } from './types-BPchcX4k.js';
|
2
|
+
export { a6 as AggregateDimensionInput, ac as BehaviorTag, l as CONTEXTUAL_EDITING_TEST_NAME, m as CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID, t as ContextEvents, u as ContextInstance, p as ContextOptions, aE as ContextState, aF as ContextStateUpdate, Y as CriteriaEvaluatorParameters, X as CriteriaEvaluatorResult, at as DecayOptions, x as DevToolsActions, B as DevToolsDataEvent, y as DevToolsEvent, H as DevToolsForgetEvent, E as DevToolsHelloEvent, z as DevToolsLogEvent, G as DevToolsRawCommandsEvent, w as DevToolsState, v as DevToolsUiVersion, F as DevToolsUpdateEvent, aa as DimensionMatch, a3 as EnrichmentCategory, az as EnrichmentData, aC as EventData, aG as GoalStateUpdate, ay as Goals, W as GroupCriteriaEvaluator, am as IdentifyCommand, R as LogMessageGroup, N as LogMessageSingle, I as LogMessages, U as ManifestInstance, _ as ManifestV2, M as MessageCategory, K as MessageFunc, ah as ModifyScoreCommand, ai as ModifySessionScoreCommand, a4 as NumberMatch, r as PersonalizationEvent, q as PersonalizationEventVariantId, $ as PersonalizationManifest, n as PersonalizationSelectionAlgorithm, o as PersonalizationSelectionAlgorithms, aA as PersonalizeControlVariant, aB as PersonalizeVariants, ab as QuirkMatch, ar as SERVER_STATE_ID, aq as ServerToClientTransitionState, aj as SetConsentCommand, an as SetControlGroupCommand, ag as SetGoalCommand, ao as SetPersonalizeVariantControlCommand, ak as SetQuirkCommand, al as SetTestCommand, J as Severity, a0 as Signal, a2 as SignalCriteria, a1 as SignalCriteriaGroup, Z as SignalData, af as StorageCommand, a5 as TestDefinition, s as TestEvent, a7 as TestOptions, ae as TestResult, ad as TestVariant, ax as Tests, as as TransitionDataStoreEvents, a9 as VariantMatchMetadata, aw as VisitorDataStore, av as VisitorDataStoreEvents, au as VisitorDataStoreOptions, ap as areCommandsEqual, aD as emptyVisitorData, a8 as testVariations } from './types-BPchcX4k.js';
|
3
3
|
import Cookies from 'js-cookie';
|
4
4
|
import 'mitt';
|
5
5
|
|
@@ -158,7 +158,22 @@ 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): boolean;
|
161
|
+
declare function evaluateVariantMatch(variantId: string, match: VariantMatchCriteria | undefined | null, vec: ScoreVector, onLogMessage?: (message: LogMessage) => void, quirks?: Quirks): boolean;
|
162
|
+
|
163
|
+
/**
|
164
|
+
* @deprecated Use `topDownCriteriaPersonalizationSelectionAlgorithm` instead
|
165
|
+
*/
|
166
|
+
declare function personalizeVariations<TVariant extends PersonalizedVariant<VariantMatchCriteria>>(options: PersonalizeOptions<TVariant> & {
|
167
|
+
context: Context;
|
168
|
+
}): PersonalizedResult<TVariant>;
|
169
|
+
|
170
|
+
/**
|
171
|
+
* Implementation of the top-down criteria personalization selection algorithm.
|
172
|
+
*
|
173
|
+
* In this mode, we evaluate variations in the order they are declared and the first <take>
|
174
|
+
* variations whose criteria evaluate to true are selected.
|
175
|
+
*/
|
176
|
+
declare function topDownCriteriaPersonalizationSelectionAlgorithm<TCriteria extends VariantMatchCriteria, TVariation extends PersonalizedVariant<TCriteria>>({ name, context, variations, take, onLogMessage, }: PersonalizationSelectionAlgorithmOptions<TCriteria, TVariation>): PersonalizedResult<TVariation>;
|
162
177
|
|
163
178
|
type ContextDevToolOptions = {
|
164
179
|
onAfterMessageReceived?: (message: DevToolsEvents) => void;
|
@@ -183,6 +198,7 @@ declare enum ScriptType {
|
|
183
198
|
type EdgePersonalizeComponentOptions = {
|
184
199
|
name: string;
|
185
200
|
count?: number;
|
201
|
+
algorithm?: string;
|
186
202
|
};
|
187
203
|
type EdgeTestComponentOptions = {
|
188
204
|
name: string;
|
@@ -213,4 +229,4 @@ type QuickConnectConfig = {
|
|
213
229
|
declare function serializeQuickConnect(config: QuickConnectConfig): string;
|
214
230
|
declare function parseQuickConnect(serialized: string): Required<QuickConnectConfig>;
|
215
231
|
|
216
|
-
export { AggregateDimension, type ConsoleDebugLogDrainOptions, type ContextDevToolOptions, ContextPlugin, CookieTransitionDataStore, type CookieTransitionDataStoreOptions, CriteriaEvaluator, DecayFunction, DevToolsEvents, ENR_SEPARATOR, EdgeNodeTagName, type EdgePersonalizeComponentOptions, type EdgeTestComponentOptions, EdgeTransitionDataStore, type EdgeTransitionDataStoreOptions, type EnableUniformInsightsOptions, KV_SEP, type LinearDecayOptions, LogDrain, LogMessage, OutputSeverity, PAIR_SEP, QUIRK_SEP, type QuickConnectConfig, Quirks, ScoreVector, ScriptType, StorageCommands, StringMatch, TYPE_SEP, TransitionDataStore, TransitionDataStoreOptions, UNIFORM_DEFAULT_COOKIE_NAME, UNIFORM_DEFAULT_QUIRK_COOKIE_NAME, VariantMatchCriteria, VisitorData, computeAggregateDimensions, cookieEvaluator, createConsoleLogDrain, createDebugConsoleLogDrain, createLinearDecay, currentPageEvaluator, decodeCookieType, decodePersonalizeVariants, enableConsoleLogDrain, enableContextDevTools, enableDebugConsoleLogDrain, enableUniformInsights, encodeCookieType, evaluateVariantMatch, eventEvaluator, explainStringMatch, explainStringMatchCriteria, getEnrichmentVectorKey, isStringMatch, pageViewCountDimension, pageViewCountEvaluator, parseCookieScores, parseCookieType, parseQuickConnect, parseQuirkCookie, parseScoreCookie, queryStringEvaluator, quirkEvaluator, serializeCookie, serializeCookieType, serializePersonalizeVariants, serializeQuickConnect, serializeQuirks };
|
232
|
+
export { AggregateDimension, type ConsoleDebugLogDrainOptions, Context, type ContextDevToolOptions, ContextPlugin, CookieTransitionDataStore, type CookieTransitionDataStoreOptions, CriteriaEvaluator, DecayFunction, DevToolsEvents, ENR_SEPARATOR, EdgeNodeTagName, type EdgePersonalizeComponentOptions, type EdgeTestComponentOptions, EdgeTransitionDataStore, type EdgeTransitionDataStoreOptions, type EnableUniformInsightsOptions, KV_SEP, type LinearDecayOptions, LogDrain, LogMessage, OutputSeverity, PAIR_SEP, PersonalizationSelectionAlgorithmOptions, PersonalizeOptions, PersonalizedResult, PersonalizedVariant, QUIRK_SEP, type QuickConnectConfig, Quirks, ScoreVector, ScriptType, StorageCommands, StringMatch, TYPE_SEP, TransitionDataStore, TransitionDataStoreOptions, UNIFORM_DEFAULT_COOKIE_NAME, UNIFORM_DEFAULT_QUIRK_COOKIE_NAME, VariantMatchCriteria, VisitorData, computeAggregateDimensions, cookieEvaluator, createConsoleLogDrain, createDebugConsoleLogDrain, createLinearDecay, currentPageEvaluator, decodeCookieType, decodePersonalizeVariants, enableConsoleLogDrain, enableContextDevTools, enableDebugConsoleLogDrain, enableUniformInsights, encodeCookieType, evaluateVariantMatch, eventEvaluator, explainStringMatch, explainStringMatchCriteria, getEnrichmentVectorKey, isStringMatch, pageViewCountDimension, pageViewCountEvaluator, parseCookieScores, parseCookieType, parseQuickConnect, parseQuirkCookie, parseScoreCookie, personalizeVariations, queryStringEvaluator, quirkEvaluator, serializeCookie, serializeCookieType, serializePersonalizeVariants, serializeQuickConnect, serializeQuirks, topDownCriteriaPersonalizationSelectionAlgorithm };
|
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, quirks) {
|
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) {
|
|
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) => evaluateMatch(c, vec, quirks != null ? quirks : {}, onLogMessage));
|
528
528
|
} else {
|
529
|
-
result = match.crit.some((c) =>
|
529
|
+
result = match.crit.some((c) => evaluateMatch(c, vec, quirks != null ? quirks : {}, onLogMessage));
|
530
530
|
}
|
531
531
|
onLogMessage == null ? void 0 : onLogMessage(["info", 303, result]);
|
532
532
|
} finally {
|
@@ -534,9 +534,16 @@ function evaluateVariantMatch(variantId, match, vec, onLogMessage) {
|
|
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
|
+
}
|
537
544
|
function evaluateDimensionMatch(crit, vec, onLogMessage) {
|
538
545
|
var _a, _b;
|
539
|
-
const {
|
546
|
+
const { l: lhs, op } = crit;
|
540
547
|
const lhsScore = (_a = vec[lhs]) != null ? _a : 0;
|
541
548
|
if (op === "^") {
|
542
549
|
const [cat] = lhs.split(ENR_SEPARATOR);
|
@@ -603,33 +610,65 @@ function evaluateDimensionMatch(crit, vec, onLogMessage) {
|
|
603
610
|
}
|
604
611
|
if (op === ">") {
|
605
612
|
const result = lhsScore > rhsScore;
|
606
|
-
|
613
|
+
explainScore(onLogMessage, result, crit, lhsScore, rhsScore);
|
607
614
|
return result;
|
608
615
|
} else if (op === ">=") {
|
609
616
|
const result = lhsScore >= rhsScore;
|
610
|
-
|
617
|
+
explainScore(onLogMessage, result, crit, lhsScore, rhsScore);
|
611
618
|
return result;
|
612
619
|
} else if (op === "<") {
|
613
620
|
const result = lhsScore < rhsScore;
|
614
|
-
|
621
|
+
explainScore(onLogMessage, result, crit, lhsScore, rhsScore);
|
615
622
|
return result;
|
616
623
|
} else if (op === "<=") {
|
617
624
|
const result = lhsScore <= rhsScore;
|
618
|
-
|
625
|
+
explainScore(onLogMessage, result, crit, lhsScore, rhsScore);
|
619
626
|
return result;
|
620
627
|
} else if (op === "=") {
|
621
628
|
const result = lhsScore === rhsScore;
|
622
|
-
|
629
|
+
explainScore(onLogMessage, result, crit, lhsScore, rhsScore);
|
623
630
|
return result;
|
624
631
|
} else if (op === "!=") {
|
625
632
|
const result = lhsScore !== rhsScore;
|
626
|
-
|
633
|
+
explainScore(onLogMessage, result, crit, lhsScore, rhsScore);
|
634
|
+
return result;
|
635
|
+
} else {
|
636
|
+
onLogMessage == null ? void 0 : onLogMessage([
|
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);
|
627
658
|
return result;
|
628
659
|
} else {
|
629
|
-
|
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;
|
630
669
|
}
|
631
670
|
}
|
632
|
-
function
|
671
|
+
function explainScore(onLogMessage, result, crit, lhsScore, rhsScore) {
|
633
672
|
onLogMessage == null ? void 0 : onLogMessage([
|
634
673
|
"info",
|
635
674
|
302,
|
@@ -639,9 +678,19 @@ function explain(onLogMessage, result, crit, lhsScore, rhsScore) {
|
|
639
678
|
}
|
640
679
|
]);
|
641
680
|
}
|
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
|
+
}
|
642
691
|
|
643
|
-
// src/placement/
|
644
|
-
function
|
692
|
+
// src/placement/topDownCriteriaPersonalizationSelectionAlgorithm.ts
|
693
|
+
function topDownCriteriaPersonalizationSelectionAlgorithm({
|
645
694
|
name,
|
646
695
|
context,
|
647
696
|
variations,
|
@@ -656,12 +705,19 @@ function personalizeVariations({
|
|
656
705
|
const needsConsent = context.requireConsentForPersonalization;
|
657
706
|
const canEvaluate = !needsConsent || context.storage.data.consent;
|
658
707
|
for (const variant of variations) {
|
659
|
-
|
660
|
-
|
661
|
-
|
708
|
+
const isInvalidFormat = variant.pz && (typeof variant.pz !== "object" || variant.pz === null || !("crit" in variant.pz && Array.isArray(variant.pz.crit)));
|
709
|
+
let validVariant;
|
710
|
+
if (isInvalidFormat) {
|
711
|
+
validVariant = { id: variant.id };
|
712
|
+
} else {
|
713
|
+
validVariant = variant;
|
714
|
+
}
|
715
|
+
if ((_a = validVariant.pz) == null ? void 0 : _a.crit.length) {
|
716
|
+
if (canEvaluate && variantMatches.length !== take && evaluateVariantMatch(variant.id, validVariant.pz, context.scores, onLogMessage, context.quirks)) {
|
717
|
+
variantMatches.push(validVariant);
|
662
718
|
}
|
663
719
|
} else {
|
664
|
-
defaultVariants.push(
|
720
|
+
defaultVariants.push(validVariant);
|
665
721
|
}
|
666
722
|
}
|
667
723
|
const result = [];
|
@@ -716,7 +772,12 @@ function personalizeVariations({
|
|
716
772
|
}
|
717
773
|
}
|
718
774
|
|
719
|
-
// src/placement/
|
775
|
+
// src/placement/personalizeVariations.ts
|
776
|
+
function personalizeVariations(options) {
|
777
|
+
return topDownCriteriaPersonalizationSelectionAlgorithm(options);
|
778
|
+
}
|
779
|
+
|
780
|
+
// src/placement/normalizeVariationDistributions.ts
|
720
781
|
var normalizeVariationDistributions = (variations) => {
|
721
782
|
const { values, total, missingDistribution } = variations.reduce(
|
722
783
|
(previous, current) => {
|
@@ -735,7 +796,12 @@ var normalizeVariationDistributions = (variations) => {
|
|
735
796
|
}
|
736
797
|
);
|
737
798
|
if (total > 100) {
|
738
|
-
|
799
|
+
const autoScaleFactor = 100 / total;
|
800
|
+
values.forEach((value, index) => {
|
801
|
+
if (typeof value === "number") {
|
802
|
+
values[index] = value * autoScaleFactor;
|
803
|
+
}
|
804
|
+
});
|
739
805
|
} else if (total < 100) {
|
740
806
|
const remainder = 100 - total;
|
741
807
|
const missingSlice = remainder / missingDistribution;
|
@@ -747,6 +813,8 @@ var normalizeVariationDistributions = (variations) => {
|
|
747
813
|
}
|
748
814
|
return values;
|
749
815
|
};
|
816
|
+
|
817
|
+
// src/placement/testVariations.ts
|
750
818
|
var testVariations = ({
|
751
819
|
name,
|
752
820
|
context,
|
@@ -1513,11 +1581,12 @@ import { dequal as dequal5 } from "dequal/lite";
|
|
1513
1581
|
import mitt3 from "mitt";
|
1514
1582
|
var CONTEXTUAL_EDITING_TEST_NAME = "contextual_editing_test";
|
1515
1583
|
var CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID = "contextual_editing_test_selected_variant";
|
1516
|
-
var _serverTransitionState, _scores, _state, _pzCache, _plugins, _commands, _requireConsentForPersonalization, _mitt3, _Context_instances, emitTest_fn, updateGoals_fn, updateComputedScores_fn, calculateScores_fn;
|
1584
|
+
var _personalizationSelectionAlgorithms, _serverTransitionState, _scores, _state, _pzCache, _plugins, _commands, _requireConsentForPersonalization, _mitt3, _Context_instances, emitTest_fn, updateGoals_fn, updateComputedScores_fn, calculateScores_fn;
|
1517
1585
|
var Context = class {
|
1518
1586
|
constructor(options) {
|
1519
1587
|
__privateAdd(this, _Context_instances);
|
1520
1588
|
__publicField(this, "manifest");
|
1589
|
+
__privateAdd(this, _personalizationSelectionAlgorithms);
|
1521
1590
|
__privateAdd(this, _serverTransitionState);
|
1522
1591
|
__privateAdd(this, _scores, {});
|
1523
1592
|
__privateAdd(this, _state);
|
@@ -1534,7 +1603,7 @@ var Context = class {
|
|
1534
1603
|
off: __privateGet(this, _mitt3).off
|
1535
1604
|
});
|
1536
1605
|
__publicField(this, "storage");
|
1537
|
-
var _a, _b;
|
1606
|
+
var _a, _b, _c;
|
1538
1607
|
const { manifest, ...storageOptions } = options;
|
1539
1608
|
__privateSet(this, _state, {});
|
1540
1609
|
__privateSet(this, _plugins, options.plugins);
|
@@ -1542,7 +1611,17 @@ var Context = class {
|
|
1542
1611
|
if (typeof options.transitionStore !== "undefined") {
|
1543
1612
|
__privateSet(this, _commands, []);
|
1544
1613
|
}
|
1614
|
+
__privateSet(this, _personalizationSelectionAlgorithms, { default: topDownCriteriaPersonalizationSelectionAlgorithm });
|
1545
1615
|
(_a = __privateGet(this, _plugins)) == null ? void 0 : _a.forEach((plugin) => {
|
1616
|
+
if (!plugin.personalizationSelectionAlgorithms) {
|
1617
|
+
return;
|
1618
|
+
}
|
1619
|
+
__privateSet(this, _personalizationSelectionAlgorithms, {
|
1620
|
+
...__privateGet(this, _personalizationSelectionAlgorithms),
|
1621
|
+
...plugin.personalizationSelectionAlgorithms
|
1622
|
+
});
|
1623
|
+
});
|
1624
|
+
(_b = __privateGet(this, _plugins)) == null ? void 0 : _b.forEach((plugin) => {
|
1546
1625
|
if (!plugin.logDrain) {
|
1547
1626
|
return;
|
1548
1627
|
}
|
@@ -1593,7 +1672,7 @@ var Context = class {
|
|
1593
1672
|
__privateGet(this, _mitt3).emit("quirksUpdated", quirks.quirks);
|
1594
1673
|
__privateGet(this, _mitt3).emit("log", ["info", 4, quirks.quirks]);
|
1595
1674
|
});
|
1596
|
-
(
|
1675
|
+
(_c = __privateGet(this, _plugins)) == null ? void 0 : _c.forEach((plugin) => {
|
1597
1676
|
if (!plugin.init) {
|
1598
1677
|
return;
|
1599
1678
|
}
|
@@ -1843,7 +1922,17 @@ var Context = class {
|
|
1843
1922
|
}
|
1844
1923
|
/** Executes a personalized placement with a given set of variants */
|
1845
1924
|
personalize(options) {
|
1846
|
-
|
1925
|
+
var _a;
|
1926
|
+
const algorithmName = (_a = options.algorithm) != null ? _a : "default";
|
1927
|
+
const algorithm = __privateGet(this, _personalizationSelectionAlgorithms)[algorithmName];
|
1928
|
+
if (!algorithm) {
|
1929
|
+
__privateGet(this, _mitt3).emit("log", ["warn", 304, { algorithm: algorithmName }]);
|
1930
|
+
return {
|
1931
|
+
personalized: false,
|
1932
|
+
variations: []
|
1933
|
+
};
|
1934
|
+
}
|
1935
|
+
const value = algorithm({
|
1847
1936
|
...options,
|
1848
1937
|
context: this,
|
1849
1938
|
onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message)
|
@@ -1917,6 +2006,7 @@ var Context = class {
|
|
1917
2006
|
__privateGet(this, _mitt3).emit("personalizationResult", event);
|
1918
2007
|
}
|
1919
2008
|
};
|
2009
|
+
_personalizationSelectionAlgorithms = new WeakMap();
|
1920
2010
|
_serverTransitionState = new WeakMap();
|
1921
2011
|
_scores = new WeakMap();
|
1922
2012
|
_state = new WeakMap();
|
@@ -2512,6 +2602,10 @@ var messageContent = {
|
|
2512
2602
|
301: ({ id, op }) => ["personalization", `testing variation ${id} (${op === "|" ? "OR" : "AND"})`],
|
2513
2603
|
302: ({ matched, description }) => ["personalization", `${description} is ${matched}`],
|
2514
2604
|
303: (selected) => ["personalization", selected ? "selected variation" : "did not select variation"],
|
2605
|
+
304: ({ algorithm }) => [
|
2606
|
+
"personalization",
|
2607
|
+
`personalization selection algorithm '${algorithm}' not found. Hiding placement.`
|
2608
|
+
],
|
2515
2609
|
// TESTING
|
2516
2610
|
400: (name) => ["testing", `executing A/B test '${name}'`],
|
2517
2611
|
401: (testName) => ["testing", `${testName} is not registered in the manifest; it will not be run.`],
|
@@ -2658,5 +2752,6 @@ export {
|
|
2658
2752
|
serializePersonalizeVariants,
|
2659
2753
|
serializeQuickConnect,
|
2660
2754
|
serializeQuirks,
|
2661
|
-
testVariations
|
2755
|
+
testVariations,
|
2756
|
+
topDownCriteriaPersonalizationSelectionAlgorithm
|
2662
2757
|
};
|