Dokumentaatio
Selaa dokumentaatiota

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.

Näytä Markdown-muodossa

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#

  1. Both automatic SPA tracking and a manual call. You call privatus.pageview() in a router hook (router.afterEach, useEffect on the location, onRouteChange) while the tracker also follows history.pushState. Remove your call, or switch the tracker to data-spa="off" and keep yours.
  2. 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.
  3. A tag manager re-fires the tag on "History change" triggers. Fire it only on page load: the tracker handles history changes itself.
  4. 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.