Install Vercel Web Analytics integration - #33
Merged
Conversation
# Vercel Web Analytics Installation
Successfully installed and configured Vercel Web Analytics for this SvelteKit project following the latest official documentation.
## Changes Made
### 1. Package Installation
- **Modified**: `package.json`
- Added `@vercel/analytics` version `^2.0.1` to dependencies
- **Modified**: `package-lock.json`
- Updated lockfile with the analytics package and its dependencies
### 2. Analytics Configuration
- **Modified**: `src/routes/+layout.ts`
- Added import for `dev` from `$app/environment` to detect development mode
- Added import for `injectAnalytics` from `@vercel/analytics/sveltekit`
- Called `injectAnalytics({ mode: dev ? 'development' : 'production' })` at the module level
## Implementation Details
The integration follows the official Vercel Analytics documentation for SvelteKit:
- Used `injectAnalytics()` function which is the recommended approach for SvelteKit
- Configured to run in development mode locally and production mode when deployed
- Added at the root layout level to ensure analytics tracks all pages
## Next Steps
To complete the setup:
1. Enable Web Analytics in the Vercel dashboard under the Analytics tab
2. Deploy the application to Vercel
3. After deployment, the analytics will automatically start tracking page views and visitors
4. Verify the setup by checking the browser's Network tab for requests to `/_vercel/insights/*`
## Notes
- The analytics package is installed as a runtime dependency (not devDependency) as it needs to be available in production
- The implementation preserves all existing code structure and only adds the necessary analytics initialization
- No breaking changes to the existing application functionality
Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Contributor
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 Installation
Successfully installed and configured Vercel Web Analytics for this SvelteKit project following the latest official documentation.
Changes Made
1. Package Installation
package.json@vercel/analyticsversion^2.0.1to dependenciespackage-lock.json2. Analytics Configuration
src/routes/+layout.tsdevfrom$app/environmentto detect development modeinjectAnalyticsfrom@vercel/analytics/sveltekitinjectAnalytics({ mode: dev ? 'development' : 'production' })at the module levelImplementation Details
The integration follows the official Vercel Analytics documentation for SvelteKit:
injectAnalytics()function which is the recommended approach for SvelteKitNext Steps
To complete the setup:
/_vercel/insights/*Notes
View Project 路 Web Analytics
Created by madeinpierre with Vercel Agent