Next.js
Install the Next.js package and render the Analytics component once, in your root layout.
The Next.js package adds the script for you from your root layout.
Install the package
bun add @ultanimus/nextnpm install @ultanimus/nextpnpm add @ultanimus/nextyarn add @ultanimus/nextAdd the component
Render Analytics once, in the root layout, with your site ID.
import { Analytics } from '@ultanimus/next'
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
{children}
<Analytics site="YOUR_SITE_ID" />
</body>
</html>
)
}Open your site, and the install check on your dashboard turns live with the first visit.
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, put the script tag in the <head> of your root layout instead:
export default function RootLayout({ children }) {
return (
<html lang="en">
<head>
<script defer src="https://cdn.ultanimus.com/s.js" data-site="YOUR_SITE_ID"></script>
</head>
<body>{children}</body>
</html>
)
}Then send events with window.ultanimus?.track(), as Custom events shows.
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.
Next steps
- Send custom events for signups and purchases.
- Pass the signed-in user with the
userprop, so one person counts once across days. - Record outbound links and downloads with the
outboundanddownloadsprops. - Measure page weight with the
loadprop, and see what to fix first on the Load page. - Measure Core Web Vitals with the
vitalsprop, and see which elements slow your pages. - Catch JavaScript errors with the
errorsprop, grouped by cause with the stack and the pages they break. - Keep IDs out of page addresses with the
urlprop, from a client component. - Send events from your server for anything confirmed on the backend.
