Skip to content

Commit

Permalink
fix: switch to default page in campaigns has issue on decoration, and…
Browse files Browse the repository at this point in the history
… audiences wrongly redirected.
  • Loading branch information
FentPams committed Jun 24, 2024
1 parent cdecca4 commit d284d3d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions plugins/experimentation/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ async function applyAllModifications(
}
}));

// Fragment-level modifications
if (pageMetadata.manifest) {
let entries = await getManifestEntriesForCurrentPage(pageMetadata.manifest);
if (entries) {
Expand Down
6 changes: 5 additions & 1 deletion plugins/experimentation/src/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,11 @@ async function decorateCampaignPills(container, options) {

function createAudience(audience, isSelected, options) {
const url = new URL(window.location.href);
url.searchParams.set(options.audiencesQueryParameter, audience);
if (audience !== 'default') {
url.searchParams.set(options.audiencesQueryParameter, audience);
} else {
url.searchParams.delete(options.audiencesQueryParameter);
}

return {
label: `<code>${audience}</code>`,
Expand Down
5 changes: 3 additions & 2 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ window.hlx.plugins.add('rum-conversion', {
});

window.hlx.plugins.add('experimentation', {
condition: () => document.head.querySelector('[name^="experiment"],[property^="campaign:-"],[property^="audience:-"]')
condition: () => document.head.querySelector('[name^="experiment"],[name^="campaign-"],[name^="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))
,

Check failure on line 49 in scripts/scripts.js

View workflow job for this annotation

GitHub Actions / build

Expected indentation of 2 spaces but found 4

Check failure on line 49 in scripts/scripts.js

View workflow job for this annotation

GitHub Actions / build

Bad line breaking before and after ','
Expand Down Expand Up @@ -280,7 +281,7 @@ async function loadPage() {
// Properly decorate fragments that were pulled in
document.addEventListener('aem:experimentation', (ev) => {
// Do not redecorate the default content
if (ev.detail.variant === 'control') {
if (ev.detail.variant === 'control' || ev.detail?.campaign === 'default' || ev.detail?.audience === 'default') {
return;
}
// Rebuild the autoblock as needed
Expand Down

0 comments on commit d284d3d

Please sign in to comment.