pageviews
A pageview on load and on every client-side navigation. On by default.
import { pageviews } from "@spoar/sdk/plugins";The client adds this plugin itself unless it is created with pageviews: false, so most apps never import it.
import { createAnalytics } from "@spoar/sdk";
export const analytics = createAnalytics({
project: "example.com",
key: "pk_...",
endpoint: "/_ra",
});Options
pageviews() takes no options. The client option pageviews: false leaves it out.
Sends
| Event | Props |
|---|---|
pageview | None from the plugin. The event carries the page path, the title, the route template when one is set and, on the first pageview of a page load, the referrer |
Behaviour
- One pageview when the client starts, then one after every
history.pushState, everyhistory.replaceStateand everypopstate(back, forward, and hash router changes). - The URL compared is the path plus the query string. A navigation to the same URL is skipped, so
replaceStateon the current path sends nothing, and so does a change of only an anchor hash (#comments). - Hash routers (
/#/pricing) report the path inside the hash, without its query. - Nothing is sent while a route template is set, because a framework adapter such as
<Analytics />sends pageviews itself. Create the client withpageviews: falsein that case. - The plugin patches
history.pushStateandhistory.replaceStateand restores them onshutdown().
In reports
Pageviews make up the pageviews metric and the page, route, entry_page and exit_page dimensions. Time on page is the gap to the session's next pageview. The API overview lists the read routes.