Skip to content

Commit

Permalink
replace overridePersonalizationVariant function
Browse files Browse the repository at this point in the history
  • Loading branch information
markpadbe committed Jun 5, 2024
1 parent 95a6593 commit c3b1675
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions libs/features/personalization/personalization.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(',');
Expand All @@ -572,7 +577,6 @@ async function getPersonalizationVariant(manifestPath, variantNames = [], varian

let userEntitlements = [];
if (hasEntitlementTag) {
const config = getConfig();
userEntitlements = await config.entitlements();
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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()}`);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c3b1675

Please sign in to comment.