Add Vercel Web Analytics integration - #1
Draft
vercel[bot] wants to merge 1 commit into
Draft
Conversation
# Vercel Web Analytics Implementation ## Summary Successfully implemented Vercel Web Analytics integration for the 1nuo Hexo blog using the Butterfly theme. ## Changes Made ### 1. Added @vercel/analytics Package **File:** `package.json` - Added `@vercel/analytics` version `^1.4.1` to dependencies - This package provides the necessary analytics tracking functionality ### 2. Added Configuration Option **File:** `themes/butterfly/_config.yml` - Added `vercel_analytics` configuration section with `enable` flag (default: false) - Includes documentation link to Vercel's analytics documentation - Placed logically after Google Tag Manager configuration, before the Advertisement section ### 3. Implemented Analytics Script Injection **File:** `themes/butterfly/layout/includes/head/analytics.pug` - Added conditional script injection that activates when `theme.vercel_analytics.enable` is true - Implements the HTML-based Vercel Web Analytics approach as recommended for static sites - Includes two scripts: 1. Initialization script that sets up the `window.va` function 2. Deferred loading of the Vercel insights script from `/_vercel/insights/script.js` - Follows the same pattern as other analytics integrations in the theme ### 4. Updated Dependencies **File:** `package-lock.json` - Updated lockfile to reflect the new @vercel/analytics dependency and its subdependencies - Ensures consistent installation across environments ## Implementation Details The implementation follows Vercel's official documentation for plain HTML sites, which is appropriate for Hexo static site generation. The analytics script will: 1. Only load when explicitly enabled in the theme configuration 2. Use the standard Vercel Web Analytics endpoint (`/_vercel/insights/script.js`) 3. Properly initialize the `window.va` analytics function 4. Load the script with the `defer` attribute for optimal page performance ## How to Use To enable Vercel Web Analytics on this blog: 1. Deploy the site to Vercel 2. Enable Web Analytics in the Vercel dashboard (Project → Analytics → Enable) 3. Set `vercel_analytics.enable: true` in `themes/butterfly/_config.yml` 4. Rebuild and deploy: `npm run build && npm run deploy` Once enabled, the analytics will automatically track: - Page views - Visitor counts - Geographic distribution - Referrer sources - And other standard web analytics metrics ## Testing ✅ Verified the build completes successfully with `npm run build` ✅ Tested with analytics disabled (default) - no script injection ✅ Tested with analytics enabled - proper script injection in generated HTML ✅ Confirmed proper HTML output includes both required scripts ✅ All dependencies installed without issues ✅ No breaking changes to existing functionality ## Notes - The analytics feature is disabled by default to respect user privacy and allow site owners to make an informed decision - The implementation uses the HTML approach (not the npm package approach) as this is most appropriate for Hexo's static site generation - No route detection is available with this implementation (as documented by Vercel for HTML-based integrations) - The analytics will only work once the site is deployed to Vercel and analytics are enabled in the dashboard Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Author
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
1nuoiscute
added a commit
that referenced
this pull request
May 21, 2026
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
Summary
Successfully implemented Vercel Web Analytics integration for the 1nuo Hexo blog using the Butterfly theme.
Changes Made
1. Added @vercel/analytics Package
File:
package.json@vercel/analyticsversion^1.4.1to dependencies2. Added Configuration Option
File:
themes/butterfly/_config.ymlvercel_analyticsconfiguration section withenableflag (default: false)3. Implemented Analytics Script Injection
File:
themes/butterfly/layout/includes/head/analytics.pugtheme.vercel_analytics.enableis truewindow.vafunction/_vercel/insights/script.js4. Updated Dependencies
File:
package-lock.jsonImplementation Details
The implementation follows Vercel's official documentation for plain HTML sites, which is appropriate for Hexo static site generation. The analytics script will:
/_vercel/insights/script.js)window.vaanalytics functiondeferattribute for optimal page performanceHow to Use
To enable Vercel Web Analytics on this blog:
vercel_analytics.enable: trueinthemes/butterfly/_config.ymlnpm run build && npm run deployOnce enabled, the analytics will automatically track:
Testing
✅ Verified the build completes successfully with
npm run build✅ Tested with analytics disabled (default) - no script injection
✅ Tested with analytics enabled - proper script injection in generated HTML
✅ Confirmed proper HTML output includes both required scripts
✅ All dependencies installed without issues
✅ No breaking changes to existing functionality
Notes
View Project · Web Analytics
Created by 1nuoiscute with Vercel Agent