diff --git a/libs/features/personalization/entitlements.js b/libs/features/personalization/entitlements.js index 7dd55853d0..b329c8b338 100644 --- a/libs/features/personalization/entitlements.js +++ b/libs/features/personalization/entitlements.js @@ -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 () => { diff --git a/libs/martech/martech.js b/libs/martech/martech.js index 58328edf33..91906910bc 100644 --- a/libs/martech/martech.js +++ b/libs/martech/martech.js @@ -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'; @@ -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, diff --git a/libs/utils/utils.js b/libs/utils/utils.js index f09580d182..52d3b0e190 100644 --- a/libs/utils/utils.js +++ b/libs/utils/utils.js @@ -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) => { @@ -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) => { @@ -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, @@ -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() diff --git a/test/utils/mocks/mep/head-xlg.html b/test/utils/mocks/mep/head-xlg.html new file mode 100644 index 0000000000..62df5c9dd3 --- /dev/null +++ b/test/utils/mocks/mep/head-xlg.html @@ -0,0 +1,6 @@ + + + +Document Title + ++ diff --git a/test/utils/utils-mep.test.js b/test/utils/utils-mep.test.js index fdbdd7a2e7..e2afe54b64 100644 --- a/test/utils/utils-mep.test.js +++ b/test/utils/utils-mep.test.js @@ -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'); + }); }); });