Skip to content

Commit

Permalink
MWPW-152270 - Performance updates and small changes to marketingtech. (
Browse files Browse the repository at this point in the history
…adobecom#2563)

* MWPW-152270 - Performance updates and small changes to marketingtech.

* Conditionally load assets from domain proxies to allow for better performance.
* Change default launch url for dev.

Resolves: [MWPW-152270](https://jira.corp.adobe.com/browse/MWPW-152270)

**Test URLs:**
- Before: https://stage--milo--adobecom.hlx.page/?martech=off
- After: https://marketingtech-updates--milo--adobecom.hlx.page/?martech=off

* trivial

* MWPW-152270 - Performance updates and small changes to marketingtech.

* Update libs/martech/martech.js

This is shorter and I like how simple this is. committing this change.

Co-authored-by: Narcis Radu <[email protected]>

* trivial: oopsie fix...

* Fixed test that was failing with chrischrischris's help by moving to new file.

* lint fixes

---------

Co-authored-by: Narcis Radu <[email protected]>
  • Loading branch information
bbythewa and narcis-radu authored Jul 17, 2024
1 parent 9d49e78 commit b197e90
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 45 deletions.
1 change: 0 additions & 1 deletion libs/deps/martech.main.standard.min.js

This file was deleted.

1 change: 0 additions & 1 deletion libs/deps/martech.main.standard.qa.min.js

This file was deleted.

65 changes: 45 additions & 20 deletions libs/martech/martech.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,6 @@ const getTargetPersonalization = async () => {
};
};

const getDtmLib = (env) => ({
edgeConfigId: env.consumer?.edgeConfigId || env.edgeConfigId,
url:
env.name === 'prod'
? env.consumer?.marTechUrl || 'https://assets.adobedtm.com/d4d114c60e50/a0e989131fd5/launch-5dd5dd2177e6.min.js'
: env.consumer?.marTechUrl || 'https://assets.adobedtm.com/d4d114c60e50/a0e989131fd5/launch-a27b33fc2dc0-development.min.js',
});

const setupEntitlementCallback = () => {
const setEntitlements = async (destinations) => {
const { default: parseEntitlements } = await import('../features/personalization/entitlements.js');
Expand Down Expand Up @@ -190,8 +182,12 @@ const setupEntitlementCallback = () => {
);
};

function isProxied() {
return /^(www|milo|business|blog)(\.stage)?\.adobe\.com$/.test(window.location.hostname);
}

let filesLoadedPromise = false;
const loadMartechFiles = async (config, url, edgeConfigId) => {
const loadMartechFiles = async (config) => {
if (filesLoadedPromise) return filesLoadedPromise;

filesLoadedPromise = async () => {
Expand All @@ -208,19 +204,52 @@ const loadMartechFiles = async (config, url, edgeConfigId) => {
);
setDeep(window, 'digitalData.diagnostic.franklin.implementation', 'milo');

const launchUrl = config.env.consumer?.marTechUrl || (
isProxied()
? '/marketingtech'
: 'https://assets.adobedtm.com'
) + (
config.env.name === 'prod'
? '/d4d114c60e50/a0e989131fd5/launch-5dd5dd2177e6.min.js'
: '/d4d114c60e50/a0e989131fd5/launch-2c94beadc94f-development.min.js'
);
loadLink(launchUrl, { as: 'script', rel: 'preload' });

window.marketingtech = {
adobe: {
launch: { url, controlPageLoad: true },
alloy: { edgeConfigId },
launch: {
url: launchUrl,
controlPageLoad: true,
},
alloy: {
edgeConfigId: config.env.consumer?.edgeConfigId || config.env.edgeConfigId,
edgeDomain: (
isProxied()
? window.location.hostname
: 'sstats.adobe.com'
),
edgeBasePath: (
isProxied()
? 'experienceedge'
: 'ee'
),
},
target: false,
},
milo: true,
};
window.edgeConfigId = edgeConfigId;
window.edgeConfigId = config.env.edgeConfigId;

await loadScript((
isProxied()
? ''
: 'https://www.adobe.com'
) + (
config.env.name === 'prod'
? '/marketingtech/main.standard.min.js'
: '/marketingtech/main.standard.qa.min.js'
));

const env = ['stage', 'local'].includes(config.env.name) ? '.qa' : '';
const martechPath = `martech.main.standard${env}.min.js`;
await loadScript(`${config.miloLibs || config.codeRoot}/deps/${martechPath}`);
window._satellite.track('pageload');
};

Expand All @@ -234,11 +263,7 @@ export default async function init({
postLCP = false,
}) {
const config = getConfig();

const { url, edgeConfigId } = getDtmLib(config.env);
loadLink(url, { as: 'script', rel: 'preload' });

const martechPromise = loadMartechFiles(config, url, edgeConfigId);
const martechPromise = loadMartechFiles(config);

if (persEnabled) {
loadLink(
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/scripts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('Decorating', async () => {

it('martech test', async () => {
const el = await waitForElement(
'script[src$="/libs/deps/martech.main.standard.qa.min.js"]',
'script[src*="main.standard.qa.min.js"]',
{ rootEl: document.head },
);
expect(el).to.exist;
Expand Down
47 changes: 47 additions & 0 deletions test/utils/utils-mep-gnav.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { readFile } from '@web/test-runner-commands';
import { expect } from '@esm-bundle/chai';
import sinon from 'sinon';

const utils = {};

const config = {
codeRoot: '/libs',
locales: { '': { ietf: 'en-US', tk: 'hah7vzn.css' } },
};

describe('Utils - MEP GNav', () => {
before(async () => {
const module = await import('../../libs/utils/utils.js');
module.setConfig(config);
Object.keys(module).forEach((func) => {
utils[func] = module[func];
});
window.hlx = { rum: { isSelected: false } };
});

after(() => {
delete window.hlx;
});

describe('target set to gnav', async () => {
const MANIFEST_JSON = {
info: { total: 2, offset: 0, limit: 2, data: [{ key: 'manifest-type', value: 'Personalization' }, { key: 'manifest-override-name', value: '' }, { key: 'name', value: '1' }] }, placeholders: { total: 0, offset: 0, limit: 0, data: [] }, experiences: { total: 1, offset: 0, limit: 1, data: [{ action: 'insertContentAfter', selector: '.marquee', 'page filter (optional)': '/products/special-offers', chrome: 'https://main--milo--adobecom.hlx.page/drafts/mariia/fragments/personalizationtext' }] }, ':version': 3, ':names': ['info', 'placeholders', 'experiences'], ':type': 'multi-sheet',
};
function htmlResponse() {
return new Promise((resolve) => {
resolve({
ok: true,
json: () => MANIFEST_JSON,
});
});
}

it('have target be set to gnav and save in config', async () => {
window.fetch = sinon.stub().returns(htmlResponse());
document.head.innerHTML = await readFile({ path: './mocks/mep/head-target-gnav.html' });
await utils.loadArea();
const resultConfig = utils.getConfig();
expect(resultConfig.mep.targetEnabled).to.equal('gnav');
});
});
});
22 changes: 0 additions & 22 deletions test/utils/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,28 +638,6 @@ describe('Utils', () => {
});
});

describe('target set to gnav', async () => {
const MANIFEST_JSON = {
info: { total: 2, offset: 0, limit: 2, data: [{ key: 'manifest-type', value: 'Personalization' }, { key: 'manifest-override-name', value: '' }, { key: 'name', value: '1' }] }, placeholders: { total: 0, offset: 0, limit: 0, data: [] }, experiences: { total: 1, offset: 0, limit: 1, data: [{ action: 'insertContentAfter', selector: '.marquee', 'page filter (optional)': '/products/special-offers', chrome: 'https://main--milo--adobecom.hlx.page/drafts/mariia/fragments/personalizationtext' }] }, ':version': 3, ':names': ['info', 'placeholders', 'experiences'], ':type': 'multi-sheet',
};
function htmlResponse() {
return new Promise((resolve) => {
resolve({
ok: true,
json: () => MANIFEST_JSON,
});
});
}

it('have target be set to gnav and save in config', async () => {
window.fetch = sinon.stub().returns(htmlResponse());
document.head.innerHTML = await readFile({ path: './mocks/mep/head-target-gnav.html' });
await utils.loadArea();
const resultConfig = utils.getConfig();
expect(resultConfig.mep.targetEnabled).to.equal('gnav');
});
});

describe('filterDuplicatedLinkBlocks', () => {
it('returns empty array if receives invalid params', () => {
expect(utils.filterDuplicatedLinkBlocks()).to.deep.equal([]);
Expand Down

0 comments on commit b197e90

Please sign in to comment.