Skip to content

Install Vercel Web Analytics#21

Draft
vercel[bot] wants to merge 1 commit into
mainfrom
vercel/install-vercel-web-analytics-t4t6g5
Draft

Install Vercel Web Analytics#21
vercel[bot] wants to merge 1 commit into
mainfrom
vercel/install-vercel-web-analytics-t4t6g5

Conversation

@vercel
Copy link
Copy Markdown

@vercel vercel Bot commented May 6, 2026

Implemented Vercel Web Analytics for this project following the official documentation.

Changes Made:

1. Package Installation

  • Added @vercel/[email protected] to dependencies using pnpm
  • Package installed successfully and lock file updated

2. Analytics Initialization (src/main.js)

  • Imported inject function from @vercel/analytics
  • Added analytics initialization call before other app initialization
  • The inject() function automatically detects the environment and starts tracking page views

3. Content Security Policy Update (index.html)

  • Updated CSP script-src directive to allow Vercel Analytics scripts
  • Added https://cdn.vercel-insights.com and https://vercel-insights.com to script sources
  • This enables the analytics scripts to load and execute properly while maintaining security

Implementation Details:

For this vanilla JavaScript + Vite project, I used the inject() method from @vercel/analytics as recommended in the official documentation for non-framework projects. This is the appropriate approach for:

  • Vanilla JS projects
  • Vite-based applications without React/Vue/etc.
  • Projects that bundle their JavaScript

The analytics will:

  • Automatically track page views
  • Work in production mode when deployed to Vercel
  • Respect the existing CSP configuration
  • Not interfere with existing functionality

Verification:

✅ Build completed successfully (no errors)
✅ All tests pass (4/4 tests passing)
✅ Lock file properly updated (pnpm-lock.yaml)
✅ CSP configuration allows analytics scripts while maintaining security

Next Steps:

To enable Web Analytics on Vercel:

  1. Deploy this project to Vercel
  2. Go to your project dashboard on Vercel
  3. Navigate to Analytics tab
  4. Enable Web Analytics
  5. Data will start appearing after deployment and user visits

The analytics will automatically begin collecting data once the project is deployed and analytics is enabled in the Vercel dashboard.


View Project · Web Analytics

Created by ikerperez12 with Vercel Agent

Implemented Vercel Web Analytics for this project following the official documentation.

## Changes Made:

### 1. Package Installation
- Added `@vercel/[email protected]` to dependencies using pnpm
- Package installed successfully and lock file updated

### 2. Analytics Initialization (src/main.js)
- Imported `inject` function from `@vercel/analytics`
- Added analytics initialization call before other app initialization
- The `inject()` function automatically detects the environment and starts tracking page views

### 3. Content Security Policy Update (index.html)
- Updated CSP `script-src` directive to allow Vercel Analytics scripts
- Added `https://cdn.vercel-insights.com` and `https://vercel-insights.com` to script sources
- This enables the analytics scripts to load and execute properly while maintaining security

## Implementation Details:

For this vanilla JavaScript + Vite project, I used the `inject()` method from `@vercel/analytics` as recommended in the official documentation for non-framework projects. This is the appropriate approach for:
- Vanilla JS projects
- Vite-based applications without React/Vue/etc.
- Projects that bundle their JavaScript

The analytics will:
- Automatically track page views
- Work in production mode when deployed to Vercel
- Respect the existing CSP configuration
- Not interfere with existing functionality

## Verification:

✅ Build completed successfully (no errors)
✅ All tests pass (4/4 tests passing)
✅ Lock file properly updated (pnpm-lock.yaml)
✅ CSP configuration allows analytics scripts while maintaining security

## Next Steps:

To enable Web Analytics on Vercel:
1. Deploy this project to Vercel
2. Go to your project dashboard on Vercel
3. Navigate to Analytics tab
4. Enable Web Analytics
5. Data will start appearing after deployment and user visits

The analytics will automatically begin collecting data once the project is deployed and analytics is enabled in the Vercel dashboard.

Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
@vercel
Copy link
Copy Markdown
Author

vercel Bot commented May 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
warp Ready Ready Preview, Comment May 6, 2026 8:58pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants