vercel-analytics — Claude Code command: what it does, how to install
Configures Vercel Analytics and Speed Insights for React and Vite projects. It installs packages, inserts tracking components, and writes SPA routing rules in vercel.json.
npx claude-code-templates@latest --command setup/vercel-analyticsWhat vercel-analytics does
The command automates metrics setup for single-page applications built with React, Vite, or Create React App. It runs npm install for @vercel/analytics and @vercel/speed-insights. Next, it searches for the entry file. It checks src/App.tsx, src/App.jsx, src/main.tsx, and src/main.jsx.
It inserts the Analytics and SpeedInsights components directly into the detected app file. Because the setup explicitly references /react import subpaths, it will not work for Next.js applications. The command also writes a vercel.json configuration file with a rewrite rule sending all traffic to /index.html. That stops 404 errors when visitors open nested SPA routes directly.
Finally, the tool confirms the imports and checks the configuration format. Deploying requires running vercel deploy once the command finishes.
What it helps with
- configure Vercel Analytics and Speed Insights tracking for a React SPA
- generate vercel.json rewrites to prevent 404 errors on direct route access
- insert analytics components into App.tsx or main.tsx automatically
- install @vercel/analytics and @vercel/speed-insights npm packages
Example prompts for the agent
- /vercel-analytics
- Set up Vercel Analytics and Speed Insights for this project with /vercel-analytics
How to install vercel-analytics
1claude-code-templates
npx claude-code-templates@latest --command setup/vercel-analytics2Manually: put the files in place
.claude/commands/vercel-analytics.mdCall it with /vercel-analytics. For all projects use ~/.claude/commands/
Manually: put the files in place
~/.codex/prompts/vercel-analytics.mdCall it with /prompts:vercel-analytics. Codex marks this format deprecated in favour of skills
Manually: put the files in place
.github/prompts/vercel-analytics.prompt.mdManually: put the files in place
.gemini/commands/vercel-analytics.tomlGemini stores commands as TOML: the prompt text goes into the prompt field
Questions about vercel-analytics
How to install vercel-analytics in Claude Code?
Run npx claude-code-templates@latest --command setup/vercel-analytics in your terminal. This adds the command file to .claude/commands/vercel-analytics.md.
What does vercel-analytics do?
It installs Vercel analytics dependencies, integrates tracking components into your React entry file, and creates a vercel.json file for SPA routing.
Why does vercel-analytics generate a vercel.json file?
It configures URL rewrites to send all paths to index.html. This prevents 404 errors when users refresh or directly access nested client-side routes on Vercel.
Source text
vercel-analytics.md · MIT
---
allowed-tools: Read, Write, Edit, Bash
argument-hint:
description: Set up Vercel Analytics and Speed Insights for React/Vite projects
---
# Vercel Analytics Setup
Automatically configure Vercel Analytics and Speed Insights for your React/Vite project.
**Usage:** `/vercel-analytics` (no arguments needed)
**What it does:**
- Installs @vercel/analytics and @vercel/speed-insights packages
- Adds components to your React app
- Configures SPA routing for Vercel deployment
- Fixes 404 errors for direct route access
**Process:**
1. **Install Vercel Packages**
```bash
npm install @vercel/analytics @vercel/speed-insights
```
2. **Detect Main App File**
- Search for main React entry point:
- `src/App.tsx` or `src/App.jsx`
- `src/main.tsx` or `src/main.jsx`
- Read file to determine current structure
3. **Add Analytics Components**
- Import Analytics from '@vercel/analytics/react'
- Import SpeedInsights from '@vercel/speed-insights/react'
- Add both components to the main App component
- Use `/react` imports (not `/next`)
4. **Create vercel.json Configuration**
- Create `vercel.json` in project root
- Add SPA rewrite rules:
```json
{
"rewrites": [
{ "source": "/(.*)", "destination": "/index.html" }
]
}
```
- This ensures all routes serve index.html (fixes 404s)
5. **Verify Setup**
- Confirm components are properly imported
- Check vercel.json exists and is valid
- Display success message with next steps
**Expected Outcome:**
- ✅ Analytics tracking active
- ✅ Speed Insights monitoring configured
- ✅ SPA routing works correctly on Vercel
- ✅ No 404 errors on direct route access
**Next Steps:**
1. Deploy to Vercel: `vercel deploy`
2. View analytics at: https://vercel.com/dashboard/analytics
3. Check Speed Insights: https://vercel.com/dashboard/speed-insights
**Note**: Works with React, Vite, Create React App, and other SPA frameworks.
© davila7 · MIT · davila7/claude-code-templates