Skip to content

Commit

Permalink
stash
Browse files Browse the repository at this point in the history
  • Loading branch information
vgoodric committed Oct 7, 2024
1 parent 1bdfd4a commit 2e6612d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
22 changes: 14 additions & 8 deletions libs/features/personalization/personalization.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const FLAGS = {
all: 'all',
includeFragments: 'include-fragments',
};
let IS_POST_LCP = false;

export const TRACKED_MANIFEST_TYPE = 'personalization';

Expand Down Expand Up @@ -489,6 +490,7 @@ export const updateFragDataProps = (a, inline, sections, fragment) => {
};

export function handleCommands(commands, rootEl, forceInline = false, forceRootEl = false) {
const section1 = document.querySelector('main > div');
commands.forEach((cmd) => {
const { action, content, selector } = cmd;
cmd.content = forceInline ? addHash(content, INLINE_HASH) : content;
Expand All @@ -501,8 +503,10 @@ export function handleCommands(commands, rootEl, forceInline = false, forceRootE
cmd.modifiers = modifiers;

els?.forEach((el) => {
if (!el || (!(action in COMMANDS) && !(action in CREATE_CMDS))
|| (rootEl && !rootEl.contains(el))) return;
if (!el
|| (!(action in COMMANDS) && !(action in CREATE_CMDS))
|| (rootEl && !rootEl.contains(el))
|| (IS_POST_LCP && section1?.contains(el))) return;

if (action in COMMANDS) {
COMMANDS[action](el, cmd);
Expand Down Expand Up @@ -969,7 +973,7 @@ export function parseNestedPlaceholders({ placeholders }) {
});
}

export async function applyPers(manifests, postLCP = false) {
export async function applyPers(manifests) {
if (!manifests?.length) return;
let experiments = manifests;
const config = getConfig();
Expand All @@ -994,13 +998,13 @@ export async function applyPers(manifests, postLCP = false) {
config.mep.commands = consolidateArray(results, 'commands', config.mep.commands);

const main = document.querySelector('main');
if (config.mep.replacepage && !postLCP && main) {
if (config.mep.replacepage && !IS_POST_LCP && main) {
await replaceInner(config.mep.replacepage.val, main);
const { manifestId, targetManifestId } = config.mep.replacepage;
addIds(main, manifestId, targetManifestId);
}

if (!postLCP) config.mep.commands = handleCommands(config.mep.commands);
config.mep.commands = handleCommands(config.mep.commands);
deleteMarkedEls();

const pznList = results.filter((r) => (r.experiment?.manifestType === TRACKED_MANIFEST_TYPE));
Expand Down Expand Up @@ -1060,7 +1064,9 @@ export async function init(enablements = {}) {
mepParam, mepHighlight, mepButton, pzn, promo, target, postLCP,
} = enablements;
const config = getConfig();
if (!postLCP) {
if (postLCP) {
IS_POST_LCP = true;
} else {
config.mep = {
updateFragDataProps,
preview: (mepButton !== 'off'
Expand All @@ -1079,7 +1085,7 @@ export async function init(enablements = {}) {
});
}

if (target === true || (target === 'gnav' && postLCP)) {
if (target === true || (target === 'postlcp' && postLCP)) {
const { getTargetPersonalization } = await import('../../martech/martech.js');
const { targetManifests, targetPropositions } = await getTargetPersonalization();
manifests = manifests.concat(targetManifests);
Expand All @@ -1088,7 +1094,7 @@ export async function init(enablements = {}) {
}
}
try {
await applyPers(manifests, postLCP);
await applyPers(manifests);
} catch (e) {
log(`MEP Error: ${e.toString()}`);
window.lana?.log(`MEP Error: ${e.toString()}`);
Expand Down
2 changes: 1 addition & 1 deletion libs/features/personalization/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function createPreviewPill(manifests) {
});
const config = getConfig();
let targetOnText = config.mep.targetEnabled ? 'on' : 'off';
if (config.mep.targetEnabled === 'gnav') targetOnText = 'on for gnav only';
if (config.mep.targetEnabled === 'postlcp') targetOnText = 'on post LCP';
const personalizationOn = getMetadata('personalization');
const personalizationOnText = personalizationOn && personalizationOn !== '' ? 'on' : 'off';
const simulateHref = new URL(window.location.href);
Expand Down
4 changes: 2 additions & 2 deletions libs/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ export async function decorateFooterPromo(doc = document) {
}

const getMepValue = (val) => {
const valMap = { on: true, off: false, gnav: 'gnav' };
const valMap = { on: true, off: false, postLCP: 'postlcp' };
const finalVal = val?.toLowerCase().trim();
if (finalVal in valMap) return valMap[finalVal];
return finalVal;
Expand Down Expand Up @@ -1049,7 +1049,7 @@ async function checkForPageMods() {

async function loadPostLCP(config) {
await decoratePlaceholders(document.body.querySelector('header'), config);
if (config.mep?.targetEnabled === 'gnav') {
if (config.mep?.targetEnabled === 'postLCP') {
/* c8 ignore next 2 */
const { init } = await import('../features/personalization/personalization.js');
await init({ postLCP: true });
Expand Down

0 comments on commit 2e6612d

Please sign in to comment.