Tutorial

Vercel Web Analytics Quickstart

Vercel Web Analytics provides you detailed insights into your website's visitors. This quickstart guide will help you get started with using Analytics on Vercel.
Table of Contents

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

To start tracking visitors and page views with Web Analytics, use the following steps:

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

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

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

    pnpm
    yarn
    npm
    pnpm i @vercel/analytics
  3. 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:

    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>
      );
    }
  4. Deploy your app using the following command:

    terminal
    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.

    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.

  5. 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.

Last updated on August 7, 2024