Skip to content

Commit

Permalink
MWPW-156898 [MEP] Add setting to use XLG segments in MEP while logged…
Browse files Browse the repository at this point in the history
… out (#2754)

* MWPW-156898 [MEP] Add setting to use XLG segments in MEP while logged out

* add 2 segments

* unit test

* unit test update
  • Loading branch information
vgoodric authored Aug 21, 2024
1 parent 3480ba2 commit 0ae86a3
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 52 deletions.
4 changes: 4 additions & 0 deletions libs/features/personalization/entitlements.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ const ENTITLEMENT_MAP = {
'5c6a4bb8-a2f3-4202-8cca-f5e918b969dc': 'firefly-signup-source',
'20106303-e88c-4b15-93e5-f6a1c3215a12': 'firefly-web-usage',
'3df0b0b0-d06e-4fcc-986e-cc97f54d04d8': 'acrobat-web-usage',

// Express segments
'2a537e84-b35f-4158-8935-170c22b8ae87': 'express-entitled',
'eb0dcb78-3e56-4b10-89f9-51831f2cc37f': 'express-pep',
};

export const getEntitlementMap = async () => {
Expand Down
18 changes: 12 additions & 6 deletions libs/martech/martech.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { getConfig, getMetadata, loadIms, loadLink, loadScript } from '../utils/utils.js';
import {
getConfig, getMetadata, loadIms, loadLink, loadScript, getMepEnablement,
} from '../utils/utils.js';

const ALLOY_SEND_EVENT = 'alloy_sendEvent';
const ALLOY_SEND_EVENT_ERROR = 'alloy_sendEvent_error';
Expand Down Expand Up @@ -178,11 +180,15 @@ const loadMartechFiles = async (config) => {
if (filesLoadedPromise) return filesLoadedPromise;

filesLoadedPromise = async () => {
loadIms()
.then(() => {
if (window.adobeIMS.isSignedInUser()) setupEntitlementCallback();
})
.catch(() => {});
if (getMepEnablement('xlg') === 'loggedout') {
setupEntitlementCallback();
} else {
loadIms()
.then(() => {
if (window.adobeIMS.isSignedInUser()) setupEntitlementCallback();
})
.catch(() => {});
}

setDeep(
window,
Expand Down
96 changes: 50 additions & 46 deletions libs/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,49 @@ export async function decorateFooterPromo(doc = document) {
await initFooterPromo(footerPromoTag, footerPromoType, doc);
}

const getMepValue = (val) => {
const valMap = { on: true, off: false, gnav: 'gnav' };
const finalVal = val?.toLowerCase().trim();
if (finalVal in valMap) return valMap[finalVal];
return finalVal;
};

const getMdValue = (key) => {
const value = getMetadata(key);
if (value) {
return getMepValue(value);
}
return false;
};

const getPromoMepEnablement = () => {
const mds = [
'apac_manifestnames',
'emea_manifestnames',
'americas_manifestnames',
'jp_manifestnames',
'manifestnames',
];
const mdObject = mds.reduce((obj, key) => {
const val = getMdValue(key);
if (val) {
obj[key] = val;
}
return obj;
}, {});
if (Object.keys(mdObject).length) {
return mdObject;
}
return false;
};

export const getMepEnablement = (mdKey, paramKey = false) => {
const paramValue = PAGE_URL.searchParams.get(paramKey || mdKey);
if (paramValue) return getMepValue(paramValue);
if (PROMO_PARAM === paramKey) return getPromoMepEnablement();
return getMdValue(mdKey);
};

let imsLoaded;
export async function loadIms() {
imsLoaded = imsLoaded || new Promise((resolve, reject) => {
Expand Down Expand Up @@ -873,7 +916,10 @@ export async function loadIms() {
: `${base}/deps/imslib.min.js`;
loadScript(path);
}).then(() => {
if (!window.adobeIMS?.isSignedInUser()) {
if (getMepEnablement('xlg') === 'loggedout') {
/* c8 ignore next */
getConfig().entitlements();
} else if (!window.adobeIMS?.isSignedInUser()) {
getConfig().entitlements([]);
}
}).catch((e) => {
Expand Down Expand Up @@ -909,49 +955,6 @@ export async function loadMartech({
return true;
}

const getMepValue = (val) => {
const valMap = { on: true, off: false, gnav: 'gnav' };
const finalVal = val?.toLowerCase().trim();
if (finalVal in valMap) return valMap[finalVal];
return finalVal;
};

const getMdValue = (key) => {
const value = getMetadata(key);
if (value) {
return getMepValue(value);
}
return false;
};

const getPromoMepEnablement = () => {
const mds = [
'apac_manifestnames',
'emea_manifestnames',
'americas_manifestnames',
'jp_manifestnames',
'manifestnames',
];
const mdObject = mds.reduce((obj, key) => {
const val = getMdValue(key);
if (val) {
obj[key] = val;
}
return obj;
}, {});
if (Object.keys(mdObject).length) {
return mdObject;
}
return false;
};

export const getMepEnablement = (mdKey, paramKey = false) => {
const paramValue = PAGE_URL.searchParams.get(paramKey || mdKey);
if (paramValue) return getMepValue(paramValue);
if (PROMO_PARAM === paramKey) return getPromoMepEnablement();
return getMdValue(mdKey);
};

async function checkForPageMods() {
const {
mep: mepParam,
Expand All @@ -963,9 +966,10 @@ async function checkForPageMods() {
const pzn = getMepEnablement('personalization');
const promo = getMepEnablement('manifestnames', PROMO_PARAM);
const target = martech === 'off' ? false : getMepEnablement('target');
const xlg = martech === 'off' ? false : getMepEnablement('xlg');
if (!(pzn || target || promo || mepParam
|| mepHighlight || mepButton || mepParam === '')) return;
if (target) {
|| mepHighlight || mepButton || mepParam === '' || xlg)) return;
if (target || xlg) {
loadMartech();
} else if (pzn && martech !== 'off') {
loadIms()
Expand Down
6 changes: 6 additions & 0 deletions test/utils/mocks/mep/head-xlg.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<meta name="personalization" content="https://main--milo--adobecom.hlx.page/products/special-offers-manifest.json">
<meta name="xlg" content="loggedout">

<title>Document Title</title>
<link rel="icon" href="data:,">
+
5 changes: 5 additions & 0 deletions test/utils/utils-mep.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,10 @@ describe('MEP Utils', () => {
expect(persEnabled).to.equal('https://main--milo--adobecom.hlx.page/products/special-offers-manifest.json');
expect(targetEnabled).to.equal(false);
});
it('checks xlg metadata', async () => {
document.head.innerHTML = await readFile({ path: './mocks/mep/head-xlg.html' });
const xlgEnabled = getMepEnablement('xlg');
expect(xlgEnabled).to.equal('loggedout');
});
});
});

0 comments on commit 0ae86a3

Please sign in to comment.