Skip to content

Commit

Permalink
feat: support naming experiment variants in metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
FentPams committed Jun 25, 2024
1 parent 5739b00 commit c632802
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions plugins/experimentation/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,13 @@ async function getExperimentConfig(pluginOptions, metadata, overrides) {

const variantNames = [];
variantNames.push('control');
stringToArray(getMetadata("variants-name")).forEach((v) => {
if (variantNames.length <= pages.length) {
variantNames.push(v);
} else{
console.log(`Variant name "${v}" is ignored: Number of variants names is more than the number of variants`);
}
});

const variants = {};
variants.control = {
Expand All @@ -586,8 +593,13 @@ async function getExperimentConfig(pluginOptions, metadata, overrides) {
};

pages.forEach((page, i) => {
const vname = `challenger-${i + 1}`;
variantNames.push(vname);
const vname =
variantNames.length > i + 1
? variantNames[i + 1]
: `challenger-${i + 1}`;
if (variantNames.length <= i + 1) {
variantNames.push(vname);
}
variants[vname] = {
percentageSplit: `${splits[i].toFixed(4)}`,
pages: [page],
Expand Down

0 comments on commit c632802

Please sign in to comment.