Add Vercel Web Analytics integration#143
Draft
vercel[bot] wants to merge 1 commit into
Draft
Conversation
# Vercel Web Analytics Implementation Report ## Summary Successfully installed and configured Vercel Web Analytics for this Astro project following the latest official Vercel documentation (https://vercel.com/docs/analytics/quickstart). ## Changes Made ### 1. Package Installation - **Added** `@vercel/analytics` v2.0.1 to package.json - **Added** `@astrojs/vercel` v10.0.7 to package.json (Vercel adapter) - **Updated** package-lock.json with new dependencies ### 2. Astro Configuration (astro.config.mjs) - **Added** Vercel adapter import: `import vercel from '@astrojs/vercel'` - **Configured** output mode as 'static' - **Enabled** Web Analytics in the Vercel adapter configuration: ```javascript adapter: vercel({ webAnalytics: { enabled: true, }, }) ``` - **Added** custom Head component to Starlight configuration - **Added** Vite environment variable definition for VERCEL_ANALYTICS_ID ### 3. Analytics Component Integration #### Created: src/components/Head.astro - **New file** that serves as the custom Head component for Starlight - **Imports** Analytics component from '@vercel/analytics/astro' - **Renders** all head tags from the Starlight route - **Includes** `<Analytics />` component in the head section #### Modified: src/pages/404.astro - **Added** Analytics import - **Added** `<Analytics />` component to the head section #### Modified: src/pages/refund.astro - **Added** Analytics import - **Added** `<Analytics />` component to the head section ## Implementation Details This implementation follows the Astro-specific setup from the official Vercel documentation: 1. **Adapter Configuration**: The Vercel adapter is configured with `webAnalytics.enabled: true`, which automatically injects the necessary analytics scripts when deployed to Vercel. 2. **Analytics Component**: The `@vercel/analytics/astro` component is added to: - The custom Head.astro component (used by all Starlight-generated pages) - Standalone pages like 404.astro and refund.astro 3. **Framework Compatibility**: This setup is specifically designed for Astro and leverages both: - The Vercel adapter's built-in analytics configuration - The explicit Analytics component for maximum compatibility ## Verification The implementation is complete and ready for deployment. Once deployed to Vercel: - Analytics will automatically start tracking page views - Data will be visible in the Vercel Analytics dashboard - No additional environment variables are required (handled automatically by Vercel) ## Next Steps 1. Deploy the application to Vercel using `vercel deploy` 2. Verify analytics tracking by checking the browser's Network tab for requests to `/<unique-path>/view` 3. View analytics data in the Vercel dashboard under Analytics ## Notes - The package `@vercel/analytics` version 2.0.1 is the latest stable version - Both the Vercel adapter (v10.0.7) and the Analytics package come with built-in integration - The implementation uses a dual approach: adapter configuration + explicit component inclusion for comprehensive coverage - All changes preserve existing code structure and follow Astro + Starlight conventions Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Author
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Vercel Web Analytics Implementation Report
Summary
Successfully installed and configured Vercel Web Analytics for this Astro project following the latest official Vercel documentation (https://vercel.com/docs/analytics/quickstart).
Changes Made
1. Package Installation
@vercel/analyticsv2.0.1 to package.json@astrojs/vercelv10.0.7 to package.json (Vercel adapter)2. Astro Configuration (astro.config.mjs)
import vercel from '@astrojs/vercel'3. Analytics Component Integration
Created: src/components/Head.astro
<Analytics />component in the head sectionModified: src/pages/404.astro
<Analytics />component to the head sectionModified: src/pages/refund.astro
<Analytics />component to the head sectionImplementation Details
This implementation follows the Astro-specific setup from the official Vercel documentation:
Adapter Configuration: The Vercel adapter is configured with
webAnalytics.enabled: true, which automatically injects the necessary analytics scripts when deployed to Vercel.Analytics Component: The
@vercel/analytics/astrocomponent is added to:Framework Compatibility: This setup is specifically designed for Astro and leverages both:
Verification
The implementation is complete and ready for deployment. Once deployed to Vercel:
Next Steps
vercel deploy/<unique-path>/viewNotes
@vercel/analyticsversion 2.0.1 is the latest stable versionView Project · Web Analytics
Created by Garrison Snelling (heygarrison) with Vercel Agent