Skip to content

Commit

Permalink
fix(lib): update scripts/aem.js to [email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
semantic-release-bot committed Oct 17, 2024
1 parent 1a18605 commit 4f41f9c
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions scripts/aem.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ function sampleRUM(checkpoint, data) {
window.hlx = window.hlx || {};
sampleRUM.enhance = () => {};
if (!window.hlx.rum) {
const param = new URLSearchParams(window.location.search).get('rum');
const weight = (window.SAMPLE_PAGEVIEWS_AT_RATE === 'high' && 10)
|| (window.SAMPLE_PAGEVIEWS_AT_RATE === 'low' && 1000)
|| (new URLSearchParams(window.location.search).get('rum') === 'on' && 1)
|| (param === 'on' && 1)
|| 100;
const id = Math.random().toString(36).slice(-4);
const isSelected = Math.random() * weight < 1;
const isSelected = param !== 'off' && Math.random() * weight < 1;
// eslint-disable-next-line object-curly-newline, max-len
window.hlx.rum = {
weight,
Expand Down Expand Up @@ -80,7 +81,13 @@ function sampleRUM(checkpoint, data) {
t: time,
...pingData,
});
const { href: url, origin } = new URL(`.rum/${weight}`, sampleRUM.collectBaseURL);
const urlParams = window.RUM_PARAMS
? `?${new URLSearchParams(window.RUM_PARAMS).toString()}`
: '';
const { href: url, origin } = new URL(
`.rum/${weight}${urlParams}`,
sampleRUM.collectBaseURL,
);
const body = origin === window.location.origin
? new Blob([rumData], { type: 'application/json' })
: rumData;
Expand All @@ -91,6 +98,9 @@ function sampleRUM(checkpoint, data) {
sampleRUM.sendPing('top', timeShift());

sampleRUM.enhance = () => {
// only enhance once
if (document.querySelector('script[src*="rum-enhancer"]')) return;

const script = document.createElement('script');
script.src = new URL(
'.rum/@adobe/helix-rum-enhancer@^2/src/index.js',
Expand All @@ -108,7 +118,7 @@ function sampleRUM(checkpoint, data) {
}
document.dispatchEvent(new CustomEvent('rum', { detail: { checkpoint, data } }));
} catch (error) {
// something went wrong
// something went awry
}
}

Expand Down Expand Up @@ -684,6 +694,9 @@ async function loadSections(element) {
for (let i = 0; i < sections.length; i += 1) {
// eslint-disable-next-line no-await-in-loop
await loadSection(sections[i]);
if (i === 0 && sampleRUM.enhance) {
sampleRUM.enhance();
}
}
}

Expand Down

0 comments on commit 4f41f9c

Please sign in to comment.