Add Vercel Web Analytics integration#185

draft1
main
vercel/vercel-web-analytics-integrati-1xwir8
opened23h agobyVvercelBot
View on GitHubTwo-way sync enabledPR last imported 18h ago

Vercel Web Analytics Installation

Successfully installed and configured Vercel Web Analytics for the Astro website project.

What Was Done

1. Documentation Review

Fetched the latest official Vercel Web Analytics quickstart guide from https://vercel.com/docs/analytics/quickstart to ensure up-to-date installation instructions.

2. Project Analysis

  • Identified the project as an Astro static site (output: "static" in astro.config.mjs)
  • Found that @vercel/analytics package (v2.0.1) was already listed in website/package.json but not installed
  • Discovered that the Analytics component was already properly imported and integrated in website/src/pages/index.astro

3. Installation

Ran npm install in the website directory to install the @vercel/analytics package and update the lock file.

4. Verification

The implementation already follows the official Astro documentation:

  • Import: import Analytics from "@vercel/analytics/astro";
  • Usage: <Analytics /> component placed in the body section of index.astro
  • This is the correct approach for Astro static sites

5. Testing

  • Successfully built the project with npm run build
  • Build completed without errors in ~97 seconds
  • Generated static output in dist/ directory with optimized images

Files Modified

  • website/package-lock.json - Updated with resolved dependencies for @vercel/analytics and its peer dependencies

Implementation Details

The Vercel Web Analytics implementation uses the Astro-specific integration:

  • Package: @vercel/analytics v2.0.1
  • Import path: @vercel/analytics/astro
  • Component placement: In the body section of the main layout page

The Analytics component:

  • Is cookieless and privacy-focused
  • Only sends data when deployed on Vercel with Analytics enabled
  • Returns 404 for the script in local/non-Vercel environments
  • Automatically routes through /_vercel/insights/* endpoints in production

Next Steps

To activate the analytics:

  1. Enable Web Analytics in the Vercel dashboard (Analytics section)
  2. Deploy the site to Vercel
  3. Verify tracking by checking browser Network tab for requests to /_vercel/insights/view

No additional configuration or environment variables are required.


View Project · Web Analytics

Created by Screen (zaid-gd) with Vercel Agent


View with [code]smith Autofix with [code]smith Need help on this PR? Tag @codesmith-bot with what you need.

Checks

3 successful · 4 skipped
All checks passed
c8f1373

Added 1 commit

  • Add Vercel Web Analytics integrationc8f1373
Synced from GitHub

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

yaml
1reviews:
2 auto_review:
3 drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts