Skip to content
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

MWPW-156867 [MILO][MEP][ANALYTICS] Support Column nicknames #3510

Merged
merged 34 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2e6612d
stash
vgoodric Oct 7, 2024
22b9995
ready to publish
vgoodric Oct 9, 2024
e8ed916
interact call coming back but timing out
vgoodric Oct 9, 2024
592b07e
working on a fast connection
vgoodric Oct 9, 2024
4f6c03d
clean up ifs
vgoodric Oct 9, 2024
f9531e1
working with promise
vgoodric Oct 10, 2024
250248a
Merge branch 'stage' into meppostlcp
vgoodric Oct 11, 2024
f7576c4
use camel case on let variable
vgoodric Oct 14, 2024
4b6771b
unit tests
vgoodric Oct 15, 2024
cd095b1
create mepxlg branch
vgoodric Oct 15, 2024
0a35738
update library
vgoodric Oct 15, 2024
a335fcb
require full hostname match
vgoodric Oct 15, 2024
63bed05
update reference for unit test
vgoodric Oct 15, 2024
f920d67
update unit tests
vgoodric Oct 16, 2024
9d7709e
Merge branch 'meppostlcp' into mepxlg
vgoodric Oct 16, 2024
e30a2f0
switch to use config instead of domain list and stub response in unit…
vgoodric Oct 16, 2024
eefbe75
update fetch to 2
vgoodric Oct 16, 2024
7508167
updating another fetch to 2
vgoodric Oct 16, 2024
76975b6
restore normalizePath to use preview domains on preview links
vgoodric Oct 17, 2024
e571daa
preload segment list json
vgoodric Oct 17, 2024
9112446
use getFederatedUrl instead
vgoodric Oct 17, 2024
0107cc7
import at top so we don't have to make normalizePath async
vgoodric Oct 17, 2024
a4b42ec
add federated link function to registerInBlockActions
vgoodric Oct 17, 2024
cf40dbf
add to unit test
vgoodric Oct 17, 2024
29f4869
initial commit
ivanvatadobe Oct 22, 2024
1e061e6
Merge branch 'mepgnavfedlink' into experience-nicknames
ivanvatadobe Oct 22, 2024
5299e9c
stash commit
ivanvatadobe Nov 5, 2024
5cd870e
Merge branch 'stage' into experience-nicknames
ivanvatadobe Nov 18, 2024
091282f
remove dupe valMap const
ivanvatadobe Nov 26, 2024
fdbcf4a
Merge branch 'stage' into experience-nicknames
ivanvatadobe Jan 8, 2025
cb847dc
update test files
ivanvatadobe Jan 17, 2025
3bb7845
Merge branch 'stage' into experience-nicknames
ivanvatadobe Jan 17, 2025
7e08ad5
linting error fix
ivanvatadobe Jan 21, 2025
5126b58
Merge branch 'stage' into experience-nicknames
vgoodric Jan 24, 2025
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
19 changes: 13 additions & 6 deletions libs/features/personalization/personalization.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ let isPostLCP = false;

export const TRACKED_MANIFEST_TYPE = 'personalization';

// Replace any non-alpha chars except comma, space, ampersand and hyphen
const RE_KEY_REPLACE = /[^a-z0-9\- _,&=]/g;
// Replace any non-alpha chars except comma, space, ampersand, colon, and hyphen
const RE_KEY_REPLACE = /[^a-z0-9\- _,&=:]/g;

const MANIFEST_KEYS = [
'action',
Expand Down Expand Up @@ -574,7 +574,7 @@ const getVariantInfo = (line, variantNames, variants, manifestPath, fTargetId) =
if (!config.mep?.preview) manifestId = false;
const { origin } = PAGE_URL;
variantNames.forEach((vn) => {
const targetManifestId = vn.startsWith(TARGET_EXP_PREFIX) ? targetId : false;
const targetManifestId = vn.includes(TARGET_EXP_PREFIX) ? targetId : false;
if (!line[vn] || line[vn].toLowerCase() === 'false') return;

const variantInfo = {
Expand Down Expand Up @@ -784,14 +784,16 @@ async function getPersonalizationVariant(manifestPath, variantNames = [], varian
}

const hasMatch = (name) => {
if (name === '') return true;
if (!name) return true;
if (name === variantLabel?.toLowerCase()) return true;
if (name.startsWith('param-')) return checkForParamMatch(name);
if (userEntitlements?.includes(name)) return true;
return PERSONALIZATION_KEYS.includes(name) && PERSONALIZATION_TAGS[name]();
};

const matchVariant = (name) => {
const matchVariant = (n) => {
// split before checks
const name = n.includes(':') ? n.split(':')[1] : n;
if (name.startsWith(TARGET_EXP_PREFIX)) return hasMatch(name);
const processedList = name.split('&').map((condition) => {
const reverse = condition.trim().startsWith(COLUMN_NOT_OPERATOR);
Expand Down Expand Up @@ -1078,7 +1080,12 @@ export async function applyPers(manifests) {

const pznVariants = pznList.map((r) => {
const val = r.experiment.selectedVariantName.replace(TARGET_EXP_PREFIX, '').trim().slice(0, 15);
return val === 'default' ? 'nopzn' : val;
const arr = val.split(':');
if (arr.length > 2 || arr[0]?.trim() === '' || arr[1]?.trim() === '') {
log('MEP Error: When using (optional) column nicknames, please use the following syntax: "<nickname>: <original audience>"');
}
if (!val.includes(':') || val.startsWith(':')) return val === 'default' ? 'nopzn' : val;
return arr[0].trim();
});
const pznManifests = pznList.map((r) => r.experiment.analyticsTitle);
config.mep.martech = `|${pznVariants.join('--')}|${pznManifests.join('--')}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"action":"replaceContent",
"selector":"#notthere",
"page filter (optional)":"",
"chrome & loggedout":"https://main--milo--adobecom.hlx.page/drafts/vgoodrich/fragments/139173-mep-and/android"
"my nickname: chrome & loggedout":"https://main--milo--adobecom.hlx.page/drafts/vgoodrich/fragments/139173-mep-and/android"
}
]
},
Expand Down
53 changes: 53 additions & 0 deletions test/features/personalization/mocks/manifestWithNicknames.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"info": {
"total": 3,
"offset": 0,
"limit": 3,
"data": [
{
"key": "manifest-type",
"value": "Personalization"
},
{
"key": "manifest-override-name",
"value": ""
},
{
"key": "manifest-execution-order",
"value": "Normal"
}
]
},
"experiences": {
"total": 1,
"offset": 0,
"limit": 1,
"data": [
{
"action": "replace",
"selector": "any-header",
"page filter (optional)": "",
"target-var1": "target-var1",
"challenger 2: target-var2": "challenger 2: target-var2",
"param-nickname=false": "param-nickname=false",
"pzn2: param-nickname=true": "pzn2: param-nickname=true",
"pzn2: param-nickname=double:": "pzn2: param-nickname=double:",
"param-nickname=end:": "param-nickname=end:",
":param-nickname=start": ":param-nickname=start"
}
]
},
"placeholders": {
"total": 0,
"offset": 0,
"limit": 0,
"data": []
},
":version": 3,
":names": [
"experiences",
"info",
"placeholders"
],
":type": "multi-sheet"
}
51 changes: 49 additions & 2 deletions test/features/personalization/personalization.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('Functional Test', () => {
// Add custom keys so tests doesn't rely on real data
const config = getConfig();
config.env = { name: 'prod' };
config.locale = { ietf: 'en-US', prefix: '' };
config.consumerEntitlements = {
'11111111-aaaa-bbbb-6666-cccccccccccc': 'my-special-app',
'22222222-xxxx-bbbb-7777-cccccccccccc': 'fireflies',
Expand Down Expand Up @@ -152,11 +153,11 @@ describe('Functional Test', () => {
expect(config.mep?.martech).to.be.undefined;
});

it('should choose chrome & logged out', async () => {
it('should choose chrome & logged out (using nickname)', async () => {
await loadManifestAndSetResponse('./mocks/manifestWithAmpersand.json');
await init(mepSettings);
const config = getConfig();
expect(config.mep?.martech).to.equal('|chrome & logged|ampersand');
expect(config.mep?.martech).to.equal('|my nickname|ampersand');
});

it('should choose not firefox', async () => {
Expand All @@ -166,6 +167,52 @@ describe('Functional Test', () => {
expect(config.mep?.martech).to.equal('|not firefox|not');
});

it('should not error when nickname has multiple colons', async () => {
await loadManifestAndSetResponse('./mocks/manifestWithNicknames.json');
const tempMepSettings = {
mepParam: '/path/to/manifest.json--pzn2: param-nickname=double:',
mepHighlight: false,
mepButton: false,
pzn: '/path/to/manifest.json',
promo: false,
target: false,
};
await init(tempMepSettings);
const config = getConfig();
console.log('test: ', config);
expect(config.mep?.martech).to.equal('|pzn2|manifest');
});

it('should not error when name nickname is empty', async () => {
await loadManifestAndSetResponse('./mocks/manifestWithNicknames.json');
const tempMepSettings = {
mepParam: '/path/to/manifest.json--:param-nickname=start',
mepHighlight: false,
mepButton: false,
pzn: '/path/to/manifest.json',
promo: false,
target: false,
};
await init(tempMepSettings);
const config = getConfig();
expect(config.mep?.martech).to.equal('|:param-nickname|manifest');
});

it('should show nickname instead of original audience when using nicknames syntax', async () => {
await loadManifestAndSetResponse('./mocks/manifestWithNicknames.json');
const tempMepSettings = {
mepParam: '/path/to/manifest.json--pzn2: param-nickname=true',
mepHighlight: false,
mepButton: false,
pzn: '/path/to/manifest.json',
promo: false,
target: false,
};
await init(tempMepSettings);
const config = getConfig();
expect(config.mep?.martech).to.equal('|pzn2|manifest');
});

it('should read and use entitlement data', async () => {
setConfig(getConfig());
const config = getConfig();
Expand Down
Loading