Skip to content

fix(react): send a pageview when route is set without a path (#197) - #205

Open
sarmah-rup wants to merge 1 commit into
vercel:mainfrom
sarmah-rup:fix/pageview-route-without-path
Open

fix(react): send a pageview when route is set without a path (#197)#205
sarmah-rup wants to merge 1 commit into
vercel:mainfrom
sarmah-rup:fix/pageview-route-without-path

Conversation

@sarmah-rup

Copy link
Copy Markdown

What I hit

Using <Analytics route="/blog/[slug]" /> (a route, no path — the normal React Router / TanStack Router pattern), zero pageviews were tracked, silently. This is issue #197.

Why

The mount effect sets disableAutoTrack: true as soon as route is defined, turning off the script's own pageview tracking. But the manual pageview effect only fires when both route && path are truthy. So with a route and no path, auto-track is disabled and the manual call is skipped, so nothing is tracked, with no warning.

Fix

Fire the manual pageview whenever route is set (the exact condition under which auto-track was disabled), defaulting path to window.location.pathname when it is omitted. The Next.js and Remix wrappers always pass both, so they are unaffected.

Test

Added two cases to react/index.test.tsx: the route-without-path case now queues a pageview, and a both-provided regression guard. Verified fail before the fix / pass after against the real component.

Closes #197.

@vercel

vercel Bot commented Jul 21, 2026

Copy link
Copy Markdown

@sarmah-rup is attempting to deploy a commit to the Analytics Test Projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

React component silently drops pageviews when route is set without path

1 participant