@adobe/helix-rum-enhancer 1.10.0 → 1.11.1

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/.releaserc.cjs CHANGED
@@ -12,5 +12,5 @@ module.exports = {
12
12
  }],
13
13
  ["@semantic-release/github", {}]
14
14
  ],
15
- branches: ['main', "1.x"],
15
+ branches: ['main', '1.x'],
16
16
  };
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [1.11.1](https://github.com/adobe/helix-rum-enhancer/compare/v1.11.0...v1.11.1) (2024-02-28)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **cwv:** report metrics eagerly ([b7a7e3e](https://github.com/adobe/helix-rum-enhancer/commit/b7a7e3e202f8dc4de97994cdf36ece95075082c4))
7
+
8
+ # [1.11.0](https://github.com/adobe/helix-rum-enhancer/compare/v1.10.0...v1.11.0) (2024-01-17)
9
+
10
+
11
+ ### Features
12
+
13
+ * **observer:** enable tracking of JSON loading for all browsers that have a PerformanceObserver implementation ([c049f93](https://github.com/adobe/helix-rum-enhancer/commit/c049f930f0cc1dc548e42bd8e76cd97709a873d7))
14
+
1
15
  # [1.10.0](https://github.com/adobe/helix-rum-enhancer/compare/v1.9.1...v1.10.0) (2024-01-16)
2
16
 
3
17
 
package/README.md CHANGED
@@ -4,10 +4,9 @@
4
4
 
5
5
  ## Status
6
6
  [![codecov](https://img.shields.io/codecov/c/github/adobe/helix-rum-enhancer.svg)](https://codecov.io/gh/adobe/helix-rum-enhancer)
7
- [![CircleCI](https://img.shields.io/circleci/project/github/adobe/helix-rum-enhancer.svg)](https://circleci.com/gh/adobe/helix-rum-enhancer)
7
+ [![GitHub Actions](https://img.shields.io/github/actions/workflow/status/adobe/helix-rum-enhancer/main.yaml)](https://github.com/adobe/helix-rum-enhancer/actions/workflows/main.yaml)
8
8
  [![GitHub license](https://img.shields.io/github/license/adobe/helix-rum-enhancer.svg)](https://github.com/adobe/helix-rum-enhancer/blob/master/LICENSE.txt)
9
9
  [![GitHub issues](https://img.shields.io/github/issues/adobe/helix-rum-enhancer.svg)](https://github.com/adobe/helix-rum-enhancer/issues)
10
- [![LGTM Code Quality Grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/adobe/helix-rum-enhancer.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/adobe/helix-rum-enhancer)
11
10
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
12
11
 
13
12
  ## Usage
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-rum-enhancer",
3
- "version": "1.10.0",
3
+ "version": "1.11.1",
4
4
  "description": "Helix RUM Enhancer",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -9,6 +9,7 @@
9
9
  "lint": "eslint .",
10
10
  "docs": "npx jsdoc2md -c .jsdoc.json --files 'src/*.js' > docs/API.md",
11
11
  "semantic-release": "semantic-release",
12
+ "semantic-release-dry": "semantic-release --dry-run --branches $CI_BRANCH 1.x main",
12
13
  "prepare": "husky install"
13
14
  },
14
15
  "repository": {
@@ -28,7 +29,7 @@
28
29
  "reporter-options": "configFile=.mocha-multi.json"
29
30
  },
30
31
  "devDependencies": {
31
- "@adobe/eslint-config-helix": "2.0.5",
32
+ "@adobe/eslint-config-helix": "2.0.6",
32
33
  "@semantic-release/changelog": "6.0.3",
33
34
  "@semantic-release/git": "10.0.1",
34
35
  "@semantic-release/npm": "11.0.2",
package/src/index.js CHANGED
@@ -91,14 +91,19 @@ sampleRUM.drain('cwv', (() => {
91
91
  data.cwv[measurement.name] = measurement.value;
92
92
  sampleRUM('cwv', data);
93
93
  };
94
+
95
+ const featureToggle = () => window.location.hostname === 'blog.adobe.com';
96
+ const isEager = (metric) => ['CLS', 'LCP'].includes(metric);
97
+
94
98
  // When loading `web-vitals` using a classic script, all the public
95
99
  // methods can be found on the `webVitals` global namespace.
96
- ['CLS', 'FID', 'LCP', 'INP', 'TTFB']
97
- .map((metric) => window.webVitals[`get${metric}`])
98
- .filter((metric) => typeof metric === 'function')
99
- .forEach((invokeMetric) => {
100
- invokeMetric(storeCWV);
101
- });
100
+ ['FID', 'INP', 'TTFB', 'CLS', 'LCP'].forEach((metric) => {
101
+ const metricFn = window.webVitals[`on${metric}`];
102
+ if (typeof metricFn === 'function') {
103
+ const opts = isEager(metric) ? { reportAllChanges: featureToggle() } : undefined;
104
+ metricFn(storeCWV, opts);
105
+ }
106
+ });
102
107
  };
103
108
  document.head.appendChild(script);
104
109
  }));
@@ -137,7 +142,6 @@ sampleRUM.sourceselector = (element) => {
137
142
  if (Array.from(element.classList).some((className) => className.match(/button|cta/))) {
138
143
  return blockName ? `.${blockName} .button` : '.button';
139
144
  }
140
-
141
145
  return sampleRUM.sourceselector(element.parentElement);
142
146
  };
143
147
 
@@ -155,15 +159,13 @@ document.querySelectorAll('form').forEach((form) => {
155
159
  window.addEventListener('visibilitychange', ((event) => sampleRUM.leave(event)));
156
160
  window.addEventListener('pagehide', ((event) => sampleRUM.leave(event)));
157
161
 
158
- if (window.location.hostname === 'blog.adobe.com') {
159
- const observer = new PerformanceObserver((list) => {
160
- list.getEntries()
161
- .filter((entry) => !entry.responseStatus || entry.responseStatus < 400)
162
- .filter((entry) => window.location.hostname === new URL(entry.name).hostname)
163
- .filter((entry) => new URL(entry.name).pathname.match('.*(\\.plain\\.html|\\.json)$'))
164
- .forEach((entry) => {
165
- sampleRUM('loadresource', { source: entry.name, target: Math.round(entry.duration) });
166
- });
167
- });
168
- observer.observe({ type: 'resource', buffered: true });
169
- }
162
+ const observer = new PerformanceObserver((list) => {
163
+ list.getEntries()
164
+ .filter((entry) => !entry.responseStatus || entry.responseStatus < 400)
165
+ .filter((entry) => window.location.hostname === new URL(entry.name).hostname)
166
+ .filter((entry) => new URL(entry.name).pathname.match('.*(\\.plain\\.html|\\.json)$'))
167
+ .forEach((entry) => {
168
+ sampleRUM('loadresource', { source: entry.name, target: Math.round(entry.duration) });
169
+ });
170
+ });
171
+ observer.observe({ type: 'resource', buffered: true });