2 min read

Speed Insights Configuration with @vercel/speed-insights

With the @vercel/speed-insights npm package, you can configure your application to capture and send web performance metrics to Vercel.
Table of Contents

Speed Insights is available on all plans

With the @vercel/speed-insights npm package, you're able to configure your application to capture and send web performance metrics to Vercel.

To get started with Speed Insights, refer to our Quickstart guide which will walk you through the process of setting up Speed Insights for your project.

In prior versions of Speed Insights this was managed in the UI. This option is now managed through code with the package.

This parameter determines the percentage of events that are sent to the server. By default, all events are sent. Lowering this parameter allows for cost savings but may result in a decrease in the overall accuracy of the data being sent. For example, a sampleRate of 0.5 would mean that only 50% of the events will be sent to the server.

With the beforeSend function, you can modify or filter out the event data before it's sent to Vercel. You can use this to redact sensitive data or to avoid sending certain events.

For instance, if you wish to ignore events from a specific URL or modify them, you can do so with this option.

// Example usage of beforeSend
beforeSend: (data) => {
  if (data.url.includes('/sensitive-path')) {
    return null; // this will ignore the event
  return data; // this will send the event as is

With the debug mode, you can view all Speed Insights events in the browser's console. This option is especially useful during development.

This option is automatically enabled if the NODE_ENV environment variable is available and either development or test.

You can manually disable it to prevent debug messages in your browsers console.

The route option allows you to specify the current dynamic route (such as /blog/[slug]). This is particularly beneficial when you need to aggregate performance metrics for similar routes.

This option is automatically set when using a framework specific import such as for Next.js, Nuxt, SvelteKit and Remix.

Last updated on June 13, 2024