# 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.

> **Tip:** The [CLI](/docs/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.

> **Note:** 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()`.

```bash
npm install @ultanimus/react
```

### TanStack Start

Render `Analytics` once in the root route, inside `<body>`.

`src/routes/__root.tsx`

```tsx
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.

`app/root.tsx`

```tsx
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](/docs/install/react) lists the component's props.

## SvelteKit

Paste the script into `src/app.html`, inside `<head>` and above `%sveltekit.head%`.

`src/app.html`

```html
<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.

`nuxt.config.ts`

```ts
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.

`src/layouts/Layout.astro`

```html
<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](/docs/install/react) instead.

`index.html`

```html
<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](/docs/install/react-native) 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](/docs/install/swift).

## 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:

```ts
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:

```ts
declare global {
  interface Window {
    ultanimus?: { track: (name: string, props?: Record<string, string | number | boolean>) => void }
  }
}

export {}
```

[Custom events](/docs/tracking/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](/docs/install/script-tag#check-that-it-works) lists what to check.

## Next steps

- If your site sends a Content Security Policy, [allow the tracker's domain](/docs/install/script-tag#content-security-policy).
- [Pass the signed-in user](/docs/tracking/identify), so one person counts once across days.
- [Record outbound links and downloads](/docs/tracking/links-and-downloads) with `data-outbound` and `data-downloads`.
- [Script tag](/docs/install/script-tag) lists every attribute the snippet takes.
