@adobe/helix-rum-enhancer 1.3.0 → 1.5.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,18 @@
1
+ # [1.5.0](https://github.com/adobe/helix-rum-enhancer/compare/v1.4.0...v1.5.0) (2023-09-21)
2
+
3
+
4
+ ### Features
5
+
6
+ * **index:** configurable base url. Adapt to changes in helix-rum-js ([1bb9792](https://github.com/adobe/helix-rum-enhancer/commit/1bb9792f46441d4b17809570f3a018552389515f))
7
+ * **index:** enable configurable base url ([3adc4a8](https://github.com/adobe/helix-rum-enhancer/commit/3adc4a8308b86571af5014f6463a4543f3fca857))
8
+
9
+ # [1.4.0](https://github.com/adobe/helix-rum-enhancer/compare/v1.3.0...v1.4.0) (2023-09-02)
10
+
11
+
12
+ ### Features
13
+
14
+ * **checkpoint:** introduce leave checkpoint ([33abd03](https://github.com/adobe/helix-rum-enhancer/commit/33abd03947b0345200eea1d5857b72a036c09923))
15
+
1
16
  # [1.3.0](https://github.com/adobe/helix-rum-enhancer/compare/v1.2.0...v1.3.0) (2023-08-24)
2
17
 
3
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-rum-enhancer",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "description": "Helix RUM Enhancer",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -31,19 +31,19 @@
31
31
  "@adobe/eslint-config-helix": "2.0.3",
32
32
  "@semantic-release/changelog": "6.0.3",
33
33
  "@semantic-release/git": "10.0.1",
34
- "@semantic-release/npm": "10.0.5",
34
+ "@semantic-release/npm": "11.0.0",
35
35
  "c8": "8.0.1",
36
36
  "codecov": "3.8.3",
37
- "eslint": "8.47.0",
37
+ "eslint": "8.49.0",
38
38
  "eslint-plugin-header": "3.1.1",
39
39
  "eslint-plugin-import": "2.28.1",
40
40
  "husky": "8.0.3",
41
41
  "jsdoc-to-markdown": "8.0.0",
42
42
  "junit-report-builder": "3.0.1",
43
- "lint-staged": "14.0.0",
43
+ "lint-staged": "14.0.1",
44
44
  "mocha": "10.2.0",
45
45
  "mocha-multi-reporters": "1.5.1",
46
- "semantic-release": "21.0.7"
46
+ "semantic-release": "22.0.0"
47
47
  },
48
48
  "lint-staged": {
49
49
  "*.js": "eslint",
package/src/index.js CHANGED
@@ -11,6 +11,8 @@
11
11
  */
12
12
  const { sampleRUM } = window.hlx.rum;
13
13
 
14
+ sampleRUM.baseURL = sampleRUM.baseURL || new URL('https://rum.hlx.page');
15
+
14
16
  sampleRUM.blockobserver = (window.IntersectionObserver) ? new IntersectionObserver((entries) => {
15
17
  entries
16
18
  .filter((entry) => entry.isIntersecting)
@@ -62,13 +64,14 @@ sampleRUM.targetselector = (element) => {
62
64
  };
63
65
 
64
66
  sampleRUM.drain('cwv', (() => {
65
- if (document.querySelector('script[src="https://rum.hlx.page/.rum/web-vitals/dist/web-vitals.iife.js"]')) {
67
+ const cwvScript = new URL('.rum/web-vitals/dist/web-vitals.iife.js', sampleRUM.baseURL).href;
68
+ if (document.querySelector(`script[src="${cwvScript}"]`)) {
66
69
  // web vitals script has been loaded already
67
70
  return;
68
71
  }
69
72
  // use classic script to avoid CORS issues
70
73
  const script = document.createElement('script');
71
- script.src = 'https://rum.hlx.page/.rum/web-vitals/dist/web-vitals.iife.js';
74
+ script.src = cwvScript;
72
75
  script.onload = () => {
73
76
  const storeCWV = (measurement) => {
74
77
  const data = { cwv: {} };
@@ -87,6 +90,14 @@ sampleRUM.drain('cwv', (() => {
87
90
  document.head.appendChild(script);
88
91
  }));
89
92
 
93
+ sampleRUM.drain('leave', ((event = {}) => {
94
+ if (sampleRUM.left || (event.type === 'visibilitychange' && document.visibilityState !== 'hidden')) {
95
+ return;
96
+ }
97
+ sampleRUM.left = true;
98
+ sampleRUM('leave');
99
+ }));
100
+
90
101
  sampleRUM.sourceselector = (element) => {
91
102
  if (element === document.body || element === document.documentElement || !element) {
92
103
  return undefined;
@@ -120,3 +131,6 @@ document.querySelectorAll('form').forEach((form) => {
120
131
  sampleRUM('formsubmit', { target: sampleRUM.targetselector(event.target), source: sampleRUM.sourceselector(event.target) });
121
132
  });
122
133
  });
134
+
135
+ window.addEventListener('visibilitychange', ((event) => sampleRUM.leave(event)));
136
+ window.addEventListener('pagehide', ((event) => sampleRUM.leave(event)));