# 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

```bash
npm install @ultanimus/next
```

## Add the component

Render `Analytics` once, in the root layout, with your site ID.

`app/layout.tsx`

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

> **Tip:** 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:

`app/layout.tsx`

```tsx
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](/docs/tracking/custom-events#from-the-script-tag) 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:

```text
script-src 'self' https://cdn.ultanimus.com
connect-src 'self' https://cdn.ultanimus.com
```

[Script tag](/docs/install/script-tag#content-security-policy) explains where the policy usually lives.

## Next steps

- [Send custom events](/docs/tracking/custom-events) for signups and purchases.
- [Pass the signed-in user](/docs/tracking/identify) with the `user` prop, so one person counts once across days.
- [Record outbound links and downloads](/docs/tracking/links-and-downloads) with the `outbound` and `downloads` props.
- [Measure page weight](/docs/dashboard/load) with the `load` prop, and see what to fix first on the Load page.
- [Measure Core Web Vitals](/docs/dashboard/vitals) with the `vitals` prop, and see which elements slow your pages.
- [Catch JavaScript errors](/docs/dashboard/errors) with the `errors` prop, grouped by cause with the stack and the pages they break.
- [Keep IDs out of page addresses](/docs/tracking/page-addresses) with the `url` prop, from a client component.
- [Send events from your server](/docs/install/server) for anything confirmed on the backend.
