Skip to content

Commit 9cbc523

Browse files
author
niuweili
committed
feat: update spa
1 parent 23a2ba3 commit 9cbc523

2 files changed

Lines changed: 53 additions & 15 deletions

File tree

flashduty/en/2. RUM/3. Performance Monitoring/2. Metrics.md

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ In addition to core metrics, it also supports other auxiliary metrics:
2525

2626
These metrics are automatically collected when users visit pages and reported to the Flashduty platform through the SDK. You can view detailed performance data in the analysis dashboard.
2727

28+
:::tip
29+
Interaction to Next Paint and Largest Contentful Paint are not collected for pages opened in the background (for example, in a new tab or a window without focus).
30+
:::
31+
2832
## Metric Calculation Methods
2933

3034
### 1. Largest Contentful Paint (LCP)
@@ -53,6 +57,18 @@ These metrics are automatically collected when users visit pages and reported to
5357
- **Use case**: Optimize response speed for interaction-intensive pages (such as forms, navigation menus).
5458

5559

60+
## Monitoring Single Page Applications (SPA)
61+
62+
For Single Page Applications (SPA), the RUM browser SDK distinguishes between two navigation types through the `loading_type` attribute: `initial_load` and `route_change`.
63+
64+
1. History Single Page Applications
65+
If an interaction on a webpage causes the URL to change but the page does not refresh completely, the RUM SDK will start a new `view` using `loading_type:route_change`. RUM uses the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History) to track URL changes.
66+
67+
2. Hash Single Page Applications
68+
The RUM SDK automatically monitors frameworks that rely on hash (`#`) navigation. The SDK listens for `HashChangeEvent` and issues a new `view`. Events from HTML anchors that do not affect the current view context are ignored.
69+
70+
For SPA applications, if you need to monitor performance after route changes, it is recommended to use the [Custom Performance Monitoring](#Custom%20Performance%20Monitoring) feature to measure performance metrics of specific components or interactions.
71+
5672
## Custom Performance Monitoring
5773

5874
### 1. Component-level Performance Measurement
@@ -122,13 +138,7 @@ document.addEventListener("scroll", function handler() {
122138
- Use descriptive naming (such as `login_form_render`).
123139
- Maintain naming consistency.
124140

125-
### 2. SPA Scenario Handling
126-
127-
- When route changes, timing is based on the start time of the current RUM view.
128-
- Some timers need to be reset.
129-
- Pay attention to metric continuity during page transitions.
130-
131-
### 3. Performance Impact Control
141+
### 2. Performance Impact Control
132142

133143
- Control the number of custom metrics.
134144
- Avoid frequent timing.
@@ -154,6 +164,15 @@ document.addEventListener("scroll", function handler() {
154164
- Ensure timers are started and stopped correctly.
155165
- Check timestamp accuracy in asynchronous scenarios.
156166

167+
### 4. Empty Web Vitals Metrics Collection
168+
169+
- **Background pages**: Pages opened in new tabs or unfocused windows, causing INP and LCP to be uncollectable
170+
- **SPA route changes**: During `loading_type:route_change`, Core Web Vitals metrics (LCP, CLS, INP, FCP) will not be re-collected
171+
- **Integration method**: Page loads completely before SDK is fully initialized
172+
- **Page lifecycle**: Page is closed or navigated away before metrics collection is complete
173+
- **Browser compatibility**: Older browser versions do not support certain Web Vitals APIs
174+
- **Empty page content**: Page has no measurable content elements (such as blank pages)
175+
157176
## Next Steps
158177

159178
- [Performance Analysis](https://docs.flashcat.cloud/en/flashduty/rum/performance-analysis?nav=01JCQ7A4N4WRWNXW8EWEHXCMF5)

flashduty/zh/2. RUM/3. 性能监控/2. 指标上报.md

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ Flashduty RUM 支持以下[核心 Web Vitals 指标](https://web.dev/articles/vi
2525

2626
这些指标会在用户访问页面时自动收集,并通过 SDK 上报到 Flashduty 平台,您可以在分析看板中查看详细的性能数据。
2727

28+
:::tip
29+
对于在后台打开的页面(例如,在新标签页或无焦点的窗口中),不会收集到下一绘制时间(Interaction to Next Paint)和最大内容绘制时间(Largest Contentful Paint)的数据。
30+
:::
31+
2832
## 指标计算方法
2933

3034
### 1. 最大内容绘制(LCP)
@@ -53,6 +57,18 @@ Flashduty RUM 支持以下[核心 Web Vitals 指标](https://web.dev/articles/vi
5357
- **用例**: 优化交互密集型页面(如表单、导航菜单)的响应速度。
5458

5559

60+
## 监控单页应用(SPA)
61+
62+
对于单页应用程序 (SPA),RUM 浏览器 SDK 通过`loading_type`属性区分`initial_load``route_change`这两种导航类型。
63+
64+
1. History 单页应用
65+
如果网页上的某个交互操作导致 URL 发生变化,但页面并未完全刷新,RUM SDK 会使用`loading_type:route_change`启动一个新的`view`。RUM 使用[History API](https://developer.mozilla.org/zh-CN/docs/Web/API/History)来跟踪 URL 的变化。
66+
67+
2. Hash 单页应用
68+
RUM SDK 会自动监控依赖哈希(`#`)导航的框架。SDK 会监听 `HashChangeEvent` 并发出一个新的`view`。来自HTML锚点且不影响当前视图上下文的事件将被忽略。
69+
70+
对于 SPA 应用,如需监控路由切换后的性能,建议使用[自定义性能监控](#自定义性能监控)功能来测量特定组件或交互的性能指标。
71+
5672
## 自定义性能监控
5773

5874
### 1. 组件级性能测量
@@ -122,20 +138,13 @@ document.addEventListener("scroll", function handler() {
122138
- 使用描述性命名(如 `login_form_render`)。
123139
- 保持命名一致性。
124140

125-
### 2. SPA 场景处理
126-
127-
- 路由变更时,计时以当前 RUM view 的开始时间为基准。
128-
- 需要重置某些计时器。
129-
- 注意页面切换时的指标连续性。
130-
131-
### 3. 性能影响控制
141+
### 2. 性能影响控制
132142

133143
- 控制自定义指标数量。
134144
- 避免频繁计时。
135145
- 合理设置采样率。
136146

137147
## 常见问题
138-
139148
### 1. 页面加载时间异常
140149

141150
- 检查慢加载资源(图片、脚本)。
@@ -154,6 +163,16 @@ document.addEventListener("scroll", function handler() {
154163
- 确保计时器正确启停。
155164
- 检查异步场景的时间戳准确性。
156165

166+
### 4. 收集的Web Vitals指标为空
167+
168+
- **后台页面**:页面在新标签页或无焦点窗口中打开,导致INP和LCP无法收集
169+
- **SPA路由切换**:在`loading_type:route_change`时,核心Web Vitals指标(LCP、CLS、INP、FCP)不会重新收集
170+
- **引入方式**:页面在SDK完全初始化前就已加载完成
171+
- **页面生命周期**:页面在指标收集完成前就被关闭或导航离开
172+
- **浏览器兼容性**:旧版本浏览器不支持某些Web Vitals API
173+
- **页面无内容**:页面没有可测量的内容元素(如空白页面)
174+
175+
157176
## 下一步
158177

159178
- [性能分析](https://docs.flashcat.cloud/zh/flashduty/rum/performance-analysis)

0 commit comments

Comments
 (0)