diff --git a/src/index.js b/src/index.js index fcac6ce..7125833 100644 --- a/src/index.js +++ b/src/index.js @@ -110,8 +110,13 @@ function trackCheckpoint(checkpoint, data, t) { const sendPing = (pdata = data) => { // eslint-disable-next-line object-curly-newline, max-len const body = JSON.stringify({ weight, id, sanitizeURL: urlSanitizers[window.hlx.RUM_MASK_URL || 'path'], checkpoint, t, ...data }, KNOWN_PROPERTIES); - const url = new URL(`.rum/${weight}`, sampleRUM.collectBaseURL || sampleRUM.baseURL).href; - navigator.sendBeacon(url, body); + const { href: url, origin} = new URL(`.rum/${weight}`, sampleRUM.collectBaseURL || sampleRUM.baseURL); + if (window.location.origin === origin) { + const headers = { type: 'application/json' }; + navigator.sendBeacon(url, new Blob([body], headers)); + } else { + navigator.sendBeacon(url, body); + } // eslint-disable-next-line no-console console.debug(`ping:${checkpoint}`, pdata); };