fix(vercel-analytics): sink insight POSTs in dev to avoid 404s#713
fix(vercel-analytics): sink insight POSTs in dev to avoid 404s#713
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
commit: |
📝 WalkthroughWalkthroughThe pull request adds local development support for Vercel Analytics insights. A new conditional server handler is registered in the module when Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docs/content/docs/1.guides/2.first-party.md`:
- Line 353: The Vercel Analytics entry is classified inconsistently: update the
privacy-tier table so the Vercel Analytics row/entry (labelled "Vercel
Analytics" or path "/scripts/vercel-analytics") appears only under the
bundle-only/no-proxy category and remove or relocate it from the proxied IP-only
scripts list so both the table and the prose consistently state it is served via
Vercel edge and only works on Vercel (skipped in nuxt dev); ensure the single
canonical description is used in both places (the table row and any list that
previously included it).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 326e5356-ea54-4ab7-9491-f2a4a516d1d9
📒 Files selected for processing (10)
docs/content/docs/1.guides/2.first-party.mddocs/content/scripts/vercel-analytics.mdpackages/script/src/registry-types.jsonpackages/script/src/registry.tspackages/script/src/runtime/registry/schemas.tspackages/script/src/runtime/registry/vercel-analytics.tsplayground/pages/third-parties/vercel-analytics/nuxt-scripts.vuescripts/generate-sizes.tstest/e2e-dev/first-party.test.tstest/e2e/basic.test.ts
💤 Files with no reviewable changes (3)
- test/e2e/basic.test.ts
- playground/pages/third-parties/vercel-analytics/nuxt-scripts.vue
- packages/script/src/runtime/registry/schemas.ts
| | [Crisp](/scripts/crisp) | SDK loads secondary scripts and CSS at runtime from `client.crisp.chat`. | | ||
| | [Mixpanel](/scripts/mixpanel-analytics) | No proxy integration yet. | | ||
| | [Bing UET](/scripts/bing-uet) | No proxy integration yet. | | ||
| | [Vercel Analytics](/scripts/vercel-analytics) | Collects via relative `/_vercel/insights/*` served by Vercel's edge. Only works on Vercel-hosted deployments; skipped in `nuxt dev`. | |
There was a problem hiding this comment.
Resolve contradictory Vercel Analytics classification in this guide.
Line 353 says Vercel Analytics is bundle-only/no-proxy, but Line 66 still lists it under proxied IP-only scripts. Please align the privacy-tier table to avoid conflicting guidance.
📝 Proposed docs fix
-| **IP only** | IP addresses anonymised to subnet level | Plausible, PostHog, Umami, Fathom, CF Web Analytics, Vercel Analytics, Rybbit, Databuddy, Matomo, Intercom, YouTube, Vimeo, Gravatar, Carbon Ads, Lemon Squeezy, Google AdSense |
+| **IP only** | IP addresses anonymised to subnet level | Plausible, PostHog, Umami, Fathom, CF Web Analytics, Rybbit, Databuddy, Matomo, Intercom, YouTube, Vimeo, Gravatar, Carbon Ads, Lemon Squeezy, Google AdSense |🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@docs/content/docs/1.guides/2.first-party.md` at line 353, The Vercel
Analytics entry is classified inconsistently: update the privacy-tier table so
the Vercel Analytics row/entry (labelled "Vercel Analytics" or path
"/scripts/vercel-analytics") appears only under the bundle-only/no-proxy
category and remove or relocate it from the proxied IP-only scripts list so both
the table and the prose consistently state it is served via Vercel edge and only
works on Vercel (skipped in nuxt dev); ensure the single canonical description
is used in both places (the table row and any list that previously included it).
Vercel Analytics collects via a relative `/_vercel/insights/*` endpoint served by Vercel's edge. Outside Vercel (including `nuxt dev`) there is no upstream, so the script POSTs to the local origin and 404s. Register a dev-only handler that returns 204 on that path when vercelAnalytics is enabled. Script behaviour, options (mode/debug), and proxy domains are unchanged.
c447f12 to
a901469
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/script/src/module.ts`:
- Around line 530-538: The dev-only insights sink is registered correctly
(nuxt.options.dev && config.registry?.vercelAnalytics) but the registry still
sets trigger: 'client' in vercel-analytics.ts (around the trigger on line ~90)
so the script will auto-load in dev; update the registry entry created in
normalizeRegistryConfig or in vercel-analytics.ts to set trigger: 'manual' when
running in dev (or make normalizeRegistryConfig convert a truthy dev-only
vercelAnalytics entry to ['vercel-analytics', { trigger: 'manual' }]), and
re-run the build so the sink (runtime/server/vercel-insights-sink) plus the
trigger change are delivered together to prevent client auto-loading while
keeping the POST sink for 204s.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 6e0f6df0-784b-4141-abcb-9c0da955d37c
📒 Files selected for processing (2)
packages/script/src/module.tspackages/script/src/runtime/server/vercel-insights-sink.ts
| // In dev, sink Vercel Analytics insight POSTs to `/_vercel/insights/*` so | ||
| // they don't 404. Vercel's edge serves this path in production; locally | ||
| // there's no upstream, so we return 204 to keep the script happy. | ||
| if (nuxt.options.dev && config.registry?.vercelAnalytics) { | ||
| addServerHandler({ | ||
| route: '/_vercel/insights/**', | ||
| handler: await resolvePath('./runtime/server/vercel-insights-sink'), | ||
| }) | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify whether the vercelAnalytics registry entry sets a dev-specific default trigger of 'manual'.
fd -t f 'vercel-analytics' packages/script/src/runtime/registry
rg -nP -C5 "vercelAnalytics|vercel-analytics" packages/script/src/runtime/registryRepository: nuxt/scripts
Length of output: 1545
🏁 Script executed:
cat -n packages/script/src/runtime/registry/vercel-analytics.tsRepository: nuxt/scripts
Length of output: 5887
Dev-only insights sink wiring looks correct, but verify trigger behavior matches PR description.
The guard on nuxt.options.dev && config.registry?.vercelAnalytics is right: after normalizeRegistryConfig a disabled entry (false) is filtered/falsy, and any truthy registration becomes a tuple, so the handler is registered exactly when expected. Route is registered before the later per-script serverHandlers loop, which is fine since vercelAnalytics doesn't declare its own handlers for this path.
However, the sink alone does not prevent the script from loading in dev. The registry sets trigger: 'client' (line 90 of vercel-analytics.ts), meaning the script will load on client hydration regardless of dev/prod. The PR description claims a dev trigger of "manual" to prevent loading, but that change is not present—the sink only prevents 404s on POST requests. Confirm both the trigger default and the sink land together, otherwise the script will still auto-load in dev as it currently does.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/script/src/module.ts` around lines 530 - 538, The dev-only insights
sink is registered correctly (nuxt.options.dev &&
config.registry?.vercelAnalytics) but the registry still sets trigger: 'client'
in vercel-analytics.ts (around the trigger on line ~90) so the script will
auto-load in dev; update the registry entry created in normalizeRegistryConfig
or in vercel-analytics.ts to set trigger: 'manual' when running in dev (or make
normalizeRegistryConfig convert a truthy dev-only vercelAnalytics entry to
['vercel-analytics', { trigger: 'manual' }]), and re-run the build so the sink
(runtime/server/vercel-insights-sink) plus the trigger change are delivered
together to prevent client auto-loading while keeping the POST sink for 204s.
🔗 Linked issue
N/A
❓ Type of change
📚 Description
Vercel Analytics collects via a relative
/_vercel/insights/*endpoint served by Vercel's edge. Outside Vercel (includingnuxt dev) there is no upstream, so the bundled script POSTs to the local origin and 404s in devtools.Register a dev-only server handler that returns 204 on
/_vercel/insights/**whenvercelAnalyticsis enabled. Mirrors what Vercel's edge does in production as a local no-op, so the script loads normally andtrack/pageviewwork end-to-end in dev without noisy 404s.Script behaviour, public options (
mode,debug), and proxy domains are unchanged.