Getting Started with Speed Insights
This guide will help you get started with using Vercel Speed Insights on your project, showing you how to enable it, add the package to your project, deploy your app to Vercel, and view your data in the dashboard.
Speed Insights provides real-time performance monitoring for your web applications, tracking key metrics like Core Web Vitals to help you understand and optimize your site's user experience.
Prerequisites
Before you begin, ensure you have the following:
- A Vercel account - If you don't have one, you can sign up for free.
- A Vercel project - If you don't have one, you can create a new project.
- The Vercel CLI installed - If you don't have it, you can install it using one of the following commands:
- pnpm
- yarn
- npm
- bun
pnpm i vercel
yarn add vercel
npm i vercel
bun add vercel
Setup Steps
Step 1: Enable Speed Insights in Vercel
On the Vercel dashboard, select your Project followed by the Speed Insights tab. Then, select Enable from the dialog.
Enabling Speed Insights will add new routes (scoped at /_vercel/speed-insights/*) after your next deployment.
Step 2: Add @vercel/speed-insights to Your Project
The installation process varies by framework. HTML projects do not require package installation.
For most frameworks (Next.js, React, Remix, SvelteKit, Vue, Nuxt, Astro), install the package using your preferred package manager:
- pnpm
- yarn
- npm
- bun
pnpm i @vercel/speed-insights
yarn add @vercel/speed-insights
npm i @vercel/speed-insights
bun add @vercel/speed-insights
When using the HTML implementation, there is no need to install the @vercel/speed-insights package. Skip to the HTML integration section below.
Step 3: Integrate Speed Insights into Your Application
The integration method depends on your framework. Choose the appropriate section below:
Framework-Specific Integration
Next.js (Pages Router)
The SpeedInsights component is a wrapper around the tracking script, offering seamless integration with Next.js.
Add the component to your pages/_app.tsx or pages/_app.jsx file:
- TypeScript
- JavaScript
import type { AppProps } from 'next/app';
import { SpeedInsights } from '@vercel/speed-insights/next';
function MyApp({ Component, pageProps }: AppProps) {
return (
<>
<Component {...pageProps} />
<SpeedInsights />
</>
);
}
export default MyApp;
import { SpeedInsights } from '@vercel/speed-insights/next';
function MyApp({ Component, pageProps }) {
return (
<>
<Component {...pageProps} />
<SpeedInsights />
</>
);
}
export default MyApp;
For versions of Next.js older than 13.5, import from @vercel/speed-insights/react and pass the pathname:
- TypeScript
- JavaScript
import { SpeedInsights } from '@vercel/speed-insights/react';
import { useRouter } from 'next/router';
export default function Layout() {
const router = useRouter();
return <SpeedInsights route={router.pathname} />;
}
import { SpeedInsights } from '@vercel/speed-insights/react';
import { useRouter } from 'next/router';
export default function Layout() {
const router = useRouter();
return <SpeedInsights route={router.pathname} />;
}
Next.js (App Router)
Add the SpeedInsights component to your root layout:
- TypeScript
- JavaScript
import { SpeedInsights } from '@vercel/speed-insights/next';
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<head>
<title>Next.js</title>
</head>
<body>
{children}
<SpeedInsights />
</body>
</html>
);
}
import { SpeedInsights } from '@vercel/speed-insights/next';
export default function RootLayout({ children }) {
return (
<html lang="en">
<head>
<title>Next.js</title>
</head>
<body>
{children}
<SpeedInsights />
</body>
</html>
);
}
Create a dedicated client component to avoid opting out from SSR on the layout:
- TypeScript
- JavaScript
'use client';
import { SpeedInsights } from '@vercel/speed-insights/react';
import { usePathname } from 'next/navigation';
export function Insights() {
const pathname = usePathname();
return <SpeedInsights route={pathname} />;
}
'use client';
import { SpeedInsights } from '@vercel/speed-insights/react';
import { usePathname } from 'next/navigation';
export function Insights() {
const pathname = usePathname();
return <SpeedInsights route={pathname} />;
}
Then import in your layout:
- TypeScript
- JavaScript
import type { ReactNode } from 'react';
import { Insights } from './insights';
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="en">
<head>
<title>Next.js</title>
</head>
<body>
{children}
<Insights />
</body>
</html>
);
}
import { Insights } from './insights';
export default function RootLayout({ children }) {
return (
<html lang="en">
<head>
<title>Next.js</title>
</head>
<body>
{children}
<Insights />
</body>
</html>
);
}
Create React App
Add the SpeedInsights component to your main app file:
- TypeScript
- JavaScript
import { SpeedInsights } from '@vercel/speed-insights/react';
export default function App() {
return (
<div>
{/* Your app content */}
<SpeedInsights />
</div>
);
}
import { SpeedInsights } from '@vercel/speed-insights/react';
export default function App() {
return (
<div>
{/* Your app content */}
<SpeedInsights />
</div>
);
}
Remix
Add the SpeedInsights component to your root file:
- TypeScript
- JavaScript
import { SpeedInsights } from '@vercel/speed-insights/remix';
export default function App() {
return (
<html lang="en">
<body>
{/* Your app content */}
<SpeedInsights />
</body>
</html>
);
}
import { SpeedInsights } from '@vercel/speed-insights/remix';
export default function App() {
return (
<html lang="en">
<body>
{/* Your app content */}
<SpeedInsights />
</body>
</html>
);
}
SvelteKit
Call the injectSpeedInsights function in your root layout:
- TypeScript
- JavaScript
import { injectSpeedInsights } from '@vercel/speed-insights/sveltekit';
injectSpeedInsights();
import { injectSpeedInsights } from '@vercel/speed-insights/sveltekit';
injectSpeedInsights();
Vue
Add the SpeedInsights component to your main app template:
- TypeScript
- JavaScript
<script setup lang="ts">
import { SpeedInsights } from '@vercel/speed-insights/vue';
</script>
<template>
<SpeedInsights />
<!-- Your app content -->
</template>
<script setup>
import { SpeedInsights } from '@vercel/speed-insights/vue';
</script>
<template>
<SpeedInsights />
<!-- Your app content -->
</template>
Nuxt
Add the SpeedInsights component to your default layout:
- TypeScript
- JavaScript
<script setup lang="ts">
import { SpeedInsights } from '@vercel/speed-insights/vue';
</script>
<template>
<SpeedInsights />
<!-- Your app content -->
</template>
<script setup>
import { SpeedInsights } from '@vercel/speed-insights/vue';
</script>
<template>
<SpeedInsights />
<!-- Your app content -->
</template>
Astro
Speed Insights is available for both static and SSR Astro apps. Declare the <SpeedInsights /> component near the bottom of a layout component:
- TypeScript
- JavaScript
---
import SpeedInsights from '@vercel/speed-insights/astro';
const { title, description } = Astro.props;
---
<title>{title}</title>
<meta name="title" content={title} />
<meta name="description" content={description} />
<SpeedInsights />
---
import SpeedInsights from '@vercel/speed-insights/astro';
const { title, description } = Astro.props;
---
<title>{title}</title>
<meta name="title" content={title} />
<meta name="description" content={description} />
<SpeedInsights />
Optional: Remove Sensitive Information
You can remove sensitive information from URLs by adding a speedInsightsBeforeSend function:
- TypeScript
- JavaScript
---
import SpeedInsights from '@vercel/speed-insights/astro';
const { title, description } = Astro.props;
---
<title>{title}</title>
<meta name="title" content={title} />
<meta name="description" content={description} />
<script is:inline>
function speedInsightsBeforeSend(data) {
console.log('Speed Insights before send', data);
return data;
}
</script>
<SpeedInsights />
---
import SpeedInsights from '@vercel/speed-insights/astro';
const { title, description } = Astro.props;
---
<title>{title}</title>
<meta name="title" content={title} />
<meta name="description" content={description} />
<script is:inline>
function speedInsightsBeforeSend(data) {
console.log('Speed Insights before send', data);
return data;
}
</script>
<SpeedInsights />
HTML (Vanilla JavaScript)
Add the following scripts before the closing </body> tag:
<script>
window.si = window.si || function () { (window.siq = window.siq || []).push(arguments); };
</script>
<script defer src="/_vercel/speed-insights/script.js"></script>
Other Frameworks
For frameworks not explicitly listed, use the generic integration:
- TypeScript
- JavaScript
import { injectSpeedInsights } from '@vercel/speed-insights';
injectSpeedInsights();
import { injectSpeedInsights } from '@vercel/speed-insights';
injectSpeedInsights();
This should only be called once in your app and must run in the client.
Step 4: Deploy Your App to Vercel
Deploy your app to Vercel's global CDN by running the following command from your terminal:
vercel deploy
Alternatively, you can connect your project's git repository, which will enable Vercel to deploy your latest pushes and merges to main.
Once your app is deployed, it's ready to begin tracking performance metrics.
If everything is set up correctly, you should be able to find the /_vercel/speed-insights/script.js script inside the body tag of your page.
Step 5: View Your Data in the Dashboard
Once your app is deployed and users have visited your site, you can view the data in the dashboard.
To do so:
- Go to your Vercel dashboard
- Select your project
- Click the Speed Insights tab
After a few days of visitors, you'll be able to start exploring your metrics.
Privacy and Compliance
Learn more about how Vercel supports privacy and data compliance standards with Vercel Speed Insights.
Next Steps
Now that you have Vercel Speed Insights set up, you can explore the following topics to learn more:
- Learn how to use the
@vercel/speed-insightspackage - Learn about metrics
- Read about privacy and compliance
- Explore pricing
- Troubleshooting
Key Takeaways
- Speed Insights provides real-time performance monitoring for web applications
- Integration is framework-specific but follows similar patterns across platforms
- The tracking script runs client-side and reports Core Web Vitals to Vercel
- Setup requires enabling in the Vercel dashboard, installing the package, integrating the component, and deploying
- Data becomes available in the dashboard after users visit your deployed site
Related Documentation:
- Fast Feedback - Learn about monitoring and observability practices
- Software Delivery Performance - Understand metrics-driven delivery optimization