Skip to content

Commit fbfef3a

Browse files
authored
RUM improvements (#909)
* LoAF attribution, remove FID * SpeedCurve CSP * GA CSP * GA4 CSP * fix GA host * more CSP * doubleclick CSP * test
1 parent 2754f02 commit fbfef3a

2 files changed

Lines changed: 35 additions & 28 deletions

File tree

server/csp.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"'self'",
66
"'strict-dynamic'",
77
"cdn.httparchive.org",
8-
"*.google-analytics.com",
98
"use.fontawesome.com",
9+
"*.googletagmanager.com",
1010
"cdn.speedcurve.com",
1111
"spdcrv.global.ssl.fastly.net",
1212
"lux.speedcurve.com",
@@ -22,14 +22,19 @@
2222
"dev.to",
2323
"cdn.rawgit.com",
2424
"www.webpagetest.org",
25-
"*.google-analytics.com",
26-
"analytics.google.com",
2725
"*.analytics.google.com",
28-
"stats.g.doubleclick.net",
26+
"*.google-analytics.com",
27+
"*.googletagmanager.com",
28+
"*.speedcurve.com",
2929
"dev-gw-2vzgiib6.ue.gateway.dev",
3030
"prod-gw-2vzgiib6.ue.gateway.dev",
3131
],
32-
"img-src": ["'self'", "https:"],
32+
"img-src": [
33+
"'self'",
34+
"https:",
35+
"*.google-analytics.com",
36+
"*.googletagmanager.com",
37+
],
3338
"frame-src": ["'none'"],
3439
"object-src": ["'none'"],
3540
"base-uri": ["'none'"],

src/js/send-web-vitals.js

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,35 @@ function sendWebVitals() {
66
return {};
77
}
88

9-
let loafAttribution = {
10-
debug_loaf_script_total_duration: 0
11-
};
12-
139
// The last LoAF entry is usually the most relevant.
1410
const loaf = attribution.longAnimationFrameEntries.at(-1);
1511
const loafEndTime = loaf.startTime + loaf.duration;
12+
13+
const loafAttribution = {
14+
// Stats for the LoAF entry itself.
15+
debug_loaf_entry_start_time: loaf.startTime,
16+
debug_loaf_entry_end_time: loafEndTime,
17+
debug_loaf_entry_work_duration: loaf.renderStart ? loaf.renderStart - loaf.startTime : loaf.duration,
18+
debug_loaf_entry_render_duration: loaf.renderStart ? loafEndTime - loaf.renderStart : 0,
19+
debug_loaf_entry_total_forced_style_and_layout_duration: loaf.scripts.reduce((sum, script) => sum + script.forcedStyleAndLayoutDuration, 0),
20+
debug_loaf_entry_pre_layout_duration: loaf.styleAndLayoutStart ? loaf.styleAndLayoutStart - loaf.renderStart : 0,
21+
debug_loaf_entry_style_and_layout_duration: loaf.styleAndLayoutStart ? loafEndTime - loaf.styleAndLayoutStart : 0,
22+
23+
// LoAF metadata.
24+
debug_loaf_meta_length: loafEntriesLength,
25+
debug_loaf_meta_script_length: loaf.scripts.length,
26+
};
27+
28+
// Stats for the slowest script in the LoAF entry.
29+
let scriptAttribution = {};
30+
let slowestScriptDuration = 0;
1631
loaf.scripts.forEach(script => {
17-
if (script.duration <= loafAttribution.debug_loaf_script_total_duration) {
18-
return;
32+
if (script.duration <= slowestScriptDuration) {
33+
return {};
1934
}
20-
loafAttribution = {
21-
// Stats for the LoAF entry itself.
22-
debug_loaf_entry_start_time: loaf.startTime,
23-
debug_loaf_entry_end_time: loafEndTime,
24-
debug_loaf_entry_work_duration: loaf.renderStart ? loaf.renderStart - loaf.startTime : loaf.duration,
25-
debug_loaf_entry_render_duration: loaf.renderStart ? loafEndTime - loaf.renderStart : 0,
26-
debug_loaf_entry_total_forced_style_and_layout_duration: loaf.scripts.reduce((sum, script) => sum + script.forcedStyleAndLayoutDuration, 0),
27-
debug_loaf_entry_pre_layout_duration: loaf.styleAndLayoutStart ? loaf.styleAndLayoutStart - loaf.renderStart : 0,
28-
debug_loaf_entry_style_and_layout_duration: loaf.styleAndLayoutStart ? loafEndTime - loaf.styleAndLayoutStart : 0,
29-
30-
// Stats for the longest script in the LoAF entry.
35+
36+
slowestScriptDuration = script.duration;
37+
scriptAttribution = {
3138
debug_loaf_script_total_duration: script.duration,
3239
debug_loaf_script_compile_duration: script.executionStart - script.startTime,
3340
debug_loaf_script_exec_duration: script.startTime + script.duration - script.executionStart,
@@ -37,9 +44,6 @@ function sendWebVitals() {
3744
debug_loaf_script_source_url: script.sourceURL,
3845
debug_loaf_script_source_function_name: script.sourceFunctionName,
3946
debug_loaf_script_source_char_position: script.sourceCharPosition,
40-
41-
// LoAF metadata.
42-
debug_loaf_meta_length: loafEntriesLength,
4347
}
4448
});
4549

@@ -73,7 +77,6 @@ function sendWebVitals() {
7377
debug_target: attribution.loadState || '(not set)',
7478
};
7579
break;
76-
case 'FID':
7780
case 'INP':
7881
const loafAttribution = getLoafAttribution(attribution);
7982
overrides = {
@@ -83,7 +86,7 @@ function sendWebVitals() {
8386
debug_target: attribution.interactionTarget || '(not set)',
8487
debug_interaction_delay: Math.round(attribution.inputDelay),
8588
debug_processing_duration: Math.round(attribution.processingDuration),
86-
debug_presentation_delay: Math.round(attribution.presentationDelay),
89+
debug_presentation_delay: Math.round(attribution.presentationDelay),
8790
...loafAttribution
8891
};
8992
break;
@@ -161,7 +164,6 @@ function sendWebVitals() {
161164
webVitals.onLCP(sendWebVitalsGAEvents);
162165
webVitals.onCLS(sendWebVitalsGAEvents);
163166
webVitals.onTTFB(sendWebVitalsGAEvents);
164-
webVitals.onFID(sendWebVitalsGAEvents);
165167
webVitals.onINP(sendWebVitalsGAEvents);
166168
} else {
167169
console.error('Web Vitals is not loaded!!');

0 commit comments

Comments
 (0)