PureStats documentation

React

Add PureStats to a React application and track client-side navigation with React Router. Send custom events and prevent duplicate tracking in development.

React apps usually load PureStats once in the HTML shell.

Vite or Create React App

Add the script to index.html:

<div id="root"></div>
<script defer src="https://purestats.io/pf.min.js" data-domain="example.com"></script>

The tracker will capture the initial pageview and listen for history changes created by common routers.

React Router

For most React Router apps, no extra code is required. If your app uses memory routing or custom navigation that does not update the browser URL, PureStats cannot record the new screen as a pageview: the tracker only counts a pageview when the URL changes. Record the screen change as a custom event instead:

window.purestats?.('Screen Viewed', { screen: 'checkout' });

Call it after the visible screen changes.

Custom events

Use JavaScript events for product interactions that are not pageviews:

window.purestats?.('Signup Started', {
  plan: 'pro',
  location: 'pricing'
});

For simple buttons or forms, no-code events may be easier to maintain.

Development mode

PureStats does not accept localhost or IP addresses as domains, so local development is not tracked. To test before release, add your preview hostname in Site settings → Domains and use tracking test mode. Production builds should use the real configured domain.