From d9e9bc7cdd8f1e24c9780ad80849a684f2e07c47 Mon Sep 17 00:00:00 2001 From: Xinyi Feng Date: Sun, 21 Jul 2024 14:36:49 -0700 Subject: [PATCH 1/2] support naming feature for page variant --- plugins/experimentation/src/index.js | 6 +++++- plugins/experimentation/src/preview.js | 4 ++-- scripts/scripts.js | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/experimentation/src/index.js b/plugins/experimentation/src/index.js index 8e9e273d..b5dd37cb 100644 --- a/plugins/experimentation/src/index.js +++ b/plugins/experimentation/src/index.js @@ -584,15 +584,19 @@ async function getExperimentConfig(pluginOptions, metadata, overrides) { pages: [window.location.pathname], label: 'Control', }; + // get the custom labels for the variants names pages.forEach((page, i) => { const vname = `challenger-${i + 1}`; + // label with custom name or default + const customLabel = labelNames.length > i ? labelNames[i] : `Challenger ${i + 1}`; + variantNames.push(vname); variants[vname] = { percentageSplit: `${splits[i].toFixed(4)}`, pages: [page], blocks: [], - label: `Challenger ${i + 1}`, + label: customLabel, }; }); inferEmptyPercentageSplits(Object.values(variants)); diff --git a/plugins/experimentation/src/preview.js b/plugins/experimentation/src/preview.js index e69ca6c5..86d4e59d 100644 --- a/plugins/experimentation/src/preview.js +++ b/plugins/experimentation/src/preview.js @@ -213,9 +213,9 @@ function createVariant(experiment, variantName, config, options) { experimentURL.searchParams.set(options.experimentsQueryParameter, `${experiment}/${variantName}`); return { - label: `${variantName}`, + label: `${variant.label}`, description: ` -

${variant.label}

+

${variantName}

(${percentage} split)

`, actions: [{ label: 'Simulate', href: experimentURL.href }], diff --git a/scripts/scripts.js b/scripts/scripts.js index d2637df3..548c8da9 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -41,7 +41,7 @@ window.hlx.plugins.add('rum-conversion', { window.hlx.plugins.add('experimentation', { condition: () => document.head.querySelector('[name^="experiment"],[name^="campaign-"],[name^="audience-"]') - || document.head.querySelector('[property^="campaign:-"],[property^="audience:-"]') + || document.head.querySelector('[property^="campaign:"],[property^="audience:"]') || document.querySelector('.section[class*="experiment-"],.section[class*="audience-"],.section[class*="campaign-"]') || [...document.querySelectorAll('.section-metadata div')].some((d) => d.textContent.match(/Experiment|Campaign|Audience/i)), options: { audiences: AUDIENCES }, From 3624f6ca765a900cbb54165e6b664a0c70a16b9e Mon Sep 17 00:00:00 2001 From: Xinyi Feng Date: Sun, 21 Jul 2024 14:42:26 -0700 Subject: [PATCH 2/2] add naming support for fragment experiments --- plugins/experimentation/src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/experimentation/src/index.js b/plugins/experimentation/src/index.js index b5dd37cb..5c29bf9d 100644 --- a/plugins/experimentation/src/index.js +++ b/plugins/experimentation/src/index.js @@ -586,6 +586,7 @@ async function getExperimentConfig(pluginOptions, metadata, overrides) { }; // get the custom labels for the variants names + const labelNames = stringToArray(metadata.variant ?? metadata.names); pages.forEach((page, i) => { const vname = `challenger-${i + 1}`; // label with custom name or default