@nuxtjs/web-vitals
Version:
Web Vitals for Nuxt.js
19 lines (18 loc) • 752 B
JavaScript
import { logError } from "./utils.mjs";
export async function webVitals({ route, options, sendToAnalytics }) {
const context = {
fullPath: route.fullPath,
href: location.href
};
try {
const { onCLS, onFID, onLCP, onTTFB, onFCP, onINP } = await import("web-vitals").then((r) => r.default || r);
onFID((metric) => sendToAnalytics(context, metric, options));
onTTFB((metric) => sendToAnalytics(context, metric, options));
onLCP((metric) => sendToAnalytics(context, metric, options));
onCLS((metric) => sendToAnalytics(context, metric, options));
onFCP((metric) => sendToAnalytics(context, metric, options));
onINP((metric) => sendToAnalytics(context, metric, options));
} catch (err) {
logError(err);
}
}