From 38cd8b9aecd9e23ae76c2f0817d8bfd6dee47880 Mon Sep 17 00:00:00 2001 From: Brandon Marshall Date: Mon, 4 May 2026 11:36:22 -0700 Subject: [PATCH] MWPW-193461 update marketolibs param (#159) --- scripts/scripts.js | 9 ++++++--- test/scripts/scripts.test.js | 13 ++++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/scripts/scripts.js b/scripts/scripts.js index f5f72470..f328efcc 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -200,13 +200,16 @@ export function setLibs(location) { } export function getMarketoLibs(location = window.location, getMetadata = null) { - const { search } = location; + const { search, hostname } = location; const branch = new URLSearchParams(search).get('marketolibs') || getMetadata?.('marketo-libs'); if (!branch) return null; if (!/^[a-zA-Z0-9_-]+$/.test(branch)) throw new Error('Invalid branch name.'); - + if (!['.aem.', '.hlx.', '.stage.', 'local', '.da.'].some((i) => hostname.includes(i))) { + if (branch === 'main') return 'https://main--da-marketo--adobecom.aem.live/mkto'; + if (branch === 'stage') return 'https://stage--da-marketo--adobecom.aem.live/mkto'; + return null; + } if (branch === 'local') return 'http://localhost:6586/mkto'; - if (branch === 'main') return 'https://main--da-marketo--adobecom.aem.live/mkto'; return branch.includes('--') ? `https://${branch}.aem.live/mkto` : `https://${branch}--da-marketo--adobecom.aem.live/mkto`; } diff --git a/test/scripts/scripts.test.js b/test/scripts/scripts.test.js index d3c7fcb4..aed0fdd4 100644 --- a/test/scripts/scripts.test.js +++ b/test/scripts/scripts.test.js @@ -247,11 +247,18 @@ describe('injectMarqueePlayIcon', () => { describe('Marketo Libs', () => { const tests = [ ['https://business.adobe.com', '', null], + ['https://business.adobe.com?marketolibs=main', '', 'https://main--da-marketo--adobecom.aem.live/mkto'], + ['https://business.adobe.com?marketolibs=stage', '', 'https://stage--da-marketo--adobecom.aem.live/mkto'], + ['https://business.adobe.com?marketolibs=foo', '', null], + ['https://business.adobe.com?marketolibs=awesome--da-marketo--forkedowner', '', null], ['https://business.adobe.com', 'main', 'https://main--da-marketo--adobecom.aem.live/mkto'], - ['https://business.adobe.com?marketolibs=foo', '', 'https://foo--da-marketo--adobecom.aem.live/mkto'], + ['https://business.adobe.com', 'stage', 'https://stage--da-marketo--adobecom.aem.live/mkto'], + ['https://business.adobe.com', 'local', null], + ['https://business.adobe.com', 'foo', null], ['https://business.stage.adobe.com', '', null], - ['https://business.stage.adobe.com?marketolibs=foo', '', 'https://foo--da-marketo--adobecom.aem.live/mkto'], + ['https://business.stage.adobe.com?marketolibs=main', '', 'https://main--da-marketo--adobecom.aem.live/mkto'], ['https://business.stage.adobe.com?marketolibs=awesome--da-marketo--forkedowner', '', 'https://awesome--da-marketo--forkedowner.aem.live/mkto'], + ['https://business.stage.adobe.com', 'awesome--da-marketo--forkedowner', 'https://awesome--da-marketo--forkedowner.aem.live/mkto'], ['https://main--da-bacom--adobecom.aem.page/', '', null], ['https://main--da-bacom--adobecom.aem.page/?marketolibs=foo', '', 'https://foo--da-marketo--adobecom.aem.live/mkto'], ['https://main--da-bacom--adobecom.aem.page/?marketolibs=local', '', 'http://localhost:6586/mkto'], @@ -263,7 +270,7 @@ describe('Marketo Libs', () => { ]; tests.forEach(([url, metadata, expected]) => { - it(`Sets marketo libs for ${url} with metadata ${metadata}`, () => { + it(`Sets marketo libs for ${url} ${metadata ? `with metadata ${metadata}` : ''}`, () => { const location = new URL(url); const libs = getMarketoLibs(location, () => metadata);