Skip to content

Commit

Permalink
MWPW-148437 [MILO][MEP] Placeholders don't work if you qualify for de…
Browse files Browse the repository at this point in the history
…fault and override with mep= (#2439)

* replace overridePersonalizationVariant function

* Fix chaining

* Move parseMepParam

* add additional optional chaining operator

Co-authored-by: Vivian A Goodrich <101133187+vgoodric@users.noreply.github.com>

* MWPW-151561 [MILO][MEP] MEP button does not appear if Target is on but there are no pzn manifests (#2441)

* calculate preview in utils

* update personalization to not recalculate

* replace overridePersonalizationVariant function

* Fix chaining

* Move parseMepParam

* add additional optional chaining operator

Co-authored-by: Vivian A Goodrich <101133187+vgoodric@users.noreply.github.com>

* MWPW-151561 [MILO][MEP] MEP button does not appear if Target is on but there are no pzn manifests (#2441)

* calculate preview in utils

* update personalization to not recalculate

* Revert "MWPW-151561 [MILO][MEP] MEP button does not appear if Target is on but there are no pzn manifests (#2441)"

This reverts commit eca39b0.

---------

Co-authored-by: Vivian A Goodrich <101133187+vgoodric@users.noreply.github.com>
Co-authored-by: vgoodric <vgoodric@adobe.com>
  • Loading branch information
3 people authored Jun 11, 2024
1 parent eeca38e commit 5a932b9
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 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?.[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 @@ -608,7 +612,7 @@ const createDefaultExperiment = (manifest) => ({
variants: {},
});

export async function getPersConfig(info, override = false) {
export async function getPersConfig(info, variantOverride = false) {
const {
name,
manifestData,
Expand All @@ -620,7 +624,7 @@ export async function getPersConfig(info, override = false) {
disabled,
event,
} = info;
if (disabled && !override) {
if (disabled && !variantOverride) {
return createDefaultExperiment(info);
}
let data = manifestData;
Expand Down Expand Up @@ -743,26 +747,19 @@ export async function categorizeActions(experiment) {
};
}

function overridePersonalizationVariant(manifest, config) {
const { manifestPath, variantNames } = manifest;
if (!config.mep?.override) return;
let selectedVariant;
config.mep?.override?.split('---').some((item) => {
function parseMepParam(mepParam) {
if (!mepParam) return false;
const mepObject = Object.create(null);
const decodedParam = decodeURIComponent(mepParam);
decodedParam.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 @@ -832,7 +828,7 @@ export async function applyPers(manifests, postLCP = false) {
handleFragmentCommand,
preview: (mepButton !== 'off'
&& (config.env?.name !== 'prod' || mepParam || mepParam === '' || mepButton)),
override: mepParam ? decodeURIComponent(mepParam) : '',
variantOverride: parseMepParam(mepParam),
highlight: (mepHighlight !== undefined && mepHighlight !== 'false'),
mepParam,
targetEnabled: config.mep?.targetEnabled,
Expand All @@ -842,7 +838,7 @@ export async function applyPers(manifests, postLCP = false) {
if (!manifests?.length) return;
let experiments = manifests;
for (let i = 0; i < experiments.length; i += 1) {
experiments[i] = await getPersConfig(experiments[i], config.mep?.override);
experiments[i] = await getPersConfig(experiments[i], config.mep?.variantOverride);
}

experiments = cleanAndSortManifestList(experiments);
Expand Down

0 comments on commit 5a932b9

Please sign in to comment.