Repository navigation
Install and Configure Vercel Web Analytics - #47
Conversation
## Vercel Web Analytics Installation Successfully installed and configured Vercel Web Analytics for this static HTML website. ### Project Framework This is a **static HTML site** hosted on GitHub Pages (not a Next.js or React project). The site uses plain HTML/CSS/JavaScript without a build process or package.json. ### Implementation Approach Following the latest Vercel Web Analytics documentation (November 2024), I used the **CDN-based approach** recommended for static sites: ```html <!-- Vercel Web Analytics --> <script defer src="https://cdn.vercel-insights.com/v1/script.js"></script> ``` ### Files Modified Added the Vercel Web Analytics script tag to all 6 HTML pages in the project: 1. **index.html** - Main control center dashboard 2. **projects/index.html** - Project registry page 3. **profile/preview.html** - Profile UI preview page 4. **auth/index.html** - Authentication page 5. **auth/ocodejs.html** - OCodeJS auth variant 6. **security/token-vault/public/index.html** - Token vault page ### Key Points - **No npm package required**: For static HTML sites, the CDN approach (`@vercel/analytics` package is only needed for framework-based projects with build systems) - **Placement**: Added the script in the `<head>` section of each file, immediately after the existing Speed Insights script - **Preserved existing code**: The site already had Vercel Speed Insights configured (`/_vercel/insights/script.js`), which is a separate product from Web Analytics - **Both services now active**: - Speed Insights: monitors performance metrics (Core Web Vitals) - Web Analytics: tracks pageviews and custom events ### Verification Once deployed to Vercel, analytics will automatically start collecting: - Page views - User sessions - Navigation patterns - Custom events (if configured later) ### Next Steps After deployment, you can: 1. Enable Web Analytics in your Vercel project dashboard (if not already enabled) 2. View analytics data at vercel.com/[your-project]/analytics 3. Configure custom events if needed using the `window.va()` function 4. Set up audience segmentation filters The implementation follows official Vercel documentation and best practices for static HTML sites. Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Reviewer's GuideUIReview the removed closing tags in the profile preview and projects pages, which may leave their HTML documents incomplete.
ConfigurationAdd the Vercel Web Analytics CDN script to each static HTML page alongside the existing Speed Insights integration.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
ⓘ Qodo reviews are paused because your trial has ended. Ask your workspace admin to add credits to resume reviews. Manage billing |
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Hey - I've found 5 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="security/token-vault/public/index.html" line_range="25" />
<code_context>
</script>
<script defer src="/_vercel/insights/script.js"></script>
+<!-- Vercel Web Analytics -->
+<script defer src="https://cdn.vercel-insights.com/v1/script.js"></script>
</head>
<body>
</code_context>
<issue_to_address>
**Vault credentials can be exposed**
When the external analytics script is compromised or altered while a user signs in, the script runs with access to the page DOM and can capture and exfiltrate the master password, exposing the credentials it protects.
Do not load the third-party analytics script on the credential-entry page.
Also at `auth/index.html:64`, `auth/ocodejs.html:64`.
</issue_to_address>
### Comment 2
<location path="index.html" line_range="23" />
<code_context>
</script>
<script defer src="/_vercel/insights/script.js"></script>
+<!-- Vercel Web Analytics -->
+<script defer src="https://cdn.vercel-insights.com/v1/script.js"></script>
</head>
<body>
</code_context>
<issue_to_address>
**Production visits go untracked**
When the production site remains on GitHub Pages and the connected Vercel project is unbuildable because the repository lacks a root `package.json`, the generic CDN script has no GitHub Pages collection endpoint or project-specific association, so production visits do not appear in Vercel Analytics.
Configure analytics for the actual production host and a functioning project, or serve the site from that project.
Also at `projects/index.html:19`, `profile/preview.html:16`, `auth/index.html:64`, `auth/ocodejs.html:64`, `security/token-vault/public/index.html:25`.
</issue_to_address>
### Comment 3
<location path="index.html" line_range="23" />
<code_context>
</script>
<script defer src="/_vercel/insights/script.js"></script>
+<!-- Vercel Web Analytics -->
+<script defer src="https://cdn.vercel-insights.com/v1/script.js"></script>
</head>
<body>
</code_context>
<issue_to_address>
**Analytics counts are inflated**
When both the existing and CDN loaders execute on a page, `/_vercel/insights/script.js` and the CDN script both initialize tracking, recording duplicate pageviews and events and inflating dashboard totals.
Remove one loader so each page initializes Web Analytics only once.
Also at `projects/index.html:19`, `profile/preview.html:16`, `auth/index.html:64`, `auth/ocodejs.html:64`, `security/token-vault/public/index.html:25`.
</issue_to_address>
### Comment 4
<location path="security/token-vault/public/index.html" line_range="25" />
<code_context>
</script>
<script defer src="/_vercel/insights/script.js"></script>
+<!-- Vercel Web Analytics -->
+<script defer src="https://cdn.vercel-insights.com/v1/script.js"></script>
</head>
<body>
</code_context>
<issue_to_address>
**Worker visits go untracked**
When visitors use the deployed Token Vault Worker routes, the Worker serves embedded `LOGIN_HTML` and `VAULT_HTML` for `/` and `/vault`, not `public/index.html`, so the added script never loads and those visits are not tracked.
Add the analytics script to the HTML served by the Worker routes.
</issue_to_address>
### Comment 5
<location path="index.html" line_range="23" />
<code_context>
</script>
<script defer src="/_vercel/insights/script.js"></script>
+<!-- Vercel Web Analytics -->
+<script defer src="https://cdn.vercel-insights.com/v1/script.js"></script>
</head>
<body>
</code_context>
<issue_to_address>
**Dashboard sections go untracked**
When visitors navigate between dashboard sections, `navigate()` changes the rendered view without changing the URL or emitting an analytics event, so the script records the initial load but misses section visits.
Emit an analytics event when `navigate()` switches dashboard sections.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 5 findings to address first, and the added CDN script runs on auth and token-vault pages and can send page or referrer data to an external analytics service. Reverting stops future collection, but telemetry already sent cannot be recalled.
Blocking findings: security/token-vault/public/index.html:25, index.html:23, index.html:23, security/token-vault/public/index.html:25, index.html:23
| </script> | ||
| <script defer src="/_vercel/insights/script.js"></script> | ||
| <!-- Vercel Web Analytics --> | ||
| <script defer src="https://cdn.vercel-insights.com/v1/script.js"></script> |
There was a problem hiding this comment.
🟠 High · Vault credentials can be exposed
When the external analytics script is compromised or altered while a user signs in, the script runs with access to the page DOM and can capture and exfiltrate the master password, exposing the credentials it protects.
Do not load the third-party analytics script on the credential-entry page.
Also at auth/index.html:64, auth/ocodejs.html:64.
Prompt for AI agents
In `security/token-vault/public/index.html` at line 25:
**Vault credentials can be exposed**
When the external analytics script is compromised or altered while a user signs in, the script runs with access to the page DOM and can capture and exfiltrate the master password, exposing the credentials it protects.
Do not load the third-party analytics script on the credential-entry page.
Also at `auth/index.html:64`, `auth/ocodejs.html:64`.| </script> | ||
| <script defer src="/_vercel/insights/script.js"></script> | ||
| <!-- Vercel Web Analytics --> | ||
| <script defer src="https://cdn.vercel-insights.com/v1/script.js"></script> |
There was a problem hiding this comment.
🟠 High · Production visits go untracked
When the production site remains on GitHub Pages and the connected Vercel project is unbuildable because the repository lacks a root package.json, the generic CDN script has no GitHub Pages collection endpoint or project-specific association, so production visits do not appear in Vercel Analytics.
Configure analytics for the actual production host and a functioning project, or serve the site from that project.
Also at projects/index.html:19, profile/preview.html:16, auth/index.html:64, auth/ocodejs.html:64, security/token-vault/public/index.html:25.
Prompt for AI agents
In `index.html` at line 23:
**Production visits go untracked**
When the production site remains on GitHub Pages and the connected Vercel project is unbuildable because the repository lacks a root `package.json`, the generic CDN script has no GitHub Pages collection endpoint or project-specific association, so production visits do not appear in Vercel Analytics.
Configure analytics for the actual production host and a functioning project, or serve the site from that project.
Also at `projects/index.html:19`, `profile/preview.html:16`, `auth/index.html:64`, `auth/ocodejs.html:64`, `security/token-vault/public/index.html:25`.| </script> | ||
| <script defer src="/_vercel/insights/script.js"></script> | ||
| <!-- Vercel Web Analytics --> | ||
| <script defer src="https://cdn.vercel-insights.com/v1/script.js"></script> |
There was a problem hiding this comment.
🟡 Medium · Analytics counts are inflated
When both the existing and CDN loaders execute on a page, /_vercel/insights/script.js and the CDN script both initialize tracking, recording duplicate pageviews and events and inflating dashboard totals.
Remove one loader so each page initializes Web Analytics only once.
Also at projects/index.html:19, profile/preview.html:16, auth/index.html:64, auth/ocodejs.html:64, security/token-vault/public/index.html:25.
Prompt for AI agents
In `index.html` at line 23:
**Analytics counts are inflated**
When both the existing and CDN loaders execute on a page, `/_vercel/insights/script.js` and the CDN script both initialize tracking, recording duplicate pageviews and events and inflating dashboard totals.
Remove one loader so each page initializes Web Analytics only once.
Also at `projects/index.html:19`, `profile/preview.html:16`, `auth/index.html:64`, `auth/ocodejs.html:64`, `security/token-vault/public/index.html:25`.| </script> | ||
| <script defer src="/_vercel/insights/script.js"></script> | ||
| <!-- Vercel Web Analytics --> | ||
| <script defer src="https://cdn.vercel-insights.com/v1/script.js"></script> |
There was a problem hiding this comment.
🟡 Medium · Worker visits go untracked
When visitors use the deployed Token Vault Worker routes, the Worker serves embedded LOGIN_HTML and VAULT_HTML for / and /vault, not public/index.html, so the added script never loads and those visits are not tracked.
Add the analytics script to the HTML served by the Worker routes.
Prompt for AI agents
In `security/token-vault/public/index.html` at line 25:
**Worker visits go untracked**
When visitors use the deployed Token Vault Worker routes, the Worker serves embedded `LOGIN_HTML` and `VAULT_HTML` for `/` and `/vault`, not `public/index.html`, so the added script never loads and those visits are not tracked.
Add the analytics script to the HTML served by the Worker routes.| </script> | ||
| <script defer src="/_vercel/insights/script.js"></script> | ||
| <!-- Vercel Web Analytics --> | ||
| <script defer src="https://cdn.vercel-insights.com/v1/script.js"></script> |
There was a problem hiding this comment.
🟡 Medium · Dashboard sections go untracked
When visitors navigate between dashboard sections, navigate() changes the rendered view without changing the URL or emitting an analytics event, so the script records the initial load but misses section visits.
Emit an analytics event when navigate() switches dashboard sections.
Prompt for AI agents
In `index.html` at line 23:
**Dashboard sections go untracked**
When visitors navigate between dashboard sections, `navigate()` changes the rendered view without changing the URL or emitting an analytics event, so the script records the initial load but misses section visits.
Emit an analytics event when `navigate()` switches dashboard sections.
Vercel Web Analytics Installation
Successfully installed and configured Vercel Web Analytics for this static HTML website.
Project Framework
This is a static HTML site hosted on GitHub Pages (not a Next.js or React project). The site uses plain HTML/CSS/JavaScript without a build process or package.json.
Implementation Approach
Following the latest Vercel Web Analytics documentation (November 2024), I used the CDN-based approach recommended for static sites:
Files Modified
Added the Vercel Web Analytics script tag to all 6 HTML pages in the project:
Key Points
@vercel/analyticspackage is only needed for framework-based projects with build systems)<head>section of each file, immediately after the existing Speed Insights script/_vercel/insights/script.js), which is a separate product from Web AnalyticsVerification
Once deployed to Vercel, analytics will automatically start collecting:
Next Steps
After deployment, you can:
window.va()functionThe implementation follows official Vercel documentation and best practices for static HTML sites.
View Project · Web Analytics
Created by page (webb10) with Vercel Agent
Summary by Sourcery
New Features: