MenuPageviews and single-page apps

Track

Pageviews and single-page apps

When ProductLense records a pageview, how client-side route changes are tracked, and how to send one by hand.

ProductLense records a pageview when the script loads and every time the URL changes inside a single-page app. You do not need router hooks for Next.js, React Router, SvelteKit, Nuxt, Astro's client router or Framer page transitions.

What counts as a pageview

  • One pageview when the page loads.
  • One pageview after history.pushState, history.replaceState and on popstate, but only when the cleaned URL differs from the last one recorded.
  • A route change is recorded 300 ms after it happens, so the pageview carries the new page's title. When the URL changes again within those 300 ms, only the newer page is recorded, 300 ms after its own change. Query-only updates, such as a search box writing ?q=, do not delay it.

The cleaned URL drops the #hash and every query parameter except utm_*, ref, gclid, fbclid and msclkid. So changing only the hash, or adding a search parameter such as ?page=2, does not record another pageview.

Turn route tracking off

Set data-spa="false" to record only full page loads:

HTML
<script defer data-site="SITE_ID" data-spa="false" src="https://api.productlense.app/a.js"></script>

Send a pageview by hand

With route tracking off, or for a view that does not change the URL (a modal that acts as a page), call:

JavaScript
window.productlense('pageview');

A manual pageview always records, even when the URL has not changed.

What a pageview carries

FieldValue
uThe cleaned page URL
rdocument.referrer
tdocument.title (stored up to 512 bytes)
wViewport width in pixels
lBrowser language
uidYour user id, after identify in this tab
tsTime in milliseconds

Events are queued and sent in batches of up to 10, or after one second, whichever comes first. The queue is flushed when the page is hidden or closed, using navigator.sendBeacon with a fetch keepalive fallback.

Page leave

Each pageview is followed by one $pageleave event when the visitor leaves the page: on the next route change in a single-page app, or when the tab is closed or the visitor navigates away. It carries p.duration, the whole seconds the page was visible. Time the page spent in a background tab is not counted.

  • Visit duration runs from the first pageview to the last pageview or page leave, so it includes time on the last page. A one-page visit no longer shows 0 s.
  • Page leave events are free. They never count toward your plan's monthly events.
  • A page leave never starts a visit, and it is not listed with your custom events. It shows in visitor journeys and in raw events.
  • A browser closed from the mobile app switcher may not send one. That visit then ends at its last pageview, as before.
  • Excluded pages send no page leave.

Timestamps

The server uses the browser's timestamp when it is no more than one hour in the past and one minute in the future; otherwise it uses the time the request arrived.

    ↑ ↓ to move, Enter to open