@adobe/helix-rum-enhancer 2.19.0 → 2.19.2

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.19.2](https://github.com/adobe/helix-rum-enhancer/compare/v2.19.1...v2.19.2) (2024-08-15)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * remove intersection threshold ([#258](https://github.com/adobe/helix-rum-enhancer/issues/258)) ([8805b49](https://github.com/adobe/helix-rum-enhancer/commit/8805b49a052bbc9a659ee2485ada8a9db5a13e40))
7
+
8
+ ## [2.19.1](https://github.com/adobe/helix-rum-enhancer/compare/v2.19.0...v2.19.1) (2024-08-15)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **navigation:** remove `leave` checkpoint ([95503de](https://github.com/adobe/helix-rum-enhancer/commit/95503de3dfd83534a8692d6fa3a1af96734e65aa)), closes [/github.com/adobe/helix-rum-enhancer/pull/257#discussion_r1718152824](https://github.com//github.com/adobe/helix-rum-enhancer/pull/257/issues/discussion_r1718152824)
14
+
1
15
  # [2.19.0](https://github.com/adobe/helix-rum-enhancer/compare/v2.18.0...v2.19.0) (2024-08-13)
2
16
 
3
17
 
package/README.md CHANGED
@@ -22,7 +22,6 @@ It will add following new checkpoints:
22
22
  - `viewmedia`: An image or video hosted by Helix Media Bus has been scrolled into the viewport
23
23
  - `reload`, `navigate`, `enter`: depending on how the current page was accessed
24
24
  - `formsubmit`: when a form is submitted
25
- - `leave`: when the user leaves the page
26
25
 
27
26
  ## Development
28
27
 
@@ -12,5 +12,5 @@
12
12
  import { fflags } from './fflags.js';
13
13
 
14
14
  export const KNOWN_PROPERTIES = ['weight', 'id', 'referer', 'checkpoint', 't', 'source', 'target', 'cwv', 'CLS', 'FID', 'LCP', 'INP', 'TTFB'];
15
- export const DEFAULT_TRACKING_EVENTS = ['click', 'cwv', 'form', 'enterleave', 'viewblock', 'viewmedia', 'loadresource', 'utm', 'paid', 'email', 'consent'];
15
+ export const DEFAULT_TRACKING_EVENTS = ['click', 'cwv', 'form', 'viewblock', 'viewmedia', 'loadresource', 'utm', 'paid', 'email', 'consent'];
16
16
  fflags.enabled('example', () => DEFAULT_TRACKING_EVENTS.push('example'));
package/modules/fflags.js CHANGED
@@ -10,11 +10,13 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
  export const fflags = {
13
- has: (flag) => !!window.origin.match(/localhost/)
14
- || fflags[flag].indexOf(Array.from(window.origin)
15
- .map((a) => a.charCodeAt(0))
16
- .reduce((a, b) => a + b, 1) % 1371) !== -1,
13
+ has: (flag) => fflags[flag].indexOf(Array.from(window.origin)
14
+ .map((a) => a.charCodeAt(0))
15
+ .reduce((a, b) => a + b, 1) % 1371) !== -1
16
+ || !!window.origin.match(/localhost/),
17
17
  enabled: (flag, callback) => fflags.has(flag) && callback(),
18
+ /* c8 ignore next */
18
19
  disabled: (flag, callback) => !fflags.has(flag) && callback(),
20
+ eagercwv: [683],
19
21
  example: [543, 770, 1136],
20
22
  };
package/modules/index.js CHANGED
@@ -20,12 +20,15 @@ import {
20
20
  addEmailParameterTracking,
21
21
  addUTMParametersTracking,
22
22
  } from './martech.js';
23
+ import { fflags } from './fflags.js';
23
24
 
24
- const { sampleRUM, queue, isSelected } = (window.hlx && window.hlx.rum) ? window.hlx.rum : {};
25
+ const { sampleRUM, queue, isSelected } = (window.hlx && window.hlx.rum) ? window.hlx.rum
26
+ /* c8 ignore next */ : {};
25
27
 
26
28
  const formSubmitListener = (e) => sampleRUM('formsubmit', { target: targetSelector(e.target), source: sourceSelector(e.target) });
27
29
  // eslint-disable-next-line no-use-before-define
28
- const mutationObserver = window.MutationObserver ? new MutationObserver(mutationsCallback) : null;
30
+ const mutationObserver = window.MutationObserver ? new MutationObserver(mutationsCallback)
31
+ /* c8 ignore next */ : null;
29
32
 
30
33
  function trackCheckpoint(checkpoint, data, t) {
31
34
  const { weight, id } = window.hlx.rum;
@@ -77,7 +80,6 @@ function addCWVTracking() {
77
80
  sampleRUM('cwv', data);
78
81
  };
79
82
 
80
- const featureToggle = () => window.location.hostname === 'blog.adobe.com';
81
83
  const isEager = (metric) => ['CLS', 'LCP'].includes(metric);
82
84
 
83
85
  // When loading `web-vitals` using a classic script, all the public
@@ -85,7 +87,10 @@ function addCWVTracking() {
85
87
  ['FID', 'INP', 'TTFB', 'CLS', 'LCP'].forEach((metric) => {
86
88
  const metricFn = window.webVitals[`on${metric}`];
87
89
  if (typeof metricFn === 'function') {
88
- const opts = isEager(metric) ? { reportAllChanges: featureToggle() } : undefined;
90
+ let opts = {};
91
+ fflags.enabled('eagercwv', () => {
92
+ opts = { reportAllChanges: isEager(metric) };
93
+ });
89
94
  metricFn(storeCWV, opts);
90
95
  }
91
96
  });
@@ -98,7 +103,7 @@ function addCWVTracking() {
98
103
  }, 2000); // wait for delayed
99
104
  }
100
105
 
101
- function addEnterLeaveTracking() {
106
+ function addNavigationTracking() {
102
107
  // enter checkpoint when referrer is not the current page url
103
108
  const navigate = (source, type) => {
104
109
  const payload = { source, target: document.visibilityState };
@@ -115,22 +120,8 @@ function addEnterLeaveTracking() {
115
120
  };
116
121
 
117
122
  new PerformanceObserver((list) => list
118
- .getEntries().map((entry) => navigate(document.referrer, entry.type)))
123
+ .getEntries().map((entry) => navigate(window.hlx.referrer || document.referrer, entry.type)))
119
124
  .observe({ type: 'navigation', buffered: true });
120
-
121
- const leave = ((event) => {
122
- try {
123
- if (leave.left || (event.type === 'visibilitychange' && document.visibilityState !== 'hidden')) {
124
- return;
125
- }
126
- leave.left = true;
127
- sampleRUM('leave');
128
- } catch (error) {
129
- // something went wrong
130
- }
131
- });
132
- window.addEventListener('visibilitychange', ((event) => leave(event)));
133
- window.addEventListener('pagehide', ((event) => leave(event)));
134
125
  }
135
126
 
136
127
  function addLoadResourceTracking() {
@@ -169,9 +160,8 @@ function activateBlocksMutationObserver() {
169
160
  }
170
161
 
171
162
  function getIntersectionObsever(checkpoint) {
172
- if (!window.IntersectionObserver) {
173
- return null;
174
- }
163
+ /* c8 ignore next */
164
+ if (!window.IntersectionObserver) return null;
175
165
  activateBlocksMutationObserver();
176
166
  const observer = new IntersectionObserver((entries) => {
177
167
  try {
@@ -187,7 +177,7 @@ function getIntersectionObsever(checkpoint) {
187
177
  } catch (error) {
188
178
  // something went wrong
189
179
  }
190
- }, { threshold: 0.25 });
180
+ });
191
181
  return observer;
192
182
  }
193
183
  function addViewBlockTracking(element) {
@@ -229,26 +219,19 @@ function mutationsCallback(mutations) {
229
219
  }
230
220
 
231
221
  function addTrackingFromConfig() {
232
- const trackingFunctions = {
233
- click: () => {
234
- document.addEventListener('click', (event) => {
235
- sampleRUM('click', { target: targetSelector(event.target), source: sourceSelector(event.target) });
236
- });
237
- },
238
- cwv: () => addCWVTracking(),
239
- form: () => addFormTracking(window.document.body),
240
- enterleave: () => addEnterLeaveTracking(),
241
- loadresource: () => addLoadResourceTracking(),
242
- utm: () => addUTMParametersTracking(sampleRUM),
243
- viewblock: () => addViewBlockTracking(window.document.body),
244
- viewmedia: () => addViewMediaTracking(window.document.body),
245
- consent: () => addCookieConsentTracking(sampleRUM),
246
- paid: () => addAdsParametersTracking(sampleRUM),
247
- email: () => addEmailParameterTracking(sampleRUM),
248
- };
249
-
250
- DEFAULT_TRACKING_EVENTS.filter((ck) => trackingFunctions[ck])
251
- .forEach((ck) => trackingFunctions[ck]());
222
+ document.addEventListener('click', (event) => {
223
+ sampleRUM('click', { target: targetSelector(event.target), source: sourceSelector(event.target) });
224
+ });
225
+ addCWVTracking();
226
+ addFormTracking(window.document.body);
227
+ addNavigationTracking();
228
+ addLoadResourceTracking();
229
+ addUTMParametersTracking(sampleRUM);
230
+ addViewBlockTracking(window.document.body);
231
+ addViewMediaTracking(window.document.body);
232
+ addCookieConsentTracking(sampleRUM);
233
+ addAdsParametersTracking(sampleRUM);
234
+ addEmailParameterTracking(sampleRUM);
252
235
  }
253
236
 
254
237
  function initEnhancer() {
@@ -33,7 +33,9 @@ export function addCookieConsentTracking(sampleRUM) {
33
33
 
34
34
  if (!trackShowConsent()) {
35
35
  // eslint-disable-next-line max-len
36
- consentMutationObserver = window.MutationObserver ? new MutationObserver(trackShowConsent) : null;
36
+ consentMutationObserver = window.MutationObserver
37
+ ? new MutationObserver(trackShowConsent)
38
+ : /* c8 ignore next */ null;
37
39
  if (consentMutationObserver) {
38
40
  consentMutationObserver.observe(
39
41
  document.body,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-rum-enhancer",
3
- "version": "2.19.0",
3
+ "version": "2.19.2",
4
4
  "description": "Helix RUM Enhancer",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -8,7 +8,7 @@
8
8
  "setup-playwright": "npx playwright install --with-deps chromium firefox webkit",
9
9
  "test": "npm run build-bundle && npm run setup-playwright && web-test-runner --node-resolve --coverage --playwright --browsers chromium firefox webkit",
10
10
  "test:ci": "npm run build-bundle && npm run setup-playwright && web-test-runner --node-resolve --coverage --playwright --browsers chromium firefox webkit",
11
- "test:watch": "web-test-runner --node-resolve --playwright --coverage --watch",
11
+ "test:watch": "npm run build-bundle && npm run setup-playwright && web-test-runner --node-resolve --playwright --coverage --watch",
12
12
  "lint": "eslint .",
13
13
  "docs": "npx jsdoc2md -c .jsdoc.json --files 'src/*.js' > docs/API.md",
14
14
  "build-bundle": "rollup --config",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "devDependencies": {
36
36
  "@adobe/eslint-config-helix": "2.0.6",
37
- "@adobe/helix-rum-js": "2.1.4",
37
+ "@adobe/helix-rum-js": "2.2.0",
38
38
  "@esm-bundle/chai": "4.3.4-fix.0",
39
39
  "@semantic-release/changelog": "6.0.3",
40
40
  "@semantic-release/git": "10.0.1",
package/src/index.js CHANGED
@@ -16,17 +16,19 @@
16
16
  'use strict';
17
17
 
18
18
  const fflags = {
19
- has: (flag) => !!window.origin.match(/localhost/)
20
- || fflags[flag].indexOf(Array.from(window.origin)
21
- .map((a) => a.charCodeAt(0))
22
- .reduce((a, b) => a + b, 1) % 1371) !== -1,
19
+ has: (flag) => fflags[flag].indexOf(Array.from(window.origin)
20
+ .map((a) => a.charCodeAt(0))
21
+ .reduce((a, b) => a + b, 1) % 1371) !== -1
22
+ || !!window.origin.match(/localhost/),
23
23
  enabled: (flag, callback) => fflags.has(flag) && callback(),
24
+
24
25
  disabled: (flag, callback) => !fflags.has(flag) && callback(),
26
+ eagercwv: [683],
25
27
  example: [543, 770, 1136],
26
28
  };
27
29
 
28
30
  const KNOWN_PROPERTIES = ['weight', 'id', 'referer', 'checkpoint', 't', 'source', 'target', 'cwv', 'CLS', 'FID', 'LCP', 'INP', 'TTFB'];
29
- const DEFAULT_TRACKING_EVENTS = ['click', 'cwv', 'form', 'enterleave', 'viewblock', 'viewmedia', 'loadresource', 'utm', 'paid', 'email', 'consent'];
31
+ const DEFAULT_TRACKING_EVENTS = ['click', 'cwv', 'form', 'viewblock', 'viewmedia', 'loadresource', 'utm', 'paid', 'email', 'consent'];
30
32
  fflags.enabled('example', () => DEFAULT_TRACKING_EVENTS.push('example'));
31
33
 
32
34
  const urlSanitizers = {
@@ -148,7 +150,9 @@
148
150
 
149
151
  if (!trackShowConsent()) {
150
152
  // eslint-disable-next-line max-len
151
- consentMutationObserver = window.MutationObserver ? new MutationObserver(trackShowConsent) : null;
153
+ consentMutationObserver = window.MutationObserver
154
+ ? new MutationObserver(trackShowConsent)
155
+ : null;
152
156
  if (consentMutationObserver) {
153
157
  consentMutationObserver.observe(
154
158
  document.body,
@@ -195,11 +199,13 @@
195
199
  });
196
200
  }
197
201
 
198
- const { sampleRUM, queue, isSelected } = (window.hlx && window.hlx.rum) ? window.hlx.rum : {};
202
+ const { sampleRUM, queue, isSelected } = (window.hlx && window.hlx.rum) ? window.hlx.rum
203
+ : {};
199
204
 
200
205
  const formSubmitListener = (e) => sampleRUM('formsubmit', { target: targetSelector(e.target), source: sourceSelector(e.target) });
201
206
  // eslint-disable-next-line no-use-before-define
202
- const mutationObserver = window.MutationObserver ? new MutationObserver(mutationsCallback) : null;
207
+ const mutationObserver = window.MutationObserver ? new MutationObserver(mutationsCallback)
208
+ : null;
203
209
 
204
210
  function trackCheckpoint(checkpoint, data, t) {
205
211
  const { weight, id } = window.hlx.rum;
@@ -250,7 +256,6 @@
250
256
  sampleRUM('cwv', data);
251
257
  };
252
258
 
253
- const featureToggle = () => window.location.hostname === 'blog.adobe.com';
254
259
  const isEager = (metric) => ['CLS', 'LCP'].includes(metric);
255
260
 
256
261
  // When loading `web-vitals` using a classic script, all the public
@@ -258,7 +263,10 @@
258
263
  ['FID', 'INP', 'TTFB', 'CLS', 'LCP'].forEach((metric) => {
259
264
  const metricFn = window.webVitals[`on${metric}`];
260
265
  if (typeof metricFn === 'function') {
261
- const opts = isEager(metric) ? { reportAllChanges: featureToggle() } : undefined;
266
+ let opts = {};
267
+ fflags.enabled('eagercwv', () => {
268
+ opts = { reportAllChanges: isEager(metric) };
269
+ });
262
270
  metricFn(storeCWV, opts);
263
271
  }
264
272
  });
@@ -270,7 +278,7 @@
270
278
  }, 2000); // wait for delayed
271
279
  }
272
280
 
273
- function addEnterLeaveTracking() {
281
+ function addNavigationTracking() {
274
282
  // enter checkpoint when referrer is not the current page url
275
283
  const navigate = (source, type) => {
276
284
  const payload = { source, target: document.visibilityState };
@@ -287,22 +295,8 @@
287
295
  };
288
296
 
289
297
  new PerformanceObserver((list) => list
290
- .getEntries().map((entry) => navigate(document.referrer, entry.type)))
298
+ .getEntries().map((entry) => navigate(window.hlx.referrer || document.referrer, entry.type)))
291
299
  .observe({ type: 'navigation', buffered: true });
292
-
293
- const leave = ((event) => {
294
- try {
295
- if (leave.left || (event.type === 'visibilitychange' && document.visibilityState !== 'hidden')) {
296
- return;
297
- }
298
- leave.left = true;
299
- sampleRUM('leave');
300
- } catch (error) {
301
- // something went wrong
302
- }
303
- });
304
- window.addEventListener('visibilitychange', ((event) => leave(event)));
305
- window.addEventListener('pagehide', ((event) => leave(event)));
306
300
  }
307
301
 
308
302
  function addLoadResourceTracking() {
@@ -340,9 +334,7 @@
340
334
  }
341
335
 
342
336
  function getIntersectionObsever(checkpoint) {
343
- if (!window.IntersectionObserver) {
344
- return null;
345
- }
337
+ if (!window.IntersectionObserver) return null;
346
338
  activateBlocksMutationObserver();
347
339
  const observer = new IntersectionObserver((entries) => {
348
340
  try {
@@ -357,7 +349,7 @@
357
349
  } catch (error) {
358
350
  // something went wrong
359
351
  }
360
- }, { threshold: 0.25 });
352
+ });
361
353
  return observer;
362
354
  }
363
355
  function addViewBlockTracking(element) {
@@ -399,26 +391,19 @@
399
391
  }
400
392
 
401
393
  function addTrackingFromConfig() {
402
- const trackingFunctions = {
403
- click: () => {
404
- document.addEventListener('click', (event) => {
405
- sampleRUM('click', { target: targetSelector(event.target), source: sourceSelector(event.target) });
406
- });
407
- },
408
- cwv: () => addCWVTracking(),
409
- form: () => addFormTracking(window.document.body),
410
- enterleave: () => addEnterLeaveTracking(),
411
- loadresource: () => addLoadResourceTracking(),
412
- utm: () => addUTMParametersTracking(sampleRUM),
413
- viewblock: () => addViewBlockTracking(window.document.body),
414
- viewmedia: () => addViewMediaTracking(window.document.body),
415
- consent: () => addCookieConsentTracking(sampleRUM),
416
- paid: () => addAdsParametersTracking(sampleRUM),
417
- email: () => addEmailParameterTracking(sampleRUM),
418
- };
419
-
420
- DEFAULT_TRACKING_EVENTS.filter((ck) => trackingFunctions[ck])
421
- .forEach((ck) => trackingFunctions[ck]());
394
+ document.addEventListener('click', (event) => {
395
+ sampleRUM('click', { target: targetSelector(event.target), source: sourceSelector(event.target) });
396
+ });
397
+ addCWVTracking();
398
+ addFormTracking(window.document.body);
399
+ addNavigationTracking();
400
+ addLoadResourceTracking();
401
+ addUTMParametersTracking(sampleRUM);
402
+ addViewBlockTracking(window.document.body);
403
+ addViewMediaTracking(window.document.body);
404
+ addCookieConsentTracking(sampleRUM);
405
+ addAdsParametersTracking(sampleRUM);
406
+ addEmailParameterTracking(sampleRUM);
422
407
  }
423
408
 
424
409
  function initEnhancer() {