/* * Get Web Vital Rating * */ function getRating(name, value) { switch (name) { case 'LCP': return calculateRating(value,2500,4000); case 'FID': return calculateRating(value,100,300); case 'CLS': return calculateRating(value,0.1,0.25); case 'FCP': return calculateRating(value,2000,4000); // Page Speed Insights is 1000 and 3000, lighthouse and web.dev does 2000 and 4000 case 'TTFB': return calculateRating(value,500,1500); // CrUX Data Studio report says NI is 500ms to 1500ms default: return '(not set)'; } } function calculateRating(value, good, poor) { if (!value && value !== 0) return '(not set)'; if (value > poor) return 'poor'; if (value > good) return 'ni'; return 'good'; }