Skip to content

Install Vercel Web Analytics - #4

Merged
shubham-lohan merged 1 commit into
masterfrom
vercel/install-vercel-web-analytics-ya01em
Jun 15, 2026
Merged

shubham-lohan merged 1 commit into
masterfrom
vercel/install-vercel-web-analytics-ya01em

Conversation

@vercel

@vercel vercel Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Vercel Web Analytics Implementation Report

Summary

Successfully installed and configured Vercel Web Analytics for the leetcode-visualiser project.

Changes Made

Modified Files:

  • app/templates/base.html - Added Vercel Web Analytics script tags

Implementation Details

Framework Analysis

This project is a FastAPI Python application that serves HTML templates using Jinja2. All pages extend from base.html, making it the ideal location for analytics integration.

Analytics Integration Approach

Following the official Vercel Analytics documentation (https://vercel.com/docs/analytics/quickstart), I implemented the vanilla JavaScript approach recommended for HTML/non-framework applications:

  1. Analytics Initialization Script: Added the window.va function initialization that queues analytics events before the main script loads
  2. Analytics Script Import: Added the deferred script tag pointing to /_vercel/insights/script.js, which is the Vercel-managed analytics endpoint

Code Added to base.html

<!-- Vercel Web Analytics -->
<script>
    window.va = window.va || function () { (window.vaq = window.vaq || []).push(arguments); };
</script>
<script defer src="/_vercel/insights/script.js"></script>

The script was placed in the <head> section after Google Analytics and before the theme initialization script, ensuring proper load order.

Key Points

  1. No npm package installation needed: For Python/FastAPI applications serving HTML templates, the vanilla JavaScript approach with CDN script is the correct implementation method. No @vercel/analytics npm package is required.

  2. Placement: The analytics code is in base.html, which is extended by all other templates (index.html, compare.html), ensuring analytics tracking across all pages.

  3. Performance: The defer attribute ensures the analytics script doesn't block page rendering.

  4. Compatibility: This implementation is framework-agnostic and works with the existing FastAPI/Jinja2 setup without any additional dependencies.

Next Steps for Deployment

After deploying to Vercel:

  1. Enable Web Analytics in the Vercel dashboard for this project
  2. Visit the deployed site and check browser Network tab for requests to /_vercel/insights/ endpoints
  3. Analytics data will appear in the Vercel dashboard after the feature is enabled

Verification

The HTML structure remains valid with proper closing tags, and the analytics script follows Vercel's official documentation for non-framework HTML applications.


View Project · Web Analytics

Created by shubhamlohan99-1076 with Vercel Agent

# Vercel Web Analytics Implementation Report

## Summary
Successfully installed and configured Vercel Web Analytics for the leetcode-visualiser project.

## Changes Made

### Modified Files:
- **app/templates/base.html** - Added Vercel Web Analytics script tags

## Implementation Details

### Framework Analysis
This project is a FastAPI Python application that serves HTML templates using Jinja2. All pages extend from `base.html`, making it the ideal location for analytics integration.

### Analytics Integration Approach
Following the official Vercel Analytics documentation (https://vercel.com/docs/analytics/quickstart), I implemented the vanilla JavaScript approach recommended for HTML/non-framework applications:

1. **Analytics Initialization Script**: Added the `window.va` function initialization that queues analytics events before the main script loads
2. **Analytics Script Import**: Added the deferred script tag pointing to `/_vercel/insights/script.js`, which is the Vercel-managed analytics endpoint

### Code Added to base.html
```html
<!-- Vercel Web Analytics -->
<script>
    window.va = window.va || function () { (window.vaq = window.vaq || []).push(arguments); };
</script>
<script defer src="/_vercel/insights/script.js"></script>
```

The script was placed in the `<head>` section after Google Analytics and before the theme initialization script, ensuring proper load order.

## Key Points

1. **No npm package installation needed**: For Python/FastAPI applications serving HTML templates, the vanilla JavaScript approach with CDN script is the correct implementation method. No `@vercel/analytics` npm package is required.

2. **Placement**: The analytics code is in `base.html`, which is extended by all other templates (`index.html`, `compare.html`), ensuring analytics tracking across all pages.

3. **Performance**: The `defer` attribute ensures the analytics script doesn't block page rendering.

4. **Compatibility**: This implementation is framework-agnostic and works with the existing FastAPI/Jinja2 setup without any additional dependencies.

## Next Steps for Deployment

After deploying to Vercel:
1. Enable Web Analytics in the Vercel dashboard for this project
2. Visit the deployed site and check browser Network tab for requests to `/_vercel/insights/` endpoints
3. Analytics data will appear in the Vercel dashboard after the feature is enabled

## Verification

The HTML structure remains valid with proper closing tags, and the analytics script follows Vercel's official documentation for non-framework HTML applications.

Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
@vercel

vercel Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Project Deployment Actions Updated (UTC)
leetcode-visualiser Ready Ready Preview, Comment Jun 15, 2026 3:12pm

@shubham-lohan
shubham-lohan marked this pull request as ready for review June 15, 2026 15:14
Copilot AI review requested due to automatic review settings June 15, 2026 15:14
@shubham-lohan
shubham-lohan merged commit a6a7189 into master Jun 15, 2026
3 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Vercel Web Analytics tracking to the FastAPI/Jinja2 app by injecting the Vercel Insights snippet into the shared base.html template so it loads on all pages.

Changes:

  • Add window.va queue initializer to support early event buffering
  • Load the Vercel-managed Insights script via /_vercel/insights/script.js with defer

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/templates/base.html
Comment on lines +96 to +100
<!-- Vercel Web Analytics -->
<script>
window.va = window.va || function () { (window.vaq = window.vaq || []).push(arguments); };
</script>
<script defer src="/_vercel/insights/script.js"></script>

This branch was successfully deployed

1 active deployment
Preview — e48cf75b Deployed Jun 15, 2026 by vercel[bot]
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.

2 participants