Home
cd ../playbooks
Developer ToolsBeginner

Vercel Analytics & Speed Insights Setup

Wire up Vercel Analytics, Speed Insights, and SPA routing rewrites into a React/Vite project in one pass — including the routing fix most people miss.

5 minutes
By Kanaeru LabsSource
#vercel#analytics#speed-insights#react#vite#spa-routing#monitoring

You add Vercel Analytics, check the dashboard a week later, and it's empty. The package installed fine — you just imported from the wrong entry point, and nothing told you.

Who it's for: React and Vite developers deploying to Vercel, indie hackers wanting traffic data without a heavier analytics stack, solo founders setting up a new SPA, developers debugging a 404-on-refresh bug in production

Example

"Set up Vercel Analytics for this Vite app" → @vercel/analytics and @vercel/speed-insights installed, both components mounted with the correct /react imports, a vercel.json rewrite rule added so direct route navigation stops 404ing, and a verification pass confirming both actually render

CLAUDE.md Template

New here? 3-minute setup guide → | Already set up? Copy the template below.

# Vercel Analytics & Speed Insights Setup

## Your Role

Wire up Vercel Analytics and Speed Insights into a React/Vite project, and fix the SPA routing gap that causes direct-navigation 404s on Vercel. One-shot setup, not an ongoing workflow.

---

## Tasks

### 1. Install the packages

```bash
npm install @vercel/analytics @vercel/speed-insights
```

### 2. Mount the components

Import from the `/react` entry points — **not** `/next**, even if the project has some Next.js-adjacent tooling. Using the wrong entry point is the most common way this silently does nothing.

```tsx
import { Analytics } from '@vercel/analytics/react';
import { SpeedInsights } from '@vercel/speed-insights/react';
```

Render both inside the root component — typically `src/App.tsx` or `src/main.tsx`, wherever the app's top-level JSX lives:

```tsx
function App() {
  return (
    <>
      {/* existing app content */}
      <Analytics />
      <SpeedInsights />
    </>
  );
}
```

### 3. Fix SPA routing for direct navigation

Vite/React SPAs use client-side routing. Without a rewrite rule, Vercel's server has no idea `/dashboard/settings` should serve `index.html` — a hard refresh or a shared link on any non-root route 404s.

Create `vercel.json` in the project root:

```json
{
  "rewrites": [
    { "source": "/(.*)", "destination": "/index.html" }
  ]
}
```

### 4. Verify

- Confirm `<Analytics />` and `<SpeedInsights />` actually render — check the mounted DOM or network tab for the Vercel script requests
- Deploy (or preview-deploy) and hit a nested route directly by URL, not by clicking through the app — this is the only way to catch a routing regression the dev server won't show you, since Vite's dev server already handles client-side routing correctly regardless of `vercel.json`

---

## Common Mistakes

**Wrong import path.** `/next` imports look almost identical to `/react` imports and won't error — they just don't collect anything. If analytics data never shows up in the Vercel dashboard, check this first.

**Skipping `vercel.json`.** Works perfectly in local dev (Vite handles routing itself), then 404s in production the moment someone refreshes on a non-root route or shares a deep link. This gap only shows up after deploying.

**Testing routing only via in-app navigation.** Clicking links inside the app never exercises the server-side routing path. Always test with a direct URL hit or a hard refresh.

---

## Scope

This is a five-minute setup task, not a monitoring workflow — it configures the two packages and the one routing fix, then stops. It doesn't cover custom event tracking, alerting, or dashboard configuration; those are separate, ongoing concerns outside what this task sets up.
README.md

What This Does

A one-shot setup task for React/Vite projects deploying to Vercel: installs Analytics and Speed Insights, mounts them correctly, and fixes the SPA routing gap that causes 404s when someone refreshes on a non-root route — a bug that only shows up in production, never in local dev.


Quick Start

Step 1: Navigate to Your Project

cd ~/your-vite-project

Step 2: Download the Template

Click Download above, then:

mv ~/Downloads/CLAUDE.md ./

Step 3: Run the Setup

claude

Then ask: "Set up Vercel Analytics and Speed Insights"


What Gets Configured

Component Purpose
@vercel/analytics Page view and visitor tracking
@vercel/speed-insights Core Web Vitals monitoring
vercel.json rewrite rule Serves index.html for all routes, fixing direct-navigation 404s

Tips & Best Practices

  • Import from /react, not /next. The two entry points look nearly identical and neither errors if you pick wrong — the wrong one just silently collects nothing. If the Vercel dashboard stays empty after a deploy, check this first.
  • Test routing with a direct URL hit, not in-app navigation. Vite's dev server already handles client-side routing correctly, so the missing-rewrite bug never shows up locally. Only a hard refresh or a shared link on a nested route — after deploying — will surface it.
  • This is a five-minute task, not an ongoing workflow. It doesn't set up custom event tracking, alerting, or dashboard configuration — just the two packages and the routing fix.

Limitations

  • Scoped to React/Vite projects specifically — Next.js apps use different Vercel Analytics import paths and don't need the vercel.json rewrite (Next.js handles SPA-style routing server-side already)
  • Doesn't cover custom event tracking or alerting — only the base pageview/vitals setup

$Related Playbooks

Developer Tools

Unslop UI: Kill the AI Design Tells

A frontend guardrail built from a 3.2M-post Reddit analysis of what people actually call AI slop, with a build mode that forces design decisions up front and an audit mode that scans existing code for the tells

10 minutes
Intermediate
Developer Tools

Tunnel Doctor

Diagnose and fix conflicts between Tailscale and proxy/VPN tools on macOS — route hijacking, proxy env vars, SSH double-tunneling, and the ~60s DNS resolver stall.

15 minutes
Advanced
Developer Tools

Vibe Coder: Idea to Prototype

Describe what you want to build and get clean, working code with a simple approach explanation, setup instructions, and optional improvements — optimized for shipping over perfecting.

5 minutes
Beginner
Developer Tools

Who Built This Before Me

Check whether your project, tool, library, or product idea has already been built — before you invest a weekend or a quarter in it.

5 minutes
Intermediate
Developer Tools

Vibe Skill Creator

Build world-class Claude skills through a guided 10-step conversation — explore where Claude fails by default, research the domain, draft, self-critique, test on a real scenario, and iterate until the skill actually improves output.

10 minutes
Intermediate
Developer Tools

Twilio SMS Integration

Automate SMS communications, two-way messaging, notifications, and voice workflows with Twilio

10 minutes
Advanced
Developer Tools

Webhook Automation Builder

Build and manage webhook-based integrations for real-time event processing and API connections

10 minutes
Advanced
Developer Tools

Web App Testing

Test local web applications with Playwright automation for frontend verification, UI debugging, and screenshot capture.

15 minutes
Intermediate
Developer Tools

Tech Debt Analyzer

Identify, analyze, document, and track technical debt in JavaScript/TypeScript codebases with automated detection and prioritized remediation plans.

10 minutes
Intermediate
Developer Tools

Agent SDK App Builder

Scaffold new Claude Agent SDK applications in TypeScript or Python, and verify existing ones against official SDK patterns before you ship.

10 minutes
Intermediate
Developer Tools

AI Agent Builder

Build AI agents with tools, memory, and multi-step reasoning - ChatGPT, Claude, Gemini integration patterns

10 minutes
Advanced
Developer Tools

Automated PR Code Review

High-signal automated PR review using parallel agents with a validation pass that filters out false positives before anything gets posted.

10 minutes
Advanced

Browse all Developer Tools playbooks →