Install Vercel Web Analytics Integration - #6
Draft
vercel[bot] wants to merge 1 commit into
Draft
Conversation
Implemented Vercel Web Analytics for the SCOM project. ## Changes Made Modified: - templates/base.html - Added Vercel Web Analytics script tag to the <head> section ## Implementation Details This is a Python-based FastAPI/Starlette project with Jinja2 HTML templates. Based on the latest official Vercel documentation, I implemented Web Analytics using the recommended approach for HTML-based projects: 1. **Fetched Latest Documentation**: Retrieved the current installation instructions from Vercel's official documentation (https://vercel.com/docs/analytics/quickstart) and examined the official HTML example (https://github.com/vercel/examples/tree/main/solutions/html). 2. **Identified Framework**: Determined that this is a Python FastAPI application serving HTML templates via Jinja2, not a JavaScript framework (Next.js, React, Vue, etc.). 3. **Applied Correct Integration Method**: For non-JavaScript frameworks and HTML-based projects, Vercel Web Analytics is integrated by adding a single script tag to the HTML: ```html <script defer src="/_vercel/insights/script.js"></script> ``` 4. **Added to Base Template**: Inserted the analytics script in the `<head>` section of `templates/base.html`. Since all other templates extend from base.html, this ensures analytics tracking is enabled across the entire website. ## Why This Approach - The `@vercel/analytics` npm package is designed for JavaScript frameworks (Next.js, React, Vue, etc.) - For Python/FastAPI projects with HTML templates, Vercel automatically provides the analytics script at `/_vercel/insights/script.js` when deployed - The script uses the `defer` attribute for optimal loading performance without blocking page rendering - No package manager changes are needed since this is purely a server-side rendered application ## Next Steps After deployment to Vercel: 1. Enable Web Analytics in the Vercel Dashboard (Analytics section → Enable button) 2. Deploy the application to activate analytics tracking 3. Verify tracking by checking browser Network tab for requests to `/_vercel/insights/` 4. View analytics data through the Vercel Dashboard ## Verification - ✓ Python syntax validated successfully - ✓ All templates inherit from base.html, ensuring site-wide coverage - ✓ Script tag follows official Vercel HTML example best practices - ✓ No dependencies to install (pure HTML/script integration) 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.
Implemented Vercel Web Analytics for the SCOM project.
Changes Made
Modified:
Implementation Details
This is a Python-based FastAPI/Starlette project with Jinja2 HTML templates. Based on the latest official Vercel documentation, I implemented Web Analytics using the recommended approach for HTML-based projects:
Fetched Latest Documentation: Retrieved the current installation instructions from Vercel's official documentation (https://vercel.com/docs/analytics/quickstart) and examined the official HTML example (https://github.com/vercel/examples/tree/main/solutions/html).
Identified Framework: Determined that this is a Python FastAPI application serving HTML templates via Jinja2, not a JavaScript framework (Next.js, React, Vue, etc.).
Applied Correct Integration Method: For non-JavaScript frameworks and HTML-based projects, Vercel Web Analytics is integrated by adding a single script tag to the HTML:
Added to Base Template: Inserted the analytics script in the
<head>section oftemplates/base.html. Since all other templates extend from base.html, this ensures analytics tracking is enabled across the entire website.Why This Approach
@vercel/analyticsnpm package is designed for JavaScript frameworks (Next.js, React, Vue, etc.)/_vercel/insights/script.jswhen deployeddeferattribute for optimal loading performance without blocking page renderingNext Steps
After deployment to Vercel:
/_vercel/insights/Verification
View Project · Web Analytics
Created by Mbugua (mbugua) with Vercel Agent