Skip to content

Commit ed74a8b

Browse files
Bump web-vitals from 4.2.4 to 5.0.0 (#1047)
* Bump web-vitals from 4.2.4 to 5.0.0 Bumps [web-vitals](https://github.com/GoogleChrome/web-vitals) from 4.2.4 to 5.0.0. - [Changelog](https://github.com/GoogleChrome/web-vitals/blob/main/CHANGELOG.md) - [Commits](GoogleChrome/web-vitals@v4.2.4...v5.0.0) --- updated-dependencies: - dependency-name: web-vitals dependency-version: 5.0.0 dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * Migrate to v5 model --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Barry Pollard <barrypollard@google.com>
1 parent 12d1980 commit ed74a8b

File tree

3 files changed

+30
-79
lines changed

3 files changed

+30
-79
lines changed

package-lock.json

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"node-fetch": "3.3.2",
3838
"recursive-readdir": "2.2.3",
3939
"run-script-os": "1.1.6",
40-
"web-vitals": "4.2.4",
40+
"web-vitals": "5.0.0",
4141
"webpack": "5.99.8",
4242
"webpack-cli": "6.0.1",
4343
"xml-js": "1.6.11"

src/js/send-web-vitals.js

Lines changed: 20 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2,70 +2,14 @@
22

33
function sendWebVitals() {
44

5-
function getLoafAttribution(attribution) {
6-
const loafEntriesLength = attribution?.longAnimationFrameEntries?.length || 0;
7-
if (loafEntriesLength === 0) {
8-
return {};
9-
}
5+
function sendWebVitalsGAEvents({name, delta, value, id, attribution, navigationType}) {
106

11-
// The last LoAF entry is usually the most relevant.
12-
const loaf = attribution.longAnimationFrameEntries.at(-1);
13-
const loafEndTime = loaf.startTime + loaf.duration;
7+
let overrides = {};
148

15-
let totalReflow = null;
16-
if (loaf.scripts.length) {
17-
totalReflow = loaf.scripts.reduce((sum, script) => {
18-
return sum + script.forcedStyleAndLayoutDuration;
19-
}, 0);
9+
function roundIfNotNull(x) {
10+
return x != null ? Math.round(x) : null;
2011
}
2112

22-
const loafAttribution = {
23-
// Stats for the LoAF entry itself.
24-
debug_loaf_entry_start_time: loaf.startTime,
25-
debug_loaf_entry_end_time: loafEndTime,
26-
debug_loaf_entry_work_duration: loaf.renderStart ? loaf.renderStart - loaf.startTime : loaf.duration,
27-
debug_loaf_entry_render_duration: loaf.renderStart ? loafEndTime - loaf.renderStart : 0,
28-
debug_loaf_entry_total_forced_style_and_layout_duration: totalReflow,
29-
debug_loaf_entry_pre_layout_duration: loaf.styleAndLayoutStart ? loaf.styleAndLayoutStart - loaf.renderStart : 0,
30-
debug_loaf_entry_style_and_layout_duration: loaf.styleAndLayoutStart ? loafEndTime - loaf.styleAndLayoutStart : 0,
31-
32-
// LoAF metadata.
33-
debug_loaf_meta_length: loafEntriesLength,
34-
debug_loaf_meta_script_length: loaf.scripts.length,
35-
};
36-
37-
// Stats for the slowest script in the LoAF entry.
38-
let scriptAttribution = {};
39-
let slowestScriptDuration = 0;
40-
loaf.scripts.forEach(script => {
41-
if (script.duration <= slowestScriptDuration) {
42-
return {};
43-
}
44-
45-
slowestScriptDuration = script.duration;
46-
scriptAttribution = {
47-
debug_loaf_script_total_duration: script.duration,
48-
debug_loaf_script_compile_duration: script.executionStart - script.startTime,
49-
debug_loaf_script_exec_duration: script.startTime + script.duration - script.executionStart,
50-
debug_loaf_script_forced_style_and_layout_duration: script.forcedStyleAndLayoutDuration,
51-
debug_loaf_script_type: script.invokerType,
52-
debug_loaf_script_invoker: script.invoker,
53-
debug_loaf_script_source_url: script.sourceURL,
54-
debug_loaf_script_source_function_name: script.sourceFunctionName,
55-
debug_loaf_script_source_char_position: script.sourceCharPosition,
56-
}
57-
});
58-
59-
// The LoAF script with the single longest total duration.
60-
return Object.fromEntries(Object.entries({...loafAttribution, ...scriptAttribution}).map(([k, v]) => {
61-
// Convert all floats to ints.
62-
return [k, typeof v == 'number' ? Math.floor(v) : v];
63-
}));
64-
}
65-
66-
function sendWebVitalsGAEvents({name, value, delta, id, attribution, navigationType}) {
67-
let overrides = {};
68-
6913
switch (name) {
7014
case 'CLS':
7115
overrides = {
@@ -83,16 +27,23 @@ function sendWebVitals() {
8327
};
8428
break;
8529
case 'INP': {
86-
const loafAttribution = getLoafAttribution(attribution);
8730
overrides = {
8831
debug_event: attribution.interactionType,
89-
debug_time: Math.round(attribution.interactionTime),
32+
debug_time: roundIfNotNull(attribution.interactionTime),
9033
debug_load_state: attribution.loadState,
9134
debug_target: attribution.interactionTarget || '(not set)',
92-
debug_interaction_delay: Math.round(attribution.inputDelay),
93-
debug_processing_duration: Math.round(attribution.processingDuration),
94-
debug_presentation_delay: Math.round(attribution.presentationDelay),
95-
...loafAttribution
35+
debug_interaction_delay: roundIfNotNull(attribution.inputDelay),
36+
debug_processing_duration: roundIfNotNull(attribution.processingDuration),
37+
debug_presentation_delay: roundIfNotNull(attribution.presentationDelay),
38+
debug_totalPaintDuration: roundIfNotNull(attribution.totalPaintDuration),
39+
debug_totalScriptDuration: roundIfNotNull(attribution.totalScriptDuration),
40+
debug_totalStyleAndLayoutDuration: roundIfNotNull(attribution.totalStyleAndLayoutDuration),
41+
debug_totalUnattributedDuration: roundIfNotNull(attribution.totalUnattributedDuration),
42+
debug_longestScriptIntersectingDuration: roundIfNotNull(attribution.longestScript?.intersectingDuration),
43+
debug_longestScriptSubPart: attribution.longestScript?.subpart || null,
44+
debug_longestScriptInvoker: attribution.longestScript?.entry.invoker || null,
45+
debug_longestScriptInvokerType: attribution.longestScript?.entry.invokerType || null,
46+
debug_longestScriptName: attribution.longestScript?.entry.name || null,
9647
};
9748
break;
9849
}
@@ -103,7 +54,7 @@ function sendWebVitals() {
10354
debug_resource_load_delay: attribution.resourceLoadDelay,
10455
debug_resource_load_time: attribution.resourceLoadTime,
10556
debug_element_render_delay: attribution.elementRenderDelay,
106-
debug_target: attribution.element || '(not set)',
57+
debug_target: attribution.target || '(not set)',
10758
debug_scroll_y: scrollY,
10859
};
10960
break;
@@ -146,12 +97,11 @@ function sendWebVitals() {
14697
event_value: Math.round(name === 'CLS' ? delta * 1000 : delta),
14798
event_label: id,
14899
// Repeat with new fields to match web-vitals documentation
149-
// TODO deprecate above UA-style names
100+
// TODO deprecate above names when no longer required
150101
metric_value: Math.round(name === 'CLS' ? value * 1000 : value),
151102
metric_delta: Math.round(name === 'CLS' ? delta * 1000 : delta),
152103
metric_id: id,
153-
nonInteraction: true,
154-
104+
non_interaction: true,
155105
effective_type: effectiveType,
156106
data_saver: dataSaver,
157107
device_memory: deviceMemory,

0 commit comments

Comments
 (0)