Skip to content

jensteichert/webvitals_exporter

Repository files navigation

webvitals_exporter

Build CodeQL

Report Web Vitals from Next.js to Prometheus

Report Web Vitals

The exporter exposes a /vitals endpoint where results can be reported.

with Next.js

Export a reportWebVitals function from your _app.js/ts

export function reportWebVitals(metric) {
    const body = JSON.stringify(metric)
    const url = 'http://{ADRESS_TO_SERVER}:2113/vitals'

    // Use `navigator.sendBeacon()` if available, falling back to `fetch()`.
    if (navigator.sendBeacon) {
        navigator.sendBeacon(url, body)
    } else {
        fetch(url, { body, method: 'POST', keepalive: true })
    }
}

For further documentation visit https://nextjs.org/docs/advanced-features/measuring-performance