Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions dist/aem.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ function sampleRUM(checkpoint, data) {
on: 1,
off: 0,
high: 10,
medium: 100,
low: 1000,
}[rate];
const weight = rateValue !== undefined ? rateValue : 100;
Expand Down Expand Up @@ -94,18 +93,14 @@ function sampleRUM(checkpoint, data) {
sampleRUM.baseURL = sampleRUM.baseURL || new URL(window.RUM_BASE || '/', new URL('https://ot.aem.live'));
sampleRUM.collectBaseURL = sampleRUM.collectBaseURL || sampleRUM.baseURL;
sampleRUM.sendPing = (ck, time, pingData = {}) => {
const uaExtra = navigator.webdriver && !navigator.userAgent.includes('+http')
? { ua: `${navigator.userAgent} +http://navigator.webdriver` }
: {};
// eslint-disable-next-line max-len, object-curly-newline
const rumData = JSON.stringify({
weight,
id,
referer: window.location.origin + window.location.pathname,
referer: window.location.href,
checkpoint: ck,
t: time,
...pingData,
...uaExtra,
});
const urlParams = window.RUM_PARAMS
? new URLSearchParams(window.RUM_PARAMS).toString() || ''
Expand All @@ -125,9 +120,7 @@ function sampleRUM(checkpoint, data) {

sampleRUM.enhance = () => {
// only enhance once
if (document.querySelector('script[src*="rum-enhancer"]')) {
return;
}
if (document.querySelector('script[src*="rum-enhancer"]')) return;
const { enhancerVersion, enhancerHash } = sampleRUM.enhancerContext || {};
const script = document.createElement('script');
if (enhancerHash) {
Expand Down Expand Up @@ -157,22 +150,21 @@ function sampleRUM(checkpoint, data) {
/**
* Setup block utils.
*/
function setup() {
function setup(importUrl = import.meta.url) {
window.hlx = window.hlx || {};
window.hlx.RUM_MASK_URL = 'full';
window.hlx.RUM_MANUAL_ENHANCE = true;
window.hlx.lighthouse = new URLSearchParams(window.location.search).get('lighthouse') === 'on';

[window.hlx.codeBasePath] = new URL(import.meta.url).pathname.split('/scripts/');
[window.hlx.codeBasePath] = new URL(importUrl).pathname.split('/scripts/');
}

/**
* Auto initialization.
*/

function init() {
setup();
sampleRUM.collectBaseURL = window.origin;
sampleRUM.collectBaseURL = new URL(`${window.hlx.codeBasePath}/`, window.origin);
sampleRUM();
}

Expand Down
2 changes: 1 addition & 1 deletion test/setup/setup.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

it('init - sets sampleRUM.collectBaseURL to include the codeBasePath', () => {
init();
expect(sampleRUM.collectBaseURL.href).to.be.equal(`${window.origin}/some/path/`);
expect(sampleRUM.collectBaseURL.href).to.be.equal(`${window.origin}/src/setup.js/`);
});
});
</script>
Expand Down