Other frameworks
Add the script or the React component to TanStack Start, React Router, SvelteKit, Nuxt, Astro, Vite, Angular, Laravel, Rails and more.
Every framework below takes the same one-line script, or the React component when it runs on React. Add it once, in your site's main layout. The script counts a pageview each time the router changes the address, so client-side navigation needs no extra code.
The CLI can do it for you. npx @ultanimus/cli init finds TanStack Start, React Router, SvelteKit, Nuxt, Astro, Vite and Angular projects and adds the code.
Apps that route by hash count too. An address like /#/pricing shows up in your reports as the page /#/pricing. A plain anchor like /docs#install still counts as /docs.
React frameworks
TanStack Start and React Router run on React, so use the React package. It gives you the component and a typed track().
bun add @ultanimus/reactnpm install @ultanimus/reactpnpm add @ultanimus/reactyarn add @ultanimus/reactTanStack Start
Render Analytics once in the root route, inside <body>.
import { Analytics } from '@ultanimus/react'
function RootDocument({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<HeadContent />
</head>
<body>
{children}
<Analytics site="YOUR_SITE_ID" />
<Scripts />
</body>
</html>
)
}React Router
Render Analytics once in the root Layout, inside <body>. Remix 2 apps use the same file.
import { Analytics } from '@ultanimus/react'
export function Layout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<Meta />
<Links />
</head>
<body>
{children}
<ScrollRestoration />
<Scripts />
<Analytics site="YOUR_SITE_ID" />
</body>
</html>
)
}React lists the component's props.
SvelteKit
Paste the script into src/app.html, inside <head> and above %sveltekit.head%.
<head>
<meta charset="utf-8" />
<script defer src="https://cdn.ultanimus.com/s.js" data-site="YOUR_SITE_ID"></script>
%sveltekit.head%
</head>Nuxt
Add the script to app.head in your Nuxt config. Nuxt renders it on every page.
export default defineNuxtConfig({
app: {
head: {
script: [{ src: 'https://cdn.ultanimus.com/s.js', defer: true, 'data-site': 'YOUR_SITE_ID' }],
},
},
})Astro
Paste the script into the <head> of the layout your pages share. is:inline tells Astro to leave the tag as it is instead of bundling it. With <ClientRouter />, the tag stays in place across navigations and counts each one.
<head>
<meta charset="utf-8" />
<script is:inline defer src="https://cdn.ultanimus.com/s.js" data-site="YOUR_SITE_ID"></script>
</head>Vite
For a Vue, Svelte, Solid or Preact app built with Vite, paste the script into index.html at the project root. A React app can use the React component instead.
<head>
<meta charset="UTF-8" />
<script defer src="https://cdn.ultanimus.com/s.js" data-site="YOUR_SITE_ID"></script>
</head>Angular
Paste the script into src/index.html, inside <head>.
React Native and Expo
iOS and Android apps use the React Native package instead of the script. On Expo web it loads the script for you.
Swift
iPhone and iPad apps built with SwiftUI or UIKit use the Swift package.
Server-rendered and static sites
Paste the script once, into the <head> of the base template your other templates extend. The usual file:
| Framework | File |
|---|---|
| Laravel | resources/views/layouts/app.blade.php |
| Rails | app/views/layouts/application.html.erb |
| Django | templates/base.html |
| Hugo | Your theme's baseof.html or head partial |
| Jekyll | _includes/head.html |
| Eleventy | The base layout in _includes |
Send events
React apps import track from the package. Everywhere else, the script adds window.ultanimus.track. Call it from a click or submit handler:
window.ultanimus?.track('signup', { plan: 'pro' })The ?. skips the call when the script has not loaded, for example when an ad blocker stopped it. In TypeScript, declare the global once, such as in src/app.d.ts in SvelteKit:
declare global {
interface Window {
ultanimus?: { track: (name: string, props?: Record<string, string | number | boolean>) => void }
}
}
export {}Custom events covers names, properties and a queue for events sent before the script loads.
Check that it works
Open your site, then your dashboard. The install check turns live with the first visit. If it keeps waiting, Script tag lists what to check.
Next steps
- If your site sends a Content Security Policy, allow the tracker's domain.
- Pass the signed-in user, so one person counts once across days.
- Record outbound links and downloads with
data-outboundanddata-downloads. - Script tag lists every attribute the snippet takes.