@adobe/helix-rum-enhancer
Advanced tools
Comparing version 2.18.0 to 2.19.0
@@ -0,1 +1,8 @@ | ||
# [2.19.0](https://github.com/adobe/helix-rum-enhancer/compare/v2.18.0...v2.19.0) (2024-08-13) | ||
### Features | ||
* **onetrust:** enable on all domains ([6039f11](https://github.com/adobe/helix-rum-enhancer/commit/6039f1198f6484d623a3e42ffdd24807b6ed7c54)) | ||
# [2.18.0](https://github.com/adobe/helix-rum-enhancer/compare/v2.17.1...v2.18.0) (2024-08-08) | ||
@@ -2,0 +9,0 @@ |
@@ -12,3 +12,6 @@ /* | ||
*/ | ||
import { fflags } from './fflags.js'; | ||
export const KNOWN_PROPERTIES = ['weight', 'id', 'referer', 'checkpoint', 't', 'source', 'target', 'cwv', 'CLS', 'FID', 'LCP', 'INP', 'TTFB']; | ||
export const DEFAULT_TRACKING_EVENTS = ['click', 'cwv', 'form', 'enterleave', 'viewblock', 'viewmedia', 'loadresource', 'utm', 'paid', 'email']; | ||
export const DEFAULT_TRACKING_EVENTS = ['click', 'cwv', 'form', 'enterleave', 'viewblock', 'viewmedia', 'loadresource', 'utm', 'paid', 'email', 'consent']; | ||
fflags.enabled('example', () => DEFAULT_TRACKING_EVENTS.push('example')); |
@@ -19,3 +19,3 @@ /* | ||
disabled: (flag, callback) => !fflags.has(flag) && callback(), | ||
onetrust: [543, 770, 1136], | ||
example: [543, 770, 1136], | ||
}; |
@@ -15,5 +15,10 @@ /* | ||
import { KNOWN_PROPERTIES, DEFAULT_TRACKING_EVENTS } from './defaults.js'; | ||
import { fflags } from './fflags.js'; | ||
import { urlSanitizers } from './utils.js'; | ||
import { targetSelector, sourceSelector } from './dom.js'; | ||
import { | ||
addAdsParametersTracking, | ||
addCookieConsentTracking, | ||
addEmailParameterTracking, | ||
addUTMParametersTracking, | ||
} from './martech.js'; | ||
@@ -26,17 +31,5 @@ const { sampleRUM, queue, isSelected } = (window.hlx && window.hlx.rum) ? window.hlx.rum : {}; | ||
// eslint-disable-next-line no-unused-vars | ||
function optedIn(checkpoint, data) { | ||
// TODO: check config service to know if | ||
return true; | ||
} | ||
// Gets configured collection from the config service for the current domain | ||
function getCollectionConfig() { | ||
// eslint-disable-next-line max-len | ||
fflags.enabled('onetrust', () => DEFAULT_TRACKING_EVENTS.push('consent')); | ||
return DEFAULT_TRACKING_EVENTS; | ||
} | ||
function trackCheckpoint(checkpoint, data, t) { | ||
const { weight, id } = window.hlx.rum; | ||
if (optedIn(checkpoint, data) && isSelected) { | ||
if (isSelected) { | ||
const sendPing = (pdata = data) => { | ||
@@ -221,41 +214,2 @@ // eslint-disable-next-line object-curly-newline, max-len | ||
function addUTMParametersTracking() { | ||
const usp = new URLSearchParams(window.location.search); | ||
[...usp.entries()] | ||
.filter(([key]) => key.startsWith('utm_')) | ||
// exclude keys that may leak PII | ||
.filter(([key]) => key !== 'utm_id') | ||
.filter(([key]) => key !== 'utm_term') | ||
.forEach(([source, target]) => sampleRUM('utm', { source, target })); | ||
} | ||
function addAdsParametersTracking() { | ||
const networks = { | ||
google: /gclid|gclsrc|wbraid|gbraid/, | ||
doubleclick: /dclid/, | ||
microsoft: /msclkid/, | ||
facebook: /fb(cl|ad_|pxl_)id/, | ||
twitter: /tw(clid|src|term)/, | ||
linkedin: /li_fat_id/, | ||
pinterest: /epik/, | ||
tiktok: /ttclid/, | ||
}; | ||
const params = Array.from(new URLSearchParams(window.location.search).keys()); | ||
Object.entries(networks).forEach(([network, regex]) => { | ||
params.filter((param) => regex.test(param)).forEach((param) => sampleRUM('paid', { source: network, target: param })); | ||
}); | ||
} | ||
function addEmailParameterTracking() { | ||
const networks = { | ||
mailchimp: /mc_(c|e)id/, | ||
marketo: /mkt_tok/, | ||
}; | ||
const params = Array.from(new URLSearchParams(window.location.search).keys()); | ||
Object.entries(networks).forEach(([network, regex]) => { | ||
params.filter((param) => regex.test(param)).forEach((param) => sampleRUM('email', { source: network, target: param })); | ||
}); | ||
} | ||
function addFormTracking(parent) { | ||
@@ -269,38 +223,3 @@ activateBlocksMutationObserver(); | ||
function addCookieConsentTracking() { | ||
const cmpCookie = document.cookie.split(';') | ||
.map((c) => c.trim()) | ||
.find((cookie) => cookie.startsWith('OptanonAlertBoxClosed=')); | ||
if (cmpCookie) { | ||
sampleRUM('consent', { source: 'onetrust', target: 'hidden' }); | ||
return; | ||
} | ||
let consentMutationObserver; | ||
const trackShowConsent = () => { | ||
if (document.querySelector('body > div#onetrust-consent-sdk')) { | ||
sampleRUM('consent', { source: 'onetrust', target: 'show' }); | ||
if (consentMutationObserver) { | ||
consentMutationObserver.disconnect(); | ||
} | ||
return true; | ||
} | ||
return false; | ||
}; | ||
if (!trackShowConsent()) { | ||
// eslint-disable-next-line max-len | ||
consentMutationObserver = window.MutationObserver ? new MutationObserver(trackShowConsent) : null; | ||
if (consentMutationObserver) { | ||
consentMutationObserver.observe( | ||
document.body, | ||
// eslint-disable-next-line object-curly-newline | ||
{ attributes: false, childList: true, subtree: false }, | ||
); | ||
} | ||
} | ||
} | ||
const addObserver = (ck, fn, block) => getCollectionConfig().includes(ck) && fn(block); | ||
const addObserver = (ck, fn, block) => DEFAULT_TRACKING_EVENTS.includes(ck) && fn(block); | ||
function mutationsCallback(mutations) { | ||
@@ -327,11 +246,11 @@ mutations.filter((m) => m.type === 'attributes' && m.attributeName === 'data-block-status') | ||
loadresource: () => addLoadResourceTracking(), | ||
utm: () => addUTMParametersTracking(), | ||
utm: () => addUTMParametersTracking(sampleRUM), | ||
viewblock: () => addViewBlockTracking(window.document.body), | ||
viewmedia: () => addViewMediaTracking(window.document.body), | ||
consent: () => addCookieConsentTracking(), | ||
paid: () => addAdsParametersTracking(), | ||
email: () => addEmailParameterTracking(), | ||
consent: () => addCookieConsentTracking(sampleRUM), | ||
paid: () => addAdsParametersTracking(sampleRUM), | ||
email: () => addEmailParameterTracking(sampleRUM), | ||
}; | ||
getCollectionConfig().filter((ck) => trackingFunctions[ck]) | ||
DEFAULT_TRACKING_EVENTS.filter((ck) => trackingFunctions[ck]) | ||
.forEach((ck) => trackingFunctions[ck]()); | ||
@@ -338,0 +257,0 @@ } |
{ | ||
"name": "@adobe/helix-rum-enhancer", | ||
"version": "2.18.0", | ||
"version": "2.19.0", | ||
"description": "Helix RUM Enhancer", | ||
@@ -42,3 +42,3 @@ "main": "src/index.js", | ||
"@semantic-release/npm": "12.0.1", | ||
"@web/test-runner": "0.18.2", | ||
"@web/test-runner": "0.18.3", | ||
"@web/test-runner-commands": "0.9.0", | ||
@@ -54,5 +54,5 @@ "@web/test-runner-mocha": "0.9.0", | ||
"jsdoc-to-markdown": "8.0.3", | ||
"junit-report-builder": "4.0.1", | ||
"junit-report-builder": "5.0.0", | ||
"lint-staged": "15.2.8", | ||
"mocha": "10.7.0", | ||
"mocha": "10.7.3", | ||
"mocha-multi-reporters": "1.5.1", | ||
@@ -63,3 +63,3 @@ "rollup": "4.20.0", | ||
"semantic-release": "24.0.0", | ||
"web-vitals": "4.2.2" | ||
"web-vitals": "4.2.3" | ||
}, | ||
@@ -66,0 +66,0 @@ "lint-staged": { |
172
src/index.js
@@ -18,5 +18,2 @@ /* | ||
const KNOWN_PROPERTIES = ['weight', 'id', 'referer', 'checkpoint', 't', 'source', 'target', 'cwv', 'CLS', 'FID', 'LCP', 'INP', 'TTFB']; | ||
const DEFAULT_TRACKING_EVENTS = ['click', 'cwv', 'form', 'enterleave', 'viewblock', 'viewmedia', 'loadresource', 'utm', 'paid', 'email']; | ||
const fflags = { | ||
@@ -29,5 +26,9 @@ has: (flag) => !!window.origin.match(/localhost/) | ||
disabled: (flag, callback) => !fflags.has(flag) && callback(), | ||
onetrust: [543, 770, 1136], | ||
example: [543, 770, 1136], | ||
}; | ||
const KNOWN_PROPERTIES = ['weight', 'id', 'referer', 'checkpoint', 't', 'source', 'target', 'cwv', 'CLS', 'FID', 'LCP', 'INP', 'TTFB']; | ||
const DEFAULT_TRACKING_EVENTS = ['click', 'cwv', 'form', 'enterleave', 'viewblock', 'viewmedia', 'loadresource', 'utm', 'paid', 'email', 'consent']; | ||
fflags.enabled('example', () => DEFAULT_TRACKING_EVENTS.push('example')); | ||
const urlSanitizers = { | ||
@@ -128,2 +129,73 @@ /** | ||
function addCookieConsentTracking(sampleRUM) { | ||
const cmpCookie = document.cookie.split(';') | ||
.map((c) => c.trim()) | ||
.find((cookie) => cookie.startsWith('OptanonAlertBoxClosed=')); | ||
if (cmpCookie) { | ||
sampleRUM('consent', { source: 'onetrust', target: 'hidden' }); | ||
return; | ||
} | ||
let consentMutationObserver; | ||
const trackShowConsent = () => { | ||
if (document.querySelector('body > div#onetrust-consent-sdk')) { | ||
sampleRUM('consent', { source: 'onetrust', target: 'show' }); | ||
if (consentMutationObserver) { | ||
consentMutationObserver.disconnect(); | ||
} | ||
return true; | ||
} | ||
return false; | ||
}; | ||
if (!trackShowConsent()) { | ||
// eslint-disable-next-line max-len | ||
consentMutationObserver = window.MutationObserver ? new MutationObserver(trackShowConsent) : null; | ||
if (consentMutationObserver) { | ||
consentMutationObserver.observe( | ||
document.body, | ||
// eslint-disable-next-line object-curly-newline | ||
{ attributes: false, childList: true, subtree: false }, | ||
); | ||
} | ||
} | ||
} | ||
function addUTMParametersTracking(sampleRUM) { | ||
const usp = new URLSearchParams(window.location.search); | ||
[...usp.entries()] | ||
.filter(([key]) => key.startsWith('utm_')) | ||
// exclude keys that may leak PII | ||
.filter(([key]) => key !== 'utm_id') | ||
.filter(([key]) => key !== 'utm_term') | ||
.forEach(([source, target]) => sampleRUM('utm', { source, target })); | ||
} | ||
function addAdsParametersTracking(sampleRUM) { | ||
const networks = { | ||
google: /gclid|gclsrc|wbraid|gbraid/, | ||
doubleclick: /dclid/, | ||
microsoft: /msclkid/, | ||
facebook: /fb(cl|ad_|pxl_)id/, | ||
twitter: /tw(clid|src|term)/, | ||
linkedin: /li_fat_id/, | ||
pinterest: /epik/, | ||
tiktok: /ttclid/, | ||
}; | ||
const params = Array.from(new URLSearchParams(window.location.search).keys()); | ||
Object.entries(networks).forEach(([network, regex]) => { | ||
params.filter((param) => regex.test(param)).forEach((param) => sampleRUM('paid', { source: network, target: param })); | ||
}); | ||
} | ||
function addEmailParameterTracking(sampleRUM) { | ||
const networks = { | ||
mailchimp: /mc_(c|e)id/, | ||
marketo: /mkt_tok/, | ||
}; | ||
const params = Array.from(new URLSearchParams(window.location.search).keys()); | ||
Object.entries(networks).forEach(([network, regex]) => { | ||
params.filter((param) => regex.test(param)).forEach((param) => sampleRUM('email', { source: network, target: param })); | ||
}); | ||
} | ||
const { sampleRUM, queue, isSelected } = (window.hlx && window.hlx.rum) ? window.hlx.rum : {}; | ||
@@ -134,8 +206,2 @@ | ||
const mutationObserver = window.MutationObserver ? new MutationObserver(mutationsCallback) : null; | ||
// Gets configured collection from the config service for the current domain | ||
function getCollectionConfig() { | ||
// eslint-disable-next-line max-len | ||
fflags.enabled('onetrust', () => DEFAULT_TRACKING_EVENTS.push('consent')); | ||
return DEFAULT_TRACKING_EVENTS; | ||
} | ||
@@ -320,41 +386,2 @@ function trackCheckpoint(checkpoint, data, t) { | ||
function addUTMParametersTracking() { | ||
const usp = new URLSearchParams(window.location.search); | ||
[...usp.entries()] | ||
.filter(([key]) => key.startsWith('utm_')) | ||
// exclude keys that may leak PII | ||
.filter(([key]) => key !== 'utm_id') | ||
.filter(([key]) => key !== 'utm_term') | ||
.forEach(([source, target]) => sampleRUM('utm', { source, target })); | ||
} | ||
function addAdsParametersTracking() { | ||
const networks = { | ||
google: /gclid|gclsrc|wbraid|gbraid/, | ||
doubleclick: /dclid/, | ||
microsoft: /msclkid/, | ||
facebook: /fb(cl|ad_|pxl_)id/, | ||
twitter: /tw(clid|src|term)/, | ||
linkedin: /li_fat_id/, | ||
pinterest: /epik/, | ||
tiktok: /ttclid/, | ||
}; | ||
const params = Array.from(new URLSearchParams(window.location.search).keys()); | ||
Object.entries(networks).forEach(([network, regex]) => { | ||
params.filter((param) => regex.test(param)).forEach((param) => sampleRUM('paid', { source: network, target: param })); | ||
}); | ||
} | ||
function addEmailParameterTracking() { | ||
const networks = { | ||
mailchimp: /mc_(c|e)id/, | ||
marketo: /mkt_tok/, | ||
}; | ||
const params = Array.from(new URLSearchParams(window.location.search).keys()); | ||
Object.entries(networks).forEach(([network, regex]) => { | ||
params.filter((param) => regex.test(param)).forEach((param) => sampleRUM('email', { source: network, target: param })); | ||
}); | ||
} | ||
function addFormTracking(parent) { | ||
@@ -368,38 +395,3 @@ activateBlocksMutationObserver(); | ||
function addCookieConsentTracking() { | ||
const cmpCookie = document.cookie.split(';') | ||
.map((c) => c.trim()) | ||
.find((cookie) => cookie.startsWith('OptanonAlertBoxClosed=')); | ||
if (cmpCookie) { | ||
sampleRUM('consent', { source: 'onetrust', target: 'hidden' }); | ||
return; | ||
} | ||
let consentMutationObserver; | ||
const trackShowConsent = () => { | ||
if (document.querySelector('body > div#onetrust-consent-sdk')) { | ||
sampleRUM('consent', { source: 'onetrust', target: 'show' }); | ||
if (consentMutationObserver) { | ||
consentMutationObserver.disconnect(); | ||
} | ||
return true; | ||
} | ||
return false; | ||
}; | ||
if (!trackShowConsent()) { | ||
// eslint-disable-next-line max-len | ||
consentMutationObserver = window.MutationObserver ? new MutationObserver(trackShowConsent) : null; | ||
if (consentMutationObserver) { | ||
consentMutationObserver.observe( | ||
document.body, | ||
// eslint-disable-next-line object-curly-newline | ||
{ attributes: false, childList: true, subtree: false }, | ||
); | ||
} | ||
} | ||
} | ||
const addObserver = (ck, fn, block) => getCollectionConfig().includes(ck) && fn(block); | ||
const addObserver = (ck, fn, block) => DEFAULT_TRACKING_EVENTS.includes(ck) && fn(block); | ||
function mutationsCallback(mutations) { | ||
@@ -426,11 +418,11 @@ mutations.filter((m) => m.type === 'attributes' && m.attributeName === 'data-block-status') | ||
loadresource: () => addLoadResourceTracking(), | ||
utm: () => addUTMParametersTracking(), | ||
utm: () => addUTMParametersTracking(sampleRUM), | ||
viewblock: () => addViewBlockTracking(window.document.body), | ||
viewmedia: () => addViewMediaTracking(window.document.body), | ||
consent: () => addCookieConsentTracking(), | ||
paid: () => addAdsParametersTracking(), | ||
email: () => addEmailParameterTracking(), | ||
consent: () => addCookieConsentTracking(sampleRUM), | ||
paid: () => addAdsParametersTracking(sampleRUM), | ||
email: () => addEmailParameterTracking(sampleRUM), | ||
}; | ||
getCollectionConfig().filter((ck) => trackingFunctions[ck]) | ||
DEFAULT_TRACKING_EVENTS.filter((ck) => trackingFunctions[ck]) | ||
.forEach((ck) => trackingFunctions[ck]()); | ||
@@ -437,0 +429,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
85987
21
1055