---
title: Set up Speed Insights behind a reverse proxy with multiple Vercel projects
description: Configure Speed Insights and Web Analytics to collect data when a reverse proxy such as Akamai or Cloudflare routes one domain to several Vercel projects.
url: "https://vercel.com/kb/guide/speed-insights-behind-reverse-proxy"
published: 2026-11-18
last_updated: 2026-11-18
authors: Dawid Dao Xuan
install_vercel_plugin: npx plugins add vercel/vercel-plugin
search_with_vercel_cli: npx vercel@latest kb search "<query>"
read_with_vercel_cli: "npx vercel@latest kb inspect speed-insights-behind-reverse-proxy"
---

When a reverse proxy such as Akamai or Cloudflare routes paths on one domain to different Vercel projects, for example, `example.com/basket/*` to one project and `example.com/account/*` to another, Speed Insights requests can fail or send data to the wrong project if the proxy does not route their collection paths correctly. This guide shows how to send each project's Speed Insights requests via the path prefix the proxy already routes to.

Vercel recommends pointing your domain directly to Vercel, so use this guide only when a reverse proxy is a requirement you can't remove. This guide is for projects that don't use [Vercel Microfrontends](https://vercel.com/docs/microfrontends). With Microfrontends, turn on [Observability Routing](https://vercel.com/docs/microfrontends/managing-microfrontends#observability-data-routing) instead.

## Quick start with an AI coding agent

To have an agent do this setup for you, use the following prompt:

### Agent prompt

```txt
Configure Vercel Speed Insights for my projects that a reverse proxy serves on one shared domain, so each project's data reaches the intended Vercel project.

If a repository is missing, ask me to open or import it. Read repository instructions and inspect the framework, package manager, Speed Insights integration, shared packages, environment configuration, and proxy configuration. Map each project to its path prefix, Vercel origin, and the environments served through the proxy, including any catch-all project at the domain root. Ask only for what you cannot discover, whether data should stay in each project or go to one receiving project, and which intake path to use: /<prefix>/_vercel/speed-insights, or a custom path such as /<prefix>/_si, which common content blockers don't block. For code or proxy configuration outside this workspace, prepare exact changes for the owning team. If the projects use Vercel Microfrontends, use its Observability Routing setting instead of this setup.

Use a relative intake path under each receiving project's prefix. To collect data in one project, point every sender, including the catch-all project, at the receiver's path.

In each sender, read NEXT_PUBLIC_SPEED_INSIGHTS_PATH, or the framework's public build-time equivalent. Only when it's set, pass scriptSrc="${path}/script.js" and endpoint="${path}/vitals" to the existing SpeedInsights component, using the framework's import, such as @vercel/speed-insights/next. If the component is shared, pass the path through its existing boundary. Set it only in environments served through the proxy, based on the actual setup, and note the redeploys it needs.

Add one proxy rule per receiving project that rewrites its intake path to /_vercel/speed-insights/* at its Vercel origin. Reuse the page rule's origin settings, including the Host header and any protection or proxy headers. Make the rule take precedence under the proxy's actual evaluation order, and keep the origin's Cache-Control headers. Don't add a Next.js rewrite.

If the projects use Web Analytics, repeat this with NEXT_PUBLIC_WEB_ANALYTICS_PATH and the matching intake path, /<prefix>/_vercel/insights or a custom one such as /<prefix>/_va: set scriptSrc, viewEndpoint, and eventEndpoint to /script.js, /view, and /event with @vercel/analytics 2 or newer, and rewrite to /_vercel/insights/*.

Before changing any files, confirm the mapping and planned changes with me. Ask again before editing proxy configuration, changing shared environment variables, or deploying.

Run build and type checks, and give me deployed verification steps: in a regular browser with Keep log on, filter DevTools Network by the intake path, confirm script.js and vitals return 200 (switch tabs if vitals hasn't appeared), then check the Paths tab in the receiving project's Speed Insights dashboard. Recommend Verified Proxy for visitor-country data without promising that Lite restores it; country breakdowns require Speed Insights Plus.

Report changed files, the sender-to-receiver mapping, environment variables and scopes, proxy rules, changes for other teams, and which checks ran or remain unverified.
```

## Why Speed Insights fails behind a reverse proxy

The `<SpeedInsights />` component makes two requests from the visitor's browser to the domain the visitor is on:

- `script.js` loads the collection script
  
- `vitals` sends the metrics.
  

By default, both go to a path at the domain root. In version 2 of the package, this is a random path such as `/ded50bb4357d28b4/script.js` that Vercel generates at build time, a mechanism called [Resilient Intake](https://vercel.com/docs/speed-insights/privacy-policy#resilient-intake).

Version 1 uses `/_vercel/speed-insights/script.js`. Neither the package nor Vercel adds the Next.js `basePath` to this path.

A proxy that routes `/basket/*` and `/account/*` to their projects doesn't route that root path to either of them. The request fails, or a catch-all rule sends it to a different project.

## Before you begin

- Install `@vercel/speed-insights` and add `<SpeedInsights />` to each project, as described in the [Speed Insights quickstart](https://vercel.com/docs/speed-insights/quickstart).
  
- Ensure you have access to change the reverse proxy's routing rules.
  

## Confirm the script request fails

The examples use two Next.js projects, `basket-app` and `account-app`. To check whether the script request succeeds:

1. Open a page from one of your projects through the reverse proxy, for example `example.com/basket`.
   
2. Open DevTools, go to the Network tab, and filter by `script.js`.
   
3. Reload the page and select the Speed Insights script request. The Headers tab shows the request URL and status.
   

Behind the proxy, the request typically fails with a `404`:

![DevTools Network tab on the basket page. The Speed Insights script request goes to a random path at the domain root and returns 404 Not Found.](https://images.ctfassets.net/hjgychtc108g/72Td8SOQWg3AhdeRI6ybrS/7da830ccc3883bb90dca24dfc34064bc/01-before-basket-script-404.png)

Repeat the check for every project behind the proxy. If the request succeeds, check which project the proxy forwards that path to. The data goes to that project, which isn't always the project that serves the page.

## Route Speed Insights through each project's prefix

### Step 1. Choose a path prefix for each project

By default, each project sends data to itself through a path under the prefix the proxy already routes to it:

| Project       | Speed Insights path               | Requests the browser makes                                                            |
| ------------- | --------------------------------- | ------------------------------------------------------------------------------------- |
| `basket-app`  | `/basket/_vercel/speed-insights`  | `/basket/_vercel/speed-insights/script.js`, `/basket/_vercel/speed-insights/vitals`   |
| `account-app` | `/account/_vercel/speed-insights` | `/account/_vercel/speed-insights/script.js`, `/account/_vercel/speed-insights/vitals` |

The path can be anything under the prefix, because the proxy rewrites it in step 3.

The examples use the paths shown in the screenshots. Optionally, choose a custom alias such as `/basket/_si`. Some content blockers match `/_vercel/speed-insights/script.js`. A custom alias avoids that specific pattern. Use the chosen path consistently in the environment variable, proxy rule, and verification steps.

A catch-all project needs no collection-path changes if its data should remain in that project and its existing collection requests already reach the correct origin. To send its data to another project, configure it to use the receiving project’s path too.

To see the whole domain in one dashboard instead, use the same project path across all projects. For example, use `/basket/_vercel/speed-insights` in `account-app` too. `basket-app` then receives the events from both projects, and they count under its Speed Insights plan. `account-app` receives none, and step 3 needs only the `/basket` rule.

### Step 2. Set `scriptSrc` and `endpoint` in each project

Set `NEXT_PUBLIC_SPEED_INSIGHTS_PATH` to the receiving project’s path from step 1, such as `/basket/_vercel/speed-insights`, in each environment served through the proxy. Leave it unset in environments accessed directly, so the component uses its default collection paths. Next.js reads this public variable at build time, so redeploy after changing it.

Then pass the path to `<SpeedInsights />` in the root layout:

```javascript
import { SpeedInsights } from '@vercel/speed-insights/next'

const speedInsightsPath = process.env.NEXT_PUBLIC_SPEED_INSIGHTS_PATH

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        {children}
        <SpeedInsights
          {...(speedInsightsPath && {
            scriptSrc: `${speedInsightsPath}/script.js`,
            endpoint: `${speedInsightsPath}/vitals`,
          })}
        />
      </body>
    </html>
  )
}
```

Explicit `scriptSrc` and `endpoint` values override Vercel’s generated script and collection paths for that build.

Relative paths keep both requests first-party on the visitor's domain. The [package reference](https://vercel.com/docs/speed-insights/package#endpoint) also shows full URLs to each project's Vercel domain, which avoid proxy rules but make the requests cross-origin. You can also set them with the `VERCEL_OBSERVABILITY_CLIENT_CONFIG` variable, as described in [Dynamic configuration](https://vercel.com/docs/speed-insights/package#dynamic-configuration).

### Step 3. Add reverse proxy rules for the Speed Insights paths

A Vercel deployment serves Speed Insights at `/_vercel/speed-insights/*` on its own root, never under a prefix. In the reverse proxy, forward each project's Speed Insights path to its Vercel origin and rewrite it to the root path. Any proxy that can rewrite paths can do this:

| Request path                        | Forward to           | Path at the origin          |
| ----------------------------------- | -------------------- | --------------------------- |
| `/basket/_vercel/speed-insights/*`  | `basket-app` origin  | `/_vercel/speed-insights/*` |
| `/account/_vercel/speed-insights/*` | `account-app` origin | `/_vercel/speed-insights/*` |

Give each rule the same origin settings as the page rule for that prefix: the origin hostname, the Host header sent to Vercel, and any headers the proxy adds, such as a protection bypass or Verified Proxy header. The simplest way is to nest the Speed Insights rule inside the page rule, or copy its origin settings.

Make each Speed Insights rule take precedence over the page rule for the same prefix. Otherwise, the page rule forwards the request with the prefix, and the origin returns `404`. In proxies where the first match wins, such as a Cloudflare Worker, place it first. In proxies where later rules override earlier ones, such as Akamai Property Manager or Cloudflare Rules, place it after the page rule or nest it inside.

Do the rewrite in the proxy, not in `next.config.ts`. A Next.js rewrite to `/_vercel/speed-insights/*` doesn't reach the Speed Insights routes, because Vercel serves them outside your app's routing.

Let the proxy follow the origin's `Cache-Control` headers, so it caches `script.js` (`max-age=2678400`) and sends every `vitals` request to Vercel (`max-age=0, must-revalidate`).

For example, in a Cloudflare Worker, the Speed Insights rule runs before the page rule:

```typescript
const SPEED_INSIGHTS = /^\/(basket|account)\/_vercel\/speed-insights(\/.*)$/

export default {
  async fetch(request, env): Promise<Response> {
    const url = new URL(request.url)
    const origins: Record<string, string> = {
      basket: env.BASKET_ORIGIN,
      account: env.ACCOUNT_ORIGIN,
    }

    // Speed Insights: rewrite /<prefix>/_vercel/speed-insights/* to /_vercel/speed-insights/* at the project's origin
    const match = url.pathname.match(SPEED_INSIGHTS)
    if (match) {
      const target = new URL(`/_vercel/speed-insights${match[2]}${url.search}`, origins[match[1]])
      return fetch(new Request(target, request))
    }

    // Pages: forward with the prefix
    const prefix = url.pathname.split('/')[1]
    if (Object.hasOwn(origins, prefix)) {
      const target = new URL(url.pathname + url.search, origins[prefix])
      return fetch(new Request(target, request))
    }

    return new Response('Not Found', { status: 404 })
  },
} satisfies ExportedHandler<Env>
```

Set `BASKET_ORIGIN` and `ACCOUNT_ORIGIN` as Worker variables with each project's production URL, and run wrangler types to generate the Env type.

### Step 4. Deploy and verify

Deploy each project to production, then check each project through the reverse proxy:

1. Open a page from the project, for example `example.com/basket`, with DevTools open on the Network tab and **Keep log** (Preserve log in older Chrome versions) turned on.
   
2. Filter by `_vercel`, and confirm that the `script.js` request uses the project's path and returns `200`. If you chose a custom alias, filter by that alias instead.
   
3. Confirm that a `vitals` request with the project's path returns `200`. The script sends vitals after the first metrics are measured and again when the page is hidden. Switch to another tab and back, or navigate to another page if it hasn't appeared.
   
4. Load and leave a few pages in each project to generate events.
   

![DevTools Network tab on the basket page, filtered by \_vercel. The script.js and vitals requests both return 200.](https://images.ctfassets.net/hjgychtc108g/4lTTI8ZfPQMZsJPsIxIn1V/d715001d64af22c2d659b405fe741beb/03b-after-basket-script-200.png)

Open **Speed Insights** in the dashboard of each project that receives data, select the Paths tab, and confirm that its paths appear. Data can take a few minutes to appear.

![Speed Insights for basket-app. The Paths tab lists /basket with a Real Experience Score of 100](https://images.ctfassets.net/hjgychtc108g/FKdTD5JE5E2DeD7i43VrR/7792bac15a5cd140ebb1b1f6d11e0792/05-dashboard-basket-app.png)

The **Routes** tab shows routes without the Next.js `basePath`, so a page at `/basket` appears as `/`. If every project sends data to one project, pages that share a route, such as both home pages, are combined there. Use the Paths tab to see full paths.

Speed Insights for basket-app. The Paths tab lists `/basket`.

![Speed Insights for basket-app with data from both projects. The Paths tab lists /basket and /account](https://images.ctfassets.net/hjgychtc108g/6JTqnXMrtQPzfYNSEyNr9Z/cb11a3ecb42cfafea5f6814839ae1d3a/07-dashboard-aggregated-basket-and-account.png)

If all projects send data to `basket-app`, its **Paths** tab lists `/basket` and `/account`.

## Apply the same setup to Web Analytics

Web Analytics fails behind the proxy for the same reason, because `<Analytics />` also requests paths at the domain root. If your projects use it, give it its own path under each project's prefix, such as `/basket/_va`, and avoid `_vercel/insights` in it for the same content-blocker reason:

1. Add a `NEXT_PUBLIC_WEB_ANALYTICS_PATH` environment variable in the same environments as `NEXT_PUBLIC_SPEED_INSIGHTS_PATH`, and pass it to `<Analytics />` from `@vercel/analytics/next`:
   

```javascript
const webAnalyticsPath = process.env.NEXT_PUBLIC_WEB_ANALYTICS_PATH

<Analytics
  {...(webAnalyticsPath && {
    scriptSrc: `${webAnalyticsPath}/script.js`,
    viewEndpoint: `${webAnalyticsPath}/view`,
    eventEndpoint: `${webAnalyticsPath}/event`,
  })}
/>
```

1. Add a proxy rule that forwards `/basket/_va/*` to `/_vercel/insights/*` at the `basket-app` origin, with the same origin settings and precedence as the Speed Insights rule.
   
2. Filter DevTools Network by `_va`_._ Confirm that `script.js` loads and the page-view POST to `/basket/_va/view` succeeds. If you use custom events, trigger one and confirm that its POST to `/basket/_va/event` succeeds. Repeat for each project’s configured path, then check the receiving project’s Web Analytics dashboard.
   

`viewEndpoint` and `eventEndpoint` require `@vercel/analytics` version 2. See the [package reference](https://vercel.com/docs/analytics/package#scriptsrc) for the options.

## Record visitor countries correctly

Country breakdowns require [Speed Insights Plus](https://vercel.com/docs/speed-insights/limits-and-pricing). Behind a reverse proxy, country data can reflect the proxy’s location. Forwarding a visitor-IP header alone does not establish trust: Vercel must also recognize the proxy, and its configuration must meet the provider-specific requirements.

[Verified Proxy Lite](https://vercel.com/docs/security/reverse-proxy) automatically identifies supported proxy traffic when these requirements are met. For preserving original client IP and geolocation, contact your Vercel account representative about [Verified Proxy Advanced](https://vercel.com/docs/security/reverse-proxy#self-hosted-reverse-proxies-verified-proxy-advanced) (available on Enterprise) and confirm its support for your Speed Insights configuration.

| Plan       | Available option                                                               |
| ---------- | ------------------------------------------------------------------------------ |
| Hobby, Pro | Verified Proxy Lite for supported providers                                    |
| Enterprise | Verified Proxy Lite and Verified Proxy Advanced, including self-hosted proxies |

## Troubleshooting

### The `script.js` request still goes to a root path

The build doesn't include `NEXT_PUBLIC_SPEED_INSIGHTS_PATH`. Next.js inlines the variable at build time, so check that it's set for the environment you deployed, then redeploy. If the proxy caches pages, purge its cache.

### The `script.js` request returns `404` at the prefixed path

The page rule takes precedence over the Speed Insights rule; the rule doesn't rewrite the path to `/_vercel/speed-insights/*`, or it forwards to the wrong origin. Check the rule's precedence, rewrite, and origin.

### `script.js` loads but no `vitals` request appears

Open the page in a regular browser; Speed Insights skips automated browsers it detects. Switch to another tab or navigate away to trigger submission, keeping DevTools’ Preserve log enabled.

If no `vitals` request appears, check the console for JavaScript or Content Security Policy errors. Also review [`sampleRate`](https://vercel.com/docs/speed-insights/package#samplerate) and [`beforeSend`](https://vercel.com/docs/speed-insights/package#beforesend): sampling can exclude the visit, and `beforeSend` can discard metrics.

If a `vitals` request appears but fails, inspect its status and response. Confirm that the proxy forwards the POST method and body to the correct project’s `/_vercel/speed-insights/vitals` endpoint, preserves the required origin headers, and does not block or challenge the request.

### A `next.config.ts` rewrite for the Speed Insights paths has no effect

Perform the path rewrite in the external reverse proxy, as described in step 3, so Vercel receives requests at `/_vercel/speed-insights/*`. Remove any redundant Next.js rewrite added for these collection paths, and confirm that the proxy forwards them to the intended project’s origin.

### Data appears in the wrong project

The project's `NEXT_PUBLIC_SPEED_INSIGHTS_PATH` uses another project's prefix or isn't set, or the proxy forwards the prefix to the wrong origin. Without the variable, the script sends vitals to the root path, where a catch-all rule can send them to another project. Check the variable in the deployed project and the origin that the Speed Insights rule forwards to.

## Related Documentation

- [Observability](/docs/observability)

## More Observability guides

- [How to prepare your storefront for Black Friday traffic](/kb/guide/black-friday-preparation): Set baselines and cut backend load. Make your catalog readable to agents and keep orders and AI features reliable. Then load test checkout before traffic peaks.
- [How can I improve function cold start performance on Vercel?](/kb/guide/improve-function-cold-start-performance-on-vercel): Learn how to confirm whether cold starts cause function latency on Vercel, and how Fluid compute reduces how often they happen.
- [How to keep your storefront running through Black Friday](/kb/guide/black-friday-reliability): Learn how to tune alerts, bot rules, and spend limits. Rehearse rollback so your team can recover quickly from checkout or order issues on Black Friday.

## Reference Architecture

Choose a stack and work through the decisions behind it, with curated documentation, guides, templates, and courses to help you build.

- [Agent stack](/kb/architecture/agents): Build and operate agents with models, tools, and durable workflows.
- [Web applications](/kb/architecture/web): Choose rendering, data, authentication, and caching approaches.
- [Backends](/kb/architecture/backends): Choose a runtime, connect services, and run background work.

[Browse all stacks](/kb/architecture)

## Build with prompts

Build an app, extend an agent, or improve your project with ready-to-use prompts for your coding agent.

[Browse the prompt library](/kb/prompts) · [Read the Markdown index](/kb/prompts.md)

## Search guides from your terminal

Search the Knowledge Base and read guides as Markdown with the Vercel CLI. No login required.

```bash
# Find guides by keyword
npx vercel@latest kb search "rewrites and redirects"
npx vercel@latest kb search "AI SDK streaming"

# Show the latest guides
npx vercel@latest kb

# Print a guide as Markdown, by slug or URL
npx vercel@latest kb inspect <guide>
```
