diff --git a/src/utils/webVitals.ts b/src/utils/webVitals.ts index 8fb3ba1..8de9a4c 100644 --- a/src/utils/webVitals.ts +++ b/src/utils/webVitals.ts @@ -1,5 +1,13 @@ +/** + * Web Vitals Reporting Service + * Tracks and reports Core Web Vitals metrics to Google Analytics + */ + import { onCLS, onINP, onLCP, onFCP, onTTFB } from 'web-vitals'; +/** + * Web Vitals metric data structure + */ interface Metric { name: string; value: number; @@ -8,6 +16,9 @@ interface Metric { id: string; } +/** + * Send Web Vitals metric to Google Analytics and dispatch custom event + */ function sendToAnalytics(metric: Metric) { const body = JSON.stringify({ name: metric.name, @@ -45,6 +56,9 @@ function sendToAnalytics(metric: Metric) { // } } +/** + * Initialize Web Vitals reporting for all Core Web Vitals metrics + */ export function reportWebVitals() { onCLS(sendToAnalytics); onINP(sendToAnalytics); @@ -53,7 +67,9 @@ export function reportWebVitals() { onTTFB(sendToAnalytics); } -// Helper function to get Web Vitals score +/** + * Calculate Web Vitals rating based on metric thresholds + */ export function getWebVitalsScore(metric: Metric): string { const thresholds = { LCP: { good: 2500, poor: 4000 },