React
The Analytics component and track() for React apps.
The React package works in any React app, with or without a framework. Other frameworks shows where the component goes in TanStack Start and React Router.
Install the package
bun add @ultanimus/reactnpm install @ultanimus/reactpnpm add @ultanimus/reactyarn add @ultanimus/reactAdd the component
Render Analytics once, near the root of your app.
import { Analytics } from '@ultanimus/react'
export function App({ children }) {
return (
<>
{children}
<Analytics site="YOUR_SITE_ID" />
</>
)
}Use the component or the script tag, not both. A second copy on the same page counts nothing, and your site's settings show a note until you remove it.
Without the package
The package is under 1 KB with no dependencies. It loads the same script as the snippet and adds a typed track(). To skip it, paste the script tag into the <head> of your index.html, or of your root layout in a framework, and send events with window.ultanimus?.track().
Page weight
Add load to measure what one page load in ten downloads, for the Load page. A number from 1 to 100 sets another share.
<Analytics site="YOUR_SITE_ID" load />Web vitals
Add vitals to measure LCP, INP and CLS on real page loads, for the Web vitals page. It measures every page load; a number from 1 to 100 sets a share.
<Analytics site="YOUR_SITE_ID" vitals />Errors
Add errors to report the JavaScript errors visitors run into, for the Errors page. The component adds the script after the page mounts, so errors thrown before that are missed. Put the script tag in your HTML instead to catch those too.
<Analytics site="YOUR_SITE_ID" errors />Content Security Policy
If your site sends a Content Security Policy, add the tracker's domain to script-src and connect-src, or the browser blocks the script:
script-src 'self' https://cdn.ultanimus.com
connect-src 'self' https://cdn.ultanimus.comScript tag explains where the policy usually lives.
Send an event
Call track with a name and, if you want, properties.
import { track } from '@ultanimus/react'
track('signup', { plan: 'pro' })Custom events covers naming and properties.
Signed-in users
Pass your own ID for the signed-in person, or null when nobody is, and they count as one visitor across days and devices.
<Analytics site="YOUR_SITE_ID" user={session?.userId ?? null} />Signed-in users explains what changes and what is stored.
IDs in page addresses
Pass url to replace the IDs and names in your page addresses before they leave the browser. Page addresses covers what the function gets and returns.
<Analytics site="YOUR_SITE_ID" url={(url) => url.replace(/\/orders\/\d+/, '/orders/[id]')} />Outbound links and downloads
Add outbound to record clicks on links to other sites, and downloads for clicks on files. Links and downloads lists what counts.
<Analytics site="YOUR_SITE_ID" outbound downloads />