Skip to main content

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

1

Enable Performance Tracking

Set enablePerformanceTracking: true in your analytics configuration:
2

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)
3

View in Dashboard

Access performance metrics in your MentiQ dashboard to:
  • Monitor Core Web Vitals trends
  • Identify slow pages
  • Compare performance across devices and browsers
  • Set performance budgets and alerts

Core Web Vitals

The SDK automatically tracks Google’s Core Web Vitals when enablePerformanceTracking 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

From src/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 the PerformanceMonitor component:
This tracks:
  • 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

From src/hooks.ts:174-234, the usePerformanceTracking hook provides:
Internally, it uses the Performance API:

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)
Consider tracking:
  • Component render times
  • Database query performance
  • Third-party script impact
  • Route transition speed

Browser Compatibility

Performance tracking requires:
  • window.performance API (supported in all modern browsers)
  • PerformanceObserver for Core Web Vitals (IE11+)
  • PerformanceNavigationTiming for detailed metrics (Edge 12+)
The SDK gracefully degrades if these APIs are unavailable.

Troubleshooting

Metrics Not Being Collected

  1. Verify enablePerformanceTracking: true in config
  2. Check browser supports Performance API
  3. Enable debug: true to see console logs

Inaccurate Load Times

Ensure measurements are taken after the load 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