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.

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.

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