8000 MWPW-172886 [MEP] Support MEP AICS pzn tags recieved from API REWORKED by ivanvatadobe · Pull Request #4358 · adobecom/milo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

MWPW-172886 [MEP] Support MEP AICS pzn tags recieved from API REWORKED #4358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 17 commits into
base: stage
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions libs/features/personalization/personalization.js
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,15 @@ async function setMepCountry(config) {
}
}

async function setMepLob(config) {
try {
const lobPromise = await config.mep.userLOBPromise;
if (lobPromise) config.mep.meplob = lobPromise;
} catch (e) {
log('MEP Error: Unable to get user line of business');
}
}

async function getPersonalizationVariant(
manifestPath,
variantNames = [],
Expand Down Expand Up @@ -945,6 +954,7 @@ async function getPersonalizationVariant(
if (name.toLowerCase().startsWith('previouspage-')) return checkForPreviousPageMatch(name);
if (hasCountryMatch(name, config)) return true;
if (userEntitlements?.includes(name)) return true;
if (config.mep?.meplob && config.mep?.meplob === name.split('lob-')[1]?.toLowerCase()) return true;
return PERSONALIZATION_KEYS.includes(name) && PERSONALIZATION_TAGS[name]();
};

Expand All @@ -960,9 +970,8 @@ async function getPersonalizationVariant(
return !processedList.includes(false);
};

if (config.mep?.geoLocation) {
await setMepCountry(config);
}
if (config.mep?.geoLocation) await setMepCountry(config);
if (config.mep?.meplob === true) await setMepLob(config);

const matchingVariant = variantNames.find((variant) => variantInfo[variant].some(matchVariant));
return matchingVariant;
Expand Down Expand Up @@ -1447,7 +1456,7 @@ export async function init(enablements = {}) {
const {
mepParam, mepHighlight, mepButton, pzn, pznroc, promo, enablePersV2,
target, ajo, countryIPPromise, mepgeolocation, targetInteractionPromise, calculatedTimeout,
postLCP,
postLCP, meplob, userLOBPromise,
} = enablements;
const config = getConfig();
if (postLCP) {
Expand All @@ -1467,8 +1476,9 @@ export async function init(enablements = {}) {
countryIPPromise,
geoLocation: mepgeolocation,
targetInteractionPromise,
meplob,
userLOBPromise,
};

manifests = manifests.concat(await combineMepSources(pzn, pznroc, promo, mepParam));
manifests?.forEach((manifest) => {
if (manifest.disabled) return;
Expand Down
42 changes: 42 additions & 0 deletions libs/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,42 @@ export function enablePersonalizationV2() {
return !!enablePersV2 && isSignedOut();
}

export function getCookie(key) {
const cookie = document.cookie.split(';')
.map((x) => decodeURIComponent(x.trim()).split(/=(.*)/s))
.find(([k]) => k === key);
return cookie ? cookie[1] : null;
}
export async function getSpectraLOB(lastVisitedPage, config = getConfig()) {
const getECID = getCookie('AMCV_9E1005A551ED61CA0A490D45@AdobeOrg');
if (!getECID) return false;
const [, ECID] = getECID.split('|');
const apiDomain = config?.env.name === 'prod' ? '' : '-stage';
let apiUrl = `https://cchome${apiDomain}.adobe.io/int/v1/aep/events/webpage?ecid=${ECID}`;
if (lastVisitedPage) {
const newUrl = new URL(lastVisitedPage);
const refWithoutParams = `${newUrl.origin}${newUrl.pathname}`;
apiUrl = `${apiUrl}&lastVisitedPage=${refWithoutParams}`;
}

try {
const rawResponse = await fetch(apiUrl, {
method: 'GET',
headers: {
'x-api-key': 'MarketingTech',
'Content-Type': 'application/json',
},
body: null,
});
const content = await rawResponse.json();
return content.modelLineOfBusiness?.toLowerCase();
} catch (e) {
if (e.name === 'TimeoutError') window.lana?.log('Spectra Timeout'); // Abort signal
else window.lana?.log(e.reason || e.error || e.message, { errorType: 'i' });
return false;
}
}

async function checkForPageMods() {
const {
mep: mepParam,
Expand All @@ -1395,6 +1431,7 @@ async function checkForPageMods() {
} = Object.fromEntries(PAGE_URL.searchParams);
let targetInteractionPromise = null;
let countryIPPromise = null;
let userLOBPromise = null;

let calculatedTimeout = null;
if (mepParam === 'off') return;
Expand All @@ -1405,6 +1442,7 @@ async function checkForPageMods() {
const xlg = martech === 'off' ? false : getMepEnablement('xlg');
const ajo = martech === 'off' ? false : getMepEnablement('ajo');
const mepgeolocation = getMepEnablement('mepgeolocation');
const meplob = getMepEnablement('lob');

if (!(pzn || pznroc || target || promo || mepParam
|| mepHighlight || mepButton || mepParam === '' || xlg || ajo)) return;
Expand All @@ -1417,6 +1455,8 @@ async function checkForPageMods() {
countryIPPromise = getAkamaiCode(true);
}
}
if (meplob === true) userLOBPromise = getSpectraLOB(document.referrer);

const enablePersV2 = enablePersonalizationV2();
if ((target || xlg) && enablePersV2) {
const params = new URL(window.location.href).searchParams;
Expand Down Expand Up @@ -1463,6 +1503,8 @@ async function checkForPageMods() {
targetInteractionPromise,
calculatedTimeout,
enablePersV2,
userLOBPromise,
meplob,
});
}

Expand Down
Loading
0