Skip to content

fix(vercel-analytics): sink insight POSTs in dev to avoid 404s#713

Merged
harlan-zw merged 1 commit intomainfrom
fix/vercel-analytics-dev-skip
Apr 17, 2026
Merged

fix(vercel-analytics): sink insight POSTs in dev to avoid 404s#713
harlan-zw merged 1 commit intomainfrom
fix/vercel-analytics-dev-skip

Conversation

@harlan-zw
Copy link
Copy Markdown
Collaborator

@harlan-zw harlan-zw commented Apr 15, 2026

🔗 Linked issue

N/A

❓ Type of change

  • 📖 Documentation
  • 🐞 Bug fix
  • 👌 Enhancement
  • ✨ New feature
  • 🧹 Chore
  • ⚠️ Breaking change

📚 Description

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 bundled script POSTs to the local origin and 404s in devtools.

Register a dev-only server handler that returns 204 on /_vercel/insights/** when vercelAnalytics is enabled. Mirrors what Vercel's edge does in production as a local no-op, so the script loads normally and track/pageview work end-to-end in dev without noisy 404s.

Script behaviour, public options (mode, debug), and proxy domains are unchanged.

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Apr 15, 2026

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

Project Deployment Actions Updated (UTC)
scripts-playground Ready Ready Preview, Comment Apr 17, 2026 1:25am

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 15, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@nuxt/scripts@713

commit: a901469

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 15, 2026

📝 Walkthrough

Walkthrough

The pull request adds local development support for Vercel Analytics insights. A new conditional server handler is registered in the module when config.registry?.vercelAnalytics is enabled. This handler intercepts requests to /_vercel/insights/** and routes them to a new stub endpoint that returns a 204 No Content response, preventing 404 errors during development. A new server file is created to implement this stub handler.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: adding a dev-only sink for Vercel Analytics POST requests to prevent 404 errors.
Description check ✅ Passed The description is directly related to the changeset, explaining the problem context, the solution implemented, and what remains unchanged.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/vercel-analytics-dev-skip

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between f4a4df6 and c447f12.

📒 Files selected for processing (10)
  • docs/content/docs/1.guides/2.first-party.md
  • docs/content/scripts/vercel-analytics.md
  • packages/script/src/registry-types.json
  • packages/script/src/registry.ts
  • packages/script/src/runtime/registry/schemas.ts
  • packages/script/src/runtime/registry/vercel-analytics.ts
  • playground/pages/third-parties/vercel-analytics/nuxt-scripts.vue
  • scripts/generate-sizes.ts
  • test/e2e-dev/first-party.test.ts
  • test/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`. |
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

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.
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between c447f12 and a901469.

📒 Files selected for processing (2)
  • packages/script/src/module.ts
  • packages/script/src/runtime/server/vercel-insights-sink.ts

Comment on lines +530 to +538
// 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'),
})
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 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/registry

Repository: nuxt/scripts

Length of output: 1545


🏁 Script executed:

cat -n packages/script/src/runtime/registry/vercel-analytics.ts

Repository: 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.

@harlan-zw harlan-zw changed the title fix(vercel-analytics): skip script in dev to avoid failed insights POSTs fix(vercel-analytics): sink insight POSTs in dev to avoid 404s Apr 17, 2026
@harlan-zw harlan-zw merged commit 8ef0d39 into main Apr 17, 2026
17 checks passed
@harlan-zw harlan-zw deleted the fix/vercel-analytics-dev-skip branch April 17, 2026 01:52
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.

1 participant