Overview
Performance tracking captures critical metrics about page load times, rendering performance, and user experience. The SDK automatically tracks Core Web Vitals and provides tools for custom performance measurements.Quick Start
Automatic Metrics Collection
Once enabled, the SDK automatically tracks:
- Page load time
- DOM ready time
- First Byte (TTFB)
- DNS lookup time
- First Paint (FP)
- First Contentful Paint (FCP)
Core Web Vitals
The SDK automatically tracks Google’s Core Web Vitals whenenablePerformanceTracking is enabled:
Largest Contentful Paint (LCP)
Measures loading performance. Good LCP is under 2.5 seconds.First Input Delay (FID)
Measures interactivity. Good FID is under 100 milliseconds.Cumulative Layout Shift (CLS)
Measures visual stability. Good CLS is under 0.1.First Contentful Paint (FCP)
Measures when the first content is rendered. Good FCP is under 1.8 seconds.Automatic Performance Tracking
Fromsrc/analytics.ts:427-447, the SDK captures navigation timing automatically:
Performance Metrics
The SDK tracks these metrics automatically:Custom Performance Tracking
Track custom performance metrics for specific operations:Using the Hook
Manual Tracking with Analytics Instance
Component Performance Monitoring
Track React component render performance with thePerformanceMonitor component:
- Initial render time
- Re-render frequency
- Total render duration
Use Cases
Track API Response Times
Monitor Image Load Times
Track Route Transitions
Database Query Performance
Performance Hook API
Fromsrc/hooks.ts:174-234, the usePerformanceTracking hook provides:
Performance Budgets
Set performance targets and track violations:Best Practices
Performance Tracking Tips:
- Enable performance tracking in production to get real user metrics
- Track both automatic Core Web Vitals and custom metrics
- Set performance budgets and monitor violations
- Segment performance by device type, connection speed, and geography
- Monitor performance trends over time, not just snapshots
What to Track
Always track:- Core Web Vitals (automatic)
- API response times
- Critical user flows (checkout, signup)
- Resource load times (images, scripts)
- Component render times
- Database query performance
- Third-party script impact
- Route transition speed
Browser Compatibility
Performance tracking requires:window.performanceAPI (supported in all modern browsers)PerformanceObserverfor Core Web Vitals (IE11+)PerformanceNavigationTimingfor detailed metrics (Edge 12+)
Troubleshooting
Metrics Not Being Collected
- Verify
enablePerformanceTracking: truein config - Check browser supports Performance API
- Enable
debug: trueto see console logs
Inaccurate Load Times
Ensure measurements are taken after theload event:
High Performance Overhead
Performance tracking has minimal overhead, but if concerned:- Sample performance data (track only 10% of sessions)
- Reduce custom measurements
- Increase batch sizes to reduce network overhead