Skip to content

Add Vercel Web Analytics integration - #1

Draft
vercel[bot] wants to merge 1 commit into
masterfrom
vercel/vercel-web-analytics-integrati-4k1div
Draft

Add Vercel Web Analytics integration#1
vercel[bot] wants to merge 1 commit into
masterfrom
vercel/vercel-web-analytics-integrati-4k1div

Conversation

@vercel

@vercel vercel Bot commented Feb 10, 2026

Copy link
Copy Markdown

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

View Project · Web Analytics

Created by 1nuoiscute with Vercel Agent

# 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>
@vercel

vercel Bot commented Feb 10, 2026

Copy link
Copy Markdown
Author

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

Project Deployment Actions Updated (UTC)
1nuo-blog Ready Ready Preview, Comment Feb 10, 2026 11:34am

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.

0 participants