Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add experimental Web Vitals support for Next.js #148

Merged
merged 3 commits into from
May 22, 2020
Merged

Conversation

adamyeats
Copy link
Contributor

@adamyeats adamyeats commented May 14, 2020

Adds experimental support for Next.js v9.4 Web Vitals reporting. This works by providing an Express middleware which will mount a route to /__appsignal-web-vitals and POST the metrics to that, and we’ll add custom metrics for these metrics on the server.

This works by exporting a reportWebVitals function from pages/_app.js as described here.

export function reportWebVitals(metric) {
  const body = JSON.stringify(metric)
  const url = '/__appsignal-web-vitals'

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

On successful setup, two new magic dashboards will be created for the user - Next.js and Next.js Web Vitals.

@adamyeats
Copy link
Contributor Author

See appsignal/public_config#18 for magic dashboard config.

@adamyeats adamyeats changed the title Add experimental Web Vitals support Add experimental Web Vitals support for Next.js May 14, 2020
@adamyeats adamyeats mentioned this pull request May 14, 2020
@adamyeats adamyeats force-pushed the nextjs-web-vitals branch 5 times, most recently from 6a2b5c1 to a577c22 Compare May 14, 2020 22:32
@backlog-helper

This comment has been minimized.

@backlog-helper

This comment has been minimized.

Copy link
Member

@jeffkreeftmeijer jeffkreeftmeijer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@backlog-helper
Copy link

While performing the daily checks some issues were found with this Pull Request.


New issue guide | Backlog management | Rules | Feedback

@adamyeats adamyeats merged commit 9f01846 into master May 22, 2020
@adamyeats adamyeats deleted the nextjs-web-vitals branch May 22, 2020 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants