From 96561464e3e4bbf097db8ae230f50b4bfda62e4a Mon Sep 17 00:00:00 2001 From: Rup Sarmah Date: Tue, 21 Jul 2026 14:10:45 +0530 Subject: [PATCH] fix(react): send a pageview when route is set without a path (#197) --- packages/web/src/react/index.test.tsx | 24 ++++++++++++++++++++++++ packages/web/src/react/index.tsx | 7 +++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/packages/web/src/react/index.test.tsx b/packages/web/src/react/index.test.tsx index d564b6d..622d896 100644 --- a/packages/web/src/react/index.test.tsx +++ b/packages/web/src/react/index.test.tsx @@ -140,4 +140,28 @@ describe('', () => { }); }); }); + + describe('pageview tracking', () => { + it('tracks a pageview when route and path are both provided', () => { + render( + , + ); + + expect(window.vaq?.[0]).toEqual([ + 'pageview', + { route: '/blog/[slug]', path: '/blog/hello' }, + ]); + }); + + it('tracks a pageview when route is provided without path', () => { + // auto tracking is disabled as soon as `route` is set, so the component + // must still emit a pageview instead of silently dropping it. + render(); + + expect(window.vaq?.[0]).toEqual([ + 'pageview', + { route: '/blog/[slug]', path: window.location.pathname }, + ]); + }); + }); }); diff --git a/packages/web/src/react/index.tsx b/packages/web/src/react/index.tsx index 0825012..852d61c 100644 --- a/packages/web/src/react/index.tsx +++ b/packages/web/src/react/index.tsx @@ -57,8 +57,11 @@ function Analytics( useEffect(() => { // explicitely track page view, since we disabled auto tracking - if (props.route && props.path) { - pageview({ route: props.route, path: props.path }); + if (props.route) { + pageview({ + route: props.route, + path: props.path ?? window.location.pathname, + }); } }, [props.route, props.path]);