Getting Started with Vercel Web Analytics

This guide will help you get started with using Vercel Web Analytics 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.

Select your framework to view instructions on using Vercel Web Analytics in your project.

Prerequisites

pnpm i vercel
yarn i vercel
npm i vercel
bun i vercel

Enable Web Analytics in Vercel

On the Vercel dashboard, select your Project and then click the Analytics tab and click Enable from the dialog.

💡 Note: Enabling Web Analytics will add new routes (scoped at /_vercel/insights/*) after your next deployment.

Add @vercel/analytics to Your Project

Using the package manager of your choice, add the @vercel/analytics package to your project:

pnpm i @vercel/analytics
yarn i @vercel/analytics
npm i @vercel/analytics
bun i @vercel/analytics

Add the Analytics Component to Your App

The implementation depends on your framework. Select your framework below:

Next.js (Pages Directory)

The Analytics component is a wrapper around the tracking script, offering more seamless integration with Next.js, including route support.

If you are using the pages directory, add the following code to your main app file:

TypeScript (pages/_app.tsx)

import type { AppProps } from "next/app";
import { Analytics } from "@vercel/analytics/next";

function MyApp({ Component, pageProps }: AppProps) {
  return (
    <>
      <Component {...pageProps} />
      <Analytics />
    </>
  );
}

export default MyApp;

JavaScript (pages/_app.js)

import { Analytics } from "@vercel/analytics/next";

function MyApp({ Component, pageProps }) {
  return (
    <>
      <Component {...pageProps} />
      <Analytics />
    </>
  );
}

export default MyApp;

Next.js (App Directory)

The Analytics component is a wrapper around the tracking script, offering more seamless integration with Next.js, including route support.

Add the following code to the root layout:

TypeScript (app/layout.tsx)

import { Analytics } from "@vercel/analytics/next";

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <head>
        <title>Next.js</title>
      </head>
      <body>
        {children}
        <Analytics />
      </body>
    </html>
  );
}

JavaScript (app/layout.jsx)

import { Analytics } from "@vercel/analytics/next";

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <head>
        <title>Next.js</title>
      </head>
      <body>
        {children}
        <Analytics />
      </body>
    </html>
  );
}

Remix

The Analytics component is a wrapper around the tracking script, offering a seamless integration with Remix, including route detection.

Add the following code to your root file:

TypeScript (app/root.tsx)

import {
  Links,
  LiveReload,
  Meta,
  Outlet,
  Scripts,
  ScrollRestoration,
} from "@remix-run/react";
import { Analytics } from "@vercel/analytics/remix";

export default function App() {
  return (
    <html lang="en">
      <head>
        <meta charSet="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <Meta />
        <Links />
      </head>
      <body>
        <Analytics />
        <Outlet />
        <ScrollRestoration />
        <Scripts />
        <LiveReload />
      </body>
    </html>
  );
}

JavaScript (app/root.jsx)

import {
  Links,
  LiveReload,
  Meta,
  Outlet,
  Scripts,
  ScrollRestoration,
} from "@remix-run/react";
import { Analytics } from "@vercel/analytics/remix";

export default function App() {
  return (
    <html lang="en">
      <head>
        <meta charSet="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <Meta />
        <Links />
      </head>
      <body>
        <Analytics />
        <Outlet />
        <ScrollRestoration />
        <Scripts />
        <LiveReload />
      </body>
    </html>
  );
}

Create React App

The Analytics component is a wrapper around the tracking script, offering more seamless integration with React.

Note: When using the plain React implementation, there is no route support.

Add the following code to the main app file:

TypeScript (App.tsx)

import { Analytics } from "@vercel/analytics/react";

export default function App() {
  return (
    <div>
      {/* ... */}
      <Analytics />
    </div>
  );
}

JavaScript (App.jsx)

import { Analytics } from "@vercel/analytics/react";

export default function App() {
  return (
    <div>
      {/* ... */}
      <Analytics />
    </div>
  );
}

Vue

The Analytics component is a wrapper around the tracking script, offering more seamless integration with Vue.

Note: Route support is automatically enabled if you're using vue-router.

Add the following code to your main component:

TypeScript (src/App.vue)

<script setup lang="ts">
import { Analytics } from '@vercel/analytics/vue';
</script>

<template>
  <Analytics />
  <!-- your content -->
</template>

JavaScript (src/App.vue)

<script setup>
import { Analytics } from '@vercel/analytics/vue';
</script>

<template>
  <Analytics />
  <!-- your content -->
</template>

Deploy Your App to Vercel

Deploy your app using the following command:

vercel deploy

If you haven't already, we also recommend connecting your project's Git repository, which will enable Vercel to deploy your latest commits to main without terminal commands.

Once your app is deployed, it will start tracking visitors and page views.

💡 Note: If everything is set up properly, you should be able to see a Fetch/XHR request in your browser's Network tab from /_vercel/insights/view when you visit any page.

View Your Data in the Dashboard

Once your app is deployed, and users have visited your site, you can view your data in the dashboard.

To do so, go to your dashboard, select your project, and click the Analytics tab.

After a few days of visitors, you'll be able to start exploring your data by viewing and filtering the panels.

Users on Pro and Enterprise plans can also add custom events to their data to track user interactions such as button clicks, form submissions, or purchases.

Learn more about how Vercel supports privacy and data compliance standards with Vercel Web Analytics.

Next Steps

Now that you have Vercel Web Analytics set up, you can explore the following topics to learn more: