auto-claude: subtask-3-5 - Add JSDoc to webVitals.ts

This commit is contained in:
2026-01-25 11:57:04 +01:00
parent a64647cce0
commit 09b31fd7c1
+17 -1
View File
@@ -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'; import { onCLS, onINP, onLCP, onFCP, onTTFB } from 'web-vitals';
/**
* Web Vitals metric data structure
*/
interface Metric { interface Metric {
name: string; name: string;
value: number; value: number;
@@ -8,6 +16,9 @@ interface Metric {
id: string; id: string;
} }
/**
* Send Web Vitals metric to Google Analytics and dispatch custom event
*/
function sendToAnalytics(metric: Metric) { function sendToAnalytics(metric: Metric) {
const body = JSON.stringify({ const body = JSON.stringify({
name: metric.name, name: metric.name,
@@ -45,6 +56,9 @@ function sendToAnalytics(metric: Metric) {
// } // }
} }
/**
* Initialize Web Vitals reporting for all Core Web Vitals metrics
*/
export function reportWebVitals() { export function reportWebVitals() {
onCLS(sendToAnalytics); onCLS(sendToAnalytics);
onINP(sendToAnalytics); onINP(sendToAnalytics);
@@ -53,7 +67,9 @@ export function reportWebVitals() {
onTTFB(sendToAnalytics); onTTFB(sendToAnalytics);
} }
// Helper function to get Web Vitals score /**
* Calculate Web Vitals rating based on metric thresholds
*/
export function getWebVitalsScore(metric: Metric): string { export function getWebVitalsScore(metric: Metric): string {
const thresholds = { const thresholds = {
LCP: { good: 2500, poor: 4000 }, LCP: { good: 2500, poor: 4000 },