jensteichert / webvitals_exporter

A prometheus exporter and server for reporting Web Vitals from Next.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

A prometheus exporter and server for reporting Web Vitals from Next.js

License:MIT License


Languages

Language:JavaScript 68.2%Language:Go 29.7%Language:Dockerfile 2.2%