Web Vitals
Automatically capture Core Web Vitals (LCP, CLS, INP, TTFB, FCP) and route-level performance metrics with zero configuration.
Quick Setup
Add the metrics component to your root layout:
typescript
Metrics are automatically captured and displayed in the Dev Overlay's Metrics tab.
Configuration
| Prop | Type | Default | Description |
|---|---|---|---|
enabled |
boolean |
true |
Enable/disable metric collection |
sampleRate |
number |
1.0 (dev) / 0.1 (prod) |
Percentage of sessions to track (0.0 - 1.0) |
reportEndpoint |
string |
'/api/vestig/metrics' |
Endpoint for sending metrics |
reportPoorImmediately |
boolean |
true |
Send "poor" ratings immediately (don't wait for batch) |
captureRouteMetrics |
boolean |
true |
Track route navigation timing |
debug |
boolean |
false |
Log metrics to console |
Captured Metrics
Core Web Vitals
| Metric | Description | Good | Poor |
|---|---|---|---|
| LCP | Largest Contentful Paint - Loading performance | < 2.5s | > 4.0s |
| CLS | Cumulative Layout Shift - Visual stability | < 0.1 | > 0.25 |
| INP | Interaction to Next Paint - Interactivity | < 200ms | > 500ms |
| TTFB | Time to First Byte - Server responsiveness | < 800ms | > 1.8s |
| FCP | First Contentful Paint - Perceived load speed | < 1.8s | > 3.0s |
Route Metrics
- Render Time: Time to render the page
- Hydration Time: Time for React hydration
- Data Fetch Time: Time spent fetching data
Using Hooks
Access metrics data in your components:
typescript
Rating System
Each metric receives a rating based on Google's Core Web Vitals thresholds:
- 🟢 Good - Meets the recommended threshold
- 🟡 Needs Improvement - Between good and poor
- 🔴 Poor - Exceeds the poor threshold
Production Setup
For production, use sampling to reduce data volume:
typescript
Metrics API Endpoint
Create an endpoint to receive metrics:
typescript
Best Practices
1. Use Sampling in Production
Full metric collection on every user adds overhead. Sample a percentage:
typescript
2. Report Poor Metrics Immediately
Don't wait to batch poor experiences:
typescript
3. Combine with Dev Overlay
Use the Dev Overlay's Metrics tab during development:
typescript
Threshold Reference
typescript
Next Steps
- Dev Overlay — View metrics in real-time
- Error Boundary — Handle errors gracefully
- Logging Basics — Understand structured logging