@adobe/helix-rum-enhancer 2.7.6 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [2.8.0](https://github.com/adobe/helix-rum-enhancer/compare/v2.7.6...v2.8.0) (2024-05-24)
2
+
3
+
4
+ ### Features
5
+
6
+ * **checkpoint:** add consent checkpoint ([6bf3740](https://github.com/adobe/helix-rum-enhancer/commit/6bf3740cdb6e2ac12624f2e1a9c5d6539a3f124f))
7
+
1
8
  ## [2.7.6](https://github.com/adobe/helix-rum-enhancer/compare/v2.7.5...v2.7.6) (2024-05-21)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-rum-enhancer",
3
- "version": "2.7.6",
3
+ "version": "2.8.0",
4
4
  "description": "Helix RUM Enhancer",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/index.js CHANGED
@@ -86,6 +86,10 @@ function optedIn(checkpoint, data) {
86
86
  }
87
87
  // Gets configured collection from the config service for the current domain
88
88
  function getCollectionConfig() {
89
+ // eslint-disable-next-line max-len
90
+ if ([770, 1136].includes(Array.from(window.origin).map((a) => a.charCodeAt(0)).reduce((a, b) => a + b, 1) % 1371)) {
91
+ return DEFAULT_TRACKING_EVENTS.concat('consent');
92
+ }
89
93
  return DEFAULT_TRACKING_EVENTS;
90
94
  }
91
95
 
@@ -285,6 +289,41 @@ function addFormTracking(parent) {
285
289
  });
286
290
  }
287
291
 
292
+ function addCookieConsentTracking() {
293
+ const cmpCookie = document.cookie.split(';')
294
+ .map((c) => c.trim())
295
+ .find((cookie) => cookie.startsWith('OptanonAlertBoxClosed='));
296
+
297
+ if (cmpCookie) {
298
+ sampleRUM('consent', { source: 'onetrust', target: 'hidden' });
299
+ return;
300
+ }
301
+
302
+ let consentMutationObserver;
303
+ const trackShowConsent = () => {
304
+ if (document.querySelector('body > div#onetrust-consent-sdk')) {
305
+ sampleRUM('consent', { source: 'onetrust', target: 'show' });
306
+ if (consentMutationObserver) {
307
+ consentMutationObserver.disconnect();
308
+ }
309
+ return true;
310
+ }
311
+ return false;
312
+ };
313
+
314
+ if (!trackShowConsent()) {
315
+ // eslint-disable-next-line max-len
316
+ consentMutationObserver = window.MutationObserver ? new MutationObserver(trackShowConsent) : null;
317
+ if (consentMutationObserver) {
318
+ consentMutationObserver.observe(
319
+ document.body,
320
+ // eslint-disable-next-line object-curly-newline
321
+ { attributes: false, childList: true, subtree: false },
322
+ );
323
+ }
324
+ }
325
+ }
326
+
288
327
  const addObserver = (ck, fn, block) => getCollectionConfig().includes(ck) && fn(block);
289
328
  function mutationsCallback(mutations) {
290
329
  mutations.filter((m) => m.type === 'attributes' && m.attributeName === 'data-block-status')
@@ -310,6 +349,7 @@ function addTrackingFromConfig() {
310
349
  utm: () => addUTMParametersTracking(),
311
350
  viewblock: () => addViewBlockTracking(window.document.body),
312
351
  viewmedia: () => addViewMediaTracking(window.document.body),
352
+ consent: () => addCookieConsentTracking(),
313
353
  };
314
354
 
315
355
  getCollectionConfig().filter((ck) => trackingFunctions[ck])