React
Add Produl to any React app. SPAs get automatic route-change tracking with no extra setup.
Install
- 1
Add the package
bashnpm install produl-tracker - 2
Add Analytics to your app root
Import
Analyticsfromprodul-tracker/reactand render it once near the top of your component tree — typically in your rootAppcomponent.
Usage
src/App.tsxtsx
import { Analytics } from 'produl-tracker/react'
export default function App() {
return (
<>
<Analytics siteId="YOUR_SITE_ID" />
{/* rest of your app */}
</>
)
}To send custom events, import track and call it anywhere in your component tree:
tsx
import { track } from 'produl-tracker/react'
function SignupButton() {
return (
<button onClick={() => track('signup', { plan: 'pro' })}>
Get started
</button>
)
}SPA routing
The React adapter intercepts history.pushState and history.replaceState so client-side navigations are tracked automatically. This works with React Router, TanStack Router, and any other router that wraps the History API. You do not need to configure anything — just keep disableAutoTrack at its default of false.
If you manage routing yourself and prefer full control, set
disableAutoTrack to true and call track('pageview') on each navigation.Configuration
| Prop | Type | Default | Description |
|---|---|---|---|
siteId | string | — | Required. Your site ID from the dashboard. |
serverUrl | string | hosted instance | Override the tracker server URL. |
disableAutoTrack | boolean | false | Disable automatic pageview tracking on route changes. |
endpoint | string | /api/collect | Base URL that pageview and event data is sent to. |
debug | boolean | false | Show a debug overlay listing every tracked event. |
Vite env var
Set
VITE_MULTIANALYTICS_URL to override the server URL in Vite-based projects without passing a prop.