Fix SPA double-counted pageviews
Fix pageviews counted twice on single-page apps: duplicate router calls, the script included twice, tag manager history triggers, and checking with debug mode.
If pageviews are roughly double the visits you'd expect, or each page shows up twice in the Live stream, two things are sending pageviews for each navigation.
Common causes#
- Both automatic SPA tracking and a manual call. You call
privatus.pageview()in a router hook (router.afterEach,useEffecton the location,onRouteChange) while the tracker also followshistory.pushState. Remove your call, or switch the tracker todata-spa="off"and keep yours. - The script is included twice: in the layout and in a page, or by a
plugin and by hand. Search the rendered HTML for
pa.js. There should be exactly one. A framework integration plus a manual snippet is a common pair. - A tag manager re-fires the tag on "History change" triggers. Fire it only on page load: the tracker handles history changes itself.
- Zaraz SPA support or similar tools re-injecting scripts on navigation.
What the tracker already prevents#
It won't send two pageviews in a row for the same path (pathname, plus the
fragment in hash mode), so a router that pushes the same URL twice isn't
double counted. privatus.pageview() always sends, by design.
Check with data-debug="true": each navigation should log exactly one
[privatus] pageview.