Skip to content

Commit

Permalink
feat: support customized variant name for fragment variants (#36)
Browse files Browse the repository at this point in the history
<!--- Provide a general summary of your changes in the Title above -->

## Description
Leverage"Variant" entry in manifest to support variant name
customization for fragment experimentation.

<!--- Describe your changes in detail -->
![Untitled
(1)](https://github.com/user-attachments/assets/74c8f053-c2c9-4c3d-9009-558b0e98e4ad)
## Related Issue


## Related Issue

<!--- This project only accepts pull requests related to open issues -->
<!--- If suggesting a new feature or change, please discuss it in an
issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps
to reproduce -->
<!--- Please link to the issue here: -->

## Motivation and Context

<!--- Why is this change required? What problem does it solve? -->

## How Has This Been Tested?

<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->

## Screenshots (if appropriate):

## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)

## Checklist:

<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->

- [x] I have signed the [Adobe Open Source
CLA](https://opensource.adobe.com/cla.html).
- [x] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have read the **CONTRIBUTING** document.
- [ ] I have added tests to cover my changes.
- [x] All new and existing tests passed.

---------

Co-authored-by: Julien Ramboz <[email protected]>
  • Loading branch information
FentPams and ramboz authored Jul 29, 2024
1 parent c9ff2c0 commit 9db8662
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ async function getExperimentConfig(pluginOptions, metadata, overrides) {
};

// get the custom labels for the variants names
const labelNames = stringToArray(metadata.names);
const labelNames = stringToArray(metadata.name);
pages.forEach((page, i) => {
const vname = `challenger-${i + 1}`;
// label with custom name or default
Expand All @@ -622,7 +622,7 @@ async function getExperimentConfig(pluginOptions, metadata, overrides) {

const config = {
id,
label: metadata.name || `Experiment ${metadata.value || metadata.experiment}`,
label: `Experiment ${metadata.value || metadata.experiment}`,
status: metadata.status || 'active',
audiences,
endDate,
Expand Down Expand Up @@ -671,9 +671,9 @@ async function getExperimentConfig(pluginOptions, metadata, overrides) {
*/
function parseExperimentManifest(entries) {
return Object.values(Object.groupBy(
entries.map((e) => depluralizeProps(e, ['experiment', 'variant', 'split'])),
entries.map((e) => depluralizeProps(e, ['experiment', 'variant', 'split', 'name'])),
({ experiment }) => experiment,
)).map(aggregateEntries('experiment', ['split', 'url', 'variant']));
)).map(aggregateEntries('experiment', ['split', 'url', 'variant', 'name']));
}

function getUrlFromExperimentConfig(config) {
Expand Down
1 change: 1 addition & 0 deletions tests/experiments.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ test.describe('Fragment-level experiments', () => {
'challenger-1': expect.objectContaining({ percentageSplit: '0.3333' }),
'challenger-2': expect.objectContaining({ percentageSplit: '0.3333' }),
},
label: expect.stringMatching(/Experiment Baz/),
}),
servedExperience: expect.stringMatching(/\/tests\/fixtures\/experiments\/(fragment|section)-level/),
}),
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/experiments/fragments--alt.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
"Pages": "/tests/fixtures/experiments/fragment-level--alt",
"Experiments": "Baz",
"Variants": "challenger-1",
"Names": "C1",
"Selectors": ".fragment",
"Urls": "/tests/fixtures/experiments/section-level-v1"
},
{
"Pages": "/tests/fixtures/experiments/fragment-level--alt",
"Experiments": "Baz",
"Variants": "challenger-2",
"Names": "C2",
"Selectors": ".fragment",
"Urls": "/tests/fixtures/experiments/section-level-v2"
}
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/experiments/fragments.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,31 @@
"Page": "/tests/fixtures/experiments/fragment-level",
"Experiment": "Baz",
"Variant": "challenger-1",
"Names": "C1",
"Selector": ".fragment",
"Url": "/tests/fixtures/experiments/section-level-v1"
},
{
"Page": "/tests/fixtures/experiments/fragment-level",
"Experiment": "Baz",
"Variant": "challenger-2",
"Names": "C2",
"Selector": ".fragment",
"Url": "/tests/fixtures/experiments/section-level-v2"
},
{
"Page": "/tests/fixtures/experiments/fragment-level--async",
"Experiment": "Baz",
"Variant": "challenger-1",
"Names": "C1",
"Selector": ".fragment",
"Url": "/tests/fixtures/experiments/section-level-v1"
},
{
"Page": "/tests/fixtures/experiments/fragment-level--async",
"Experiment": "Baz",
"Variant": "challenger-2",
"Names": "C2",
"Selector": ".fragment",
"Url": "/tests/fixtures/experiments/section-level-v2"
}
Expand Down

0 comments on commit 9db8662

Please sign in to comment.