Conversation
Add analytics tracking to all documentation pages using docmd's customJs configuration. The script dynamically loads Vercel's analytics from /_vercel/insights/script.js. - Create assets/js/vercel-analytics.js initialization script - Add customJs config to docmd.config.js
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
Adds Vercel Web Analytics to the documentation site by injecting a custom initialization script via docmd configuration.
Changes:
- Configure docmd to load a custom JavaScript file on all pages.
- Add a client-side script that defines
window.vaand dynamically loads Vercel’s Insights script.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| docmd.config.js | Adds customJs entry to include the Vercel analytics initializer on all doc pages. |
| assets/js/vercel-analytics.js | Initializes window.va and injects /_vercel/insights/script.js at runtime. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| }, | ||
| autoTitleFromH1: true, | ||
| copyCode: true, | ||
| customJs: ["/assets/js/vercel-analytics.js"], |
There was a problem hiding this comment.
customJs is configured with an absolute /assets/... URL, but this repo’s basePath is /variables-contract for GitHub Pages. If docmd doesn’t automatically prefix customJs entries with basePath, this will 404 on GitHub Pages. Prefer constructing the path with basePath (or using a relative path that docmd resolves against basePath) to ensure it works across both GH Pages and Vercel deployments.
| customJs: ["/assets/js/vercel-analytics.js"], | |
| customJs: [`${basePath}/assets/js/vercel-analytics.js`], |
| (function () { | ||
| var script = document.createElement('script'); | ||
| script.defer = true; | ||
| script.src = '/_vercel/insights/script.js'; | ||
| document.head.appendChild(script); | ||
| })(); |
There was a problem hiding this comment.
This script always injects /_vercel/insights/script.js. On the GitHub Pages deployment (see docmd.config.js’s siteUrl/basePath), that endpoint won’t exist, causing a 404 request on every page load. Consider gating the injection to known Vercel hosts (e.g., variables-contract.vercel.app / *.vercel.app) or adding a lightweight guard/feature-detect so non‑Vercel environments don’t attempt to load it; also consider preventing duplicate injection by checking for an existing script tag before appending.
Add analytics tracking to all documentation pages using docmd's
customJs configuration. The script dynamically loads Vercel's
analytics from /_vercel/insights/script.js.