Skip to content

Install Vercel Web Analytics - #4

Merged
pietrocious merged 1 commit into
mainfrom
vercel/install-vercel-web-analytics-6eb9ou
Jul 8, 2026
Merged

pietrocious merged 1 commit into
mainfrom
vercel/install-vercel-web-analytics-6eb9ou

Conversation

@vercel

@vercel vercel Bot commented Jul 7, 2026

Copy link
Copy Markdown

Vercel Web Analytics Installation Report

Summary

Successfully installed and configured Vercel Web Analytics for the pietrouni.com project.

Changes Made

1. Package Installation

  • Added dependency: @vercel/analytics v2.0.1
  • Files modified:
    • package.json - Added @vercel/analytics to dependencies
    • package-lock.json - Updated with new dependency tree

2. Analytics Integration

  • File modified: src/main.ts
  • Changes:
    • Added import statement for the inject function from @vercel/analytics
    • Added inject() call in the DOMContentLoaded event handler, right after initTheme()
    • Placed strategically to ensure analytics initializes early in the application lifecycle

3. Implementation Details

Following the official Vercel Web Analytics documentation (https://vercel.com/docs/analytics/quickstart), I used the vanilla JavaScript/Vite approach:

  • Used the inject() function from @vercel/analytics package
  • This is the recommended approach for vanilla TypeScript/JavaScript projects with Vite
  • The inject() function automatically:
    • Initializes the analytics queue
    • Loads the Vercel Analytics script
    • Handles development vs production modes
    • Tracks page views and custom events

4. Verification

✅ Build completed successfully (npm run build)
✅ All tests pass (58 tests across 5 test files)
✅ No TypeScript errors introduced
✅ Lock file updated correctly

Next Steps

To enable Web Analytics in production:

  1. Navigate to your Vercel project dashboard
  2. Go to the Analytics section
  3. Click "Enable Web Analytics"
  4. Deploy this code to Vercel

Once deployed, analytics data will start appearing in the Vercel dashboard, showing:

  • Page views and unique visitors
  • Top pages and referrers
  • Device and browser statistics
  • Geographic distribution of visitors

Technical Notes

  • The analytics script is loaded asynchronously and won't block page rendering
  • In development mode, analytics events are logged but not sent to the server
  • The implementation respects ad blockers and privacy preferences
  • Zero impact on bundle size (script is loaded externally by Vercel)

View Project · Web Analytics

Created by pietrouni-1351 with Vercel Agent

# Vercel Web Analytics Installation Report

## Summary
Successfully installed and configured Vercel Web Analytics for the pietrouni.com project.

## Changes Made

### 1. Package Installation
- **Added dependency**: `@vercel/analytics` v2.0.1
- **Files modified**: 
  - `package.json` - Added @vercel/analytics to dependencies
  - `package-lock.json` - Updated with new dependency tree

### 2. Analytics Integration
- **File modified**: `src/main.ts`
- **Changes**:
  - Added import statement for the `inject` function from `@vercel/analytics`
  - Added `inject()` call in the DOMContentLoaded event handler, right after `initTheme()`
  - Placed strategically to ensure analytics initializes early in the application lifecycle

### 3. Implementation Details
Following the official Vercel Web Analytics documentation (https://vercel.com/docs/analytics/quickstart), I used the vanilla JavaScript/Vite approach:
- Used the `inject()` function from `@vercel/analytics` package
- This is the recommended approach for vanilla TypeScript/JavaScript projects with Vite
- The `inject()` function automatically:
  - Initializes the analytics queue
  - Loads the Vercel Analytics script
  - Handles development vs production modes
  - Tracks page views and custom events

### 4. Verification
✅ Build completed successfully (`npm run build`)
✅ All tests pass (58 tests across 5 test files)
✅ No TypeScript errors introduced
✅ Lock file updated correctly

## Next Steps
To enable Web Analytics in production:
1. Navigate to your Vercel project dashboard
2. Go to the Analytics section
3. Click "Enable Web Analytics"
4. Deploy this code to Vercel

Once deployed, analytics data will start appearing in the Vercel dashboard, showing:
- Page views and unique visitors
- Top pages and referrers
- Device and browser statistics
- Geographic distribution of visitors

## Technical Notes
- The analytics script is loaded asynchronously and won't block page rendering
- In development mode, analytics events are logged but not sent to the server
- The implementation respects ad blockers and privacy preferences
- Zero impact on bundle size (script is loaded externally by Vercel)

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

vercel Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Author

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

Project Deployment Actions Updated (UTC)
pietrouni-com Ready Ready Preview, Comment Jul 7, 2026 6:45am

@pietrocious
pietrocious marked this pull request as ready for review July 8, 2026 13:45
@pietrocious
pietrocious merged commit 36a8569 into main Jul 8, 2026
4 checks passed
@pietrocious
pietrocious deleted the vercel/install-vercel-web-analytics-6eb9ou branch July 8, 2026 13:45

This branch was successfully deployed

1 active deployment
Preview — d0ccc78a Deployed Jul 7, 2026 by vercel[bot]
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.

1 participant