Skip to content

React component silently drops pageviews when route is set without path #197

@pookyl

Description

@pookyl

Bug Report

Description

When using <Analytics route={route} /> from @vercel/analytics/react (v2.0.1) in a plain React + React Router app, no pageviews are ever sent — silently, with no warning or error.

Root Cause

In the React component (source):

// Setting route enables disableAutoTrack
useEffect(() => {
  inject({
    ...props.route !== void 0 && { disableAutoTrack: true },
    ...props,
  });
}, []);

// But pageview() only fires when BOTH route and path are truthy
useEffect(() => {
  if (props.route && props.path) {
    pageview({ route: props.route, path: props.path });
  }
}, [props.route, props.path]);

When route is provided:

  1. disableAutoTrack is set to true → the script won't track pageviews on its own
  2. The component is supposed to call pageview() manually on route changes
  3. But pageview() only fires when both route AND path are truthy
  4. If path is omitted → the condition is falsezero pageviews are sent, ever

There is no console.warn, no error, no fallback. The component renders null and does nothing.

How to Reproduce

import { Analytics } from '@vercel/analytics/react';
import { useLocation, matchPath } from 'react-router-dom';

function AnalyticsWithRoutes() {
  const { pathname } = useLocation();
  const route = ROUTES.find(p => matchPath(p, pathname)) ?? pathname;

  // ❌ This sends ZERO pageviews — no error, no warning
  return <Analytics route={route} />;

  // ✅ This works — but only discoverable by reading source code
  // return <Analytics route={route} path={pathname} />;
}

Expected Behavior

At minimum, one of:

  1. Documentation: The route and path props should be documented on the package configuration page, with a clear note that path is required when route is used.

  2. Runtime warning: When route is provided without path, log a warning:

    [Vercel Web Analytics] `route` prop requires `path` prop for pageviews to be tracked.
    
  3. Graceful fallback: When route is set but path is omitted, fall back to window.location.pathname instead of silently doing nothing.

Context

  • This primarily affects non-Next.js/Remix apps (React Router, TanStack Router, etc.) where developers must wire up route tracking manually.
  • The Next.js and Remix wrappers pass both route and path automatically, which is likely why this gap hasn't been caught — the manual usage path is undocumented.
  • The route and path props appear in TypeScript autocomplete but are absent from the official docs, so developers can discover and use route without ever knowing path is required.
  • We spent significant debugging time on this because the failure mode is completely silent — no network requests, no console output, nothing in DevTools.

Environment

  • @vercel/analytics: 2.0.1
  • Framework: React 19 + React Router 7 + Vite
  • Deployment: Vercel (production)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions