Skip to content

Commit

Permalink
fix: fetch campigns and audiences in metadata property for page-level…
Browse files Browse the repository at this point in the history
… experiment
  • Loading branch information
FentPams committed Jun 23, 2024
1 parent 30f172d commit cdecca4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions plugins/experimentation/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,18 @@ export function getMetadata(name) {
*/
export function getAllMetadata(scope) {
const value = getMetadata(scope);
return [...document.head.querySelectorAll(`meta[name^="${scope}-"]`)]
.reduce((res, meta) => {
const key = toCamelCase(meta.name.substring(scope.length + 1));
res[key] = meta.getAttribute('content');
return res;
}, value ? { value } : {});
const metaTags = document.head.querySelectorAll(`meta[name^="${scope}-"], meta[property^="${scope}:-"]`);

return [...metaTags].reduce((res, meta) => {
const key = meta.getAttribute('name')
? meta.getAttribute('name').substring(scope.length + 1)
: meta.getAttribute('property').substring(scope.length + 2);

const camelCaseKey = toCamelCase(key);
res[camelCaseKey] = meta.getAttribute('content');

return res;
}, value ? { value } : {});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ window.hlx.plugins.add('rum-conversion', {
});

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

0 comments on commit cdecca4

Please sign in to comment.