Why track page views?
Apage_view event tells you:
- Which pages in your app are visited most
- Where users first land when they open your app
- Which pages users visit before signing up or purchasing
- Which pages have high drop-off (users leave from there)
How page views work in single-page apps
In a traditional website, each page is a separate HTML file — every new page load is automatic. In a React or Next.js app, the URL changes without a full page reload. This means we need to manually tell Analytiq when the user navigates to a new page. There are two approaches:- Per-component tracking — add
track('page_view')inside each page component individually - Auto-tracking — add one listener at the root level that fires on every navigation
Approach 1 — Per-component tracking (simpler)
Add atrack() call inside each page component. If the page function already exists, just add the 2 lines inside it.
- React (JavaScript)
- React (TypeScript)
- Next.js App Router
- Vue 3
- Vanilla HTML
src/pages/Home.jsx
src/pages/Dashboard.jsx
Approach 2 — Global Router Tracking (Optional)
If you don’t want to copy-pasteuseEffect into every single page component, you can listen to your router globally.
- React (React Router)
- Next.js (App Router)
Add a listener inside your
App.jsx that watches the location object:src/App.jsx
Recommended properties for page_view events
utils/analytics.js
What if a user visits the same page twice?
The SDK has built-in deduplication — iftrack() is called with the exact same event within 300ms, the duplicate is silently ignored. However, if a user navigates away and comes back, that’s a new visit and gets tracked normally.
Verifying it works
- Open your app in the browser
- Press F12, then Console
- Navigate between pages
- Watch the Console for:
- Check your Analytiq dashboard — each page navigation appears as a separate event