@adobe/helix-rum-enhancer 2.7.5 → 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,17 @@
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
+
8
+ ## [2.7.6](https://github.com/adobe/helix-rum-enhancer/compare/v2.7.5...v2.7.6) (2024-05-21)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * no type leads to empty checkpoint ([#167](https://github.com/adobe/helix-rum-enhancer/issues/167)) ([c1d41ad](https://github.com/adobe/helix-rum-enhancer/commit/c1d41ad084fd9e0e71b3bea7aff54e543ee45953))
14
+
1
15
  ## [2.7.5](https://github.com/adobe/helix-rum-enhancer/compare/v2.7.4...v2.7.5) (2024-05-14)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-rum-enhancer",
3
- "version": "2.7.5",
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
 
@@ -161,7 +165,7 @@ function addEnterLeaveTracking() {
161
165
  // reload: same page, navigate: same origin, enter: everything else
162
166
  if (type === 'reload' || source === window.location.href) {
163
167
  sampleRUM('reload', payload);
164
- } else if (type !== 'navigate') {
168
+ } else if (type && type !== 'navigate') {
165
169
  sampleRUM(type, payload); // back, forward, prerender, etc.
166
170
  } else if (source && window.location.origin === new URL(source).origin) {
167
171
  sampleRUM('navigate', payload); // internal navigation
@@ -169,7 +173,6 @@ function addEnterLeaveTracking() {
169
173
  sampleRUM('enter', payload); // enter site
170
174
  }
171
175
  };
172
- navigate(document.referrer);
173
176
 
174
177
  new PerformanceObserver((list) => list
175
178
  .getEntries().map((entry) => navigate(document.referrer, entry.type)))
@@ -286,6 +289,41 @@ function addFormTracking(parent) {
286
289
  });
287
290
  }
288
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
+
289
327
  const addObserver = (ck, fn, block) => getCollectionConfig().includes(ck) && fn(block);
290
328
  function mutationsCallback(mutations) {
291
329
  mutations.filter((m) => m.type === 'attributes' && m.attributeName === 'data-block-status')
@@ -311,6 +349,7 @@ function addTrackingFromConfig() {
311
349
  utm: () => addUTMParametersTracking(),
312
350
  viewblock: () => addViewBlockTracking(window.document.body),
313
351
  viewmedia: () => addViewMediaTracking(window.document.body),
352
+ consent: () => addCookieConsentTracking(),
314
353
  };
315
354
 
316
355
  getCollectionConfig().filter((ck) => trackingFunctions[ck])