Skip to main content

Why track page views?

A page_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)
This is the most fundamental event in any analytics setup. You should have it on every page.

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:
  1. Per-component tracking — add track('page_view') inside each page component individually
  2. Auto-tracking — add one listener at the root level that fires on every navigation

Approach 1 — Per-component tracking (simpler)

Add a track() call inside each page component. If the page function already exists, just add the 2 lines inside it.
src/pages/Home.jsx
src/pages/Dashboard.jsx

Approach 2 — Global Router Tracking (Optional)

If you don’t want to copy-paste useEffect into every single page component, you can listen to your router globally.
Add a listener inside your App.jsx that watches the location object:
src/App.jsx

utils/analytics.js

What if a user visits the same page twice?

The SDK has built-in deduplication — if track() 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

  1. Open your app in the browser
  2. Press F12, then Console
  3. Navigate between pages
  4. Watch the Console for:
  5. Check your Analytiq dashboard — each page navigation appears as a separate event