Appearance
Single-page apps
In apps with client-side routing (React Router, Vue Router, Next.js, Nuxt and others), the page doesn't reload on navigation, so a page view has to be recorded on each route change.
Automatic page views
Pass autoPageviews: true to init():
js
vectelle.init('pk_live_REPLACE_ME', {
endpoint: 'https://INGEST_HOST/v1/batch',
autoPageviews: true,
})The SDK then sends a page_view:
- once when it starts, and
- whenever the path or query string changes through
history.pushState,history.replaceState, or the back and forward buttons.
A navigation that leaves the path and query string unchanged, such as a change to the #hash alone, doesn't count as a new page.
Manual page views
If you'd rather control it, for example to wait until the new page's title is set, leave autoPageviews off and call page() yourself after each navigation:
js
router.afterEach(() => {
vectelle.page()
})page(properties) is shorthand for track('page_view', properties). The current URL, path, title and referrer are added automatically.