@nuxtjs/web-vitals
Version:
Web Vitals for Nuxt.js
19 lines (18 loc) • 492 B
JavaScript
import { webVitals } from "./web-vitals.mjs";
import { sendToAnalytics } from "~web-vitals-provider";
import webVitalsOptions from "#build/web-vitals-config.mjs";
const sendVitals = (to) => webVitals({
options: webVitalsOptions,
sendToAnalytics,
route: to
});
export default function(ctx) {
const router = ctx.app && ctx.app.router || ctx.$router;
if (!router) {
return;
}
router.onReady((to) => {
sendVitals(to);
router.afterEach((to2) => sendVitals(to2));
});
}