From c3b16754d103aba2b85cda0d5a9dcea261ce3a4a Mon Sep 17 00:00:00 2001 From: markpadbe Date: Wed, 5 Jun 2024 12:54:01 -0700 Subject: [PATCH] replace overridePersonalizationVariant function --- .../personalization/personalization.js | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/libs/features/personalization/personalization.js b/libs/features/personalization/personalization.js index 1473eb2bf0..059b01607c 100644 --- a/libs/features/personalization/personalization.js +++ b/libs/features/personalization/personalization.js @@ -558,6 +558,11 @@ const checkForParamMatch = (paramStr) => { }; async function getPersonalizationVariant(manifestPath, variantNames = [], variantLabel = null) { + const config = getConfig(); + if (config.mep?.variantOverride && config.mep?.variantOverride[manifestPath]) { + return config.mep?.variantOverride[manifestPath]; + } + const variantInfo = variantNames.reduce((acc, name) => { let nameArr = [name]; if (!name.startsWith(TARGET_EXP_PREFIX)) nameArr = name.split(','); @@ -572,7 +577,6 @@ async function getPersonalizationVariant(manifestPath, variantNames = [], varian let userEntitlements = []; if (hasEntitlementTag) { - const config = getConfig(); userEntitlements = await config.entitlements(); } @@ -742,27 +746,20 @@ export async function categorizeActions(experiment) { commands: selectedVariant.commands, }; } +function parseMepParam(config) { + const mepObject = Object.create(null); -function overridePersonalizationVariant(manifest, config) { - const { manifestPath, variantNames } = manifest; - if (!config.mep?.override) return; - let selectedVariant; - config.mep?.override?.split('---').some((item) => { + if (!config.mep?.override) return mepObject; + + config.mep.override.split('---').forEach((item) => { const pair = item.trim().split('--'); - if (pair[0] === manifestPath && pair.length > 1) { - [, selectedVariant] = pair; - return true; + if (pair.length > 1) { + const [manifestPath, selectedVariant] = pair; + mepObject[manifestPath] = selectedVariant; } - return false; }); - if (!selectedVariant) return; - if (variantNames.includes(selectedVariant)) { - manifest.selectedVariantName = selectedVariant; - manifest.selectedVariant = manifest.variants[selectedVariant]; - return; - } - manifest.selectedVariantName = selectedVariant; - manifest.selectedVariant = manifest.variants[selectedVariant]; + + return mepObject; } function compareExecutionOrder(a, b) { @@ -793,7 +790,6 @@ export function cleanAndSortManifestList(manifests) { } else { manifestObj[manifest.manifestPath] = manifest; } - if (config.mep?.override) overridePersonalizationVariant(manifest, config); } catch (e) { console.warn(e); window.lana?.log(`MEP Error parsing manifests: ${e.toString()}`); @@ -839,6 +835,8 @@ export async function applyPers(manifests, postLCP = false) { }; } + config.mep.variantOverride = parseMepParam(config); + if (!manifests?.length) return; let experiments = manifests; for (let i = 0; i < experiments.length; i += 1) {