# Set up with an AI agent

Copy one prompt and let your coding agent install the script and suggest events.

Coding agents like Claude Code, Cursor and Codex can add Ultanimus to your project. Copy the prompt, paste it into your agent, and replace `YOUR_SITE_ID` with the ID from your site's settings.

```text
Add Ultanimus analytics to this project.

If the Ultanimus MCP server is connected, use its create_site, get_snippet and install_status tools for the site ID, the snippet and the final check instead of asking me.

1. Read the project and find its framework: Next.js with the App Router, another React framework, React Native or Expo, a Swift app in Xcode, or anything else. If the project already loads the Ultanimus script or package, stop and tell me where, because a second copy counts nothing.
2. Install the matching option:
   - Next.js: install @ultanimus/next and render <Analytics site="YOUR_SITE_ID" /> once in the root layout, inside <body>.
   - React, including TanStack Start and React Router: install @ultanimus/react and render <Analytics site="YOUR_SITE_ID" /> once near the root of the app. In TanStack Start and React Router that is inside <body> of the root route.
   - React Native or Expo: install @ultanimus/react-native with npx expo install, or npm in a bare app. With Expo Router, render <Analytics site="YOUR_SITE_ID" /> from @ultanimus/react-native/expo-router once in the root layout, app/_layout.tsx or src/app/_layout.tsx. With React Navigation, render it from @ultanimus/react-native/navigation inside <NavigationContainer>, with app and version props. Then tell me to add the app's bundle ID or package name under Apps in the site's settings.
   - A Swift app for iPhone or iPad: add the Swift package https://github.com/ultanimus/ultanimus-swift to the app target, from version 0.1.0. Add import Ultanimus and call Ultanimus.start(site: "YOUR_SITE_ID") once when the app launches, in the App's init or in application(_:didFinishLaunchingWithOptions:). Name each screen with .screen("Name") on its SwiftUI view, or Ultanimus.screen("Name") in viewDidAppear, and leave IDs out of the names. Then tell me to add the app's bundle ID under Apps in the site's settings.
   - Anything else: add <script defer src="https://cdn.ultanimus.com/s.js" data-site="YOUR_SITE_ID"></script> once to the shared <head>: src/app.html in SvelteKit, app.head.script in nuxt.config, the shared layout in Astro, index.html in Vite and Angular.
   Use exactly one of these. Never add both a package and the script tag.
3. Use the package manager the project already uses. Do not change anything else.
4. Look for a Content-Security-Policy: headers() in next.config, the proxy or middleware file, a <meta http-equiv="Content-Security-Policy"> tag, or the server or host config. If there is one, add https://cdn.ultanimus.com to script-src and connect-src, or to default-src when those two are missing. Leave every other source as it is. Without this the browser blocks the script and no event arrives.
5. Suggest these, and ask me before adding any of them:
   - Up to five custom events for the actions that matter in this product, such as signup or purchase, sent with track(name, props) from the package, Ultanimus.track(name, props) in Swift, or window.ultanimus.track(name, props) with the script tag.
   - If people sign in, the signed-in user's database ID, never an email address, with the user prop or data-user.
   - Path patterns for pages that should not count, such as /admin/*, a signed-in app on the same domain or internal tools. With the MCP server, add them with create_page_rule. Otherwise tell me to add them under Excluded pages in the site's settings.
   - Speed measurements: vitals for Core Web Vitals and load for page weight, as props on the component or data-vitals and data-load on the script tag.
   - JavaScript errors visitors run into, with the errors prop or data-errors on the script tag.
6. Never put an API key in browser code. Events sent from the server use @ultanimus/node on Node.js, Bun or Deno, or https://api.ultanimus.com/v1/events from any other language, with the key kept in ULTANIMUS_API_KEY.
7. When you are done, list the files you changed, say whether you changed a Content-Security-Policy, and tell me to open the site and watch the install check on the dashboard turn live.

Docs written for agents: https://ultanimus.com/llms.txt
```

## What the agent does

### Finds your stack

It reads the project to see whether it uses Next.js, another React framework or something else, such as SvelteKit, Nuxt or Astro, and picks the matching install. If the project already tracks, it stops and tells you where, so you never load a second copy.

### Adds the script

It installs the package or adds the script tag once, in the root layout, with the package manager the project already uses. If the project sets a [Content Security Policy](/docs/install/script-tag#content-security-policy), it adds the tracker's domain to `script-src` and `connect-src` so the browser lets the script run.

### Suggests what to add

It proposes a few custom events for the actions that matter, like a signup or a purchase. It also offers the signed-in user's ID, [pages to exclude](/docs/tracking/excluded-pages) such as an admin area, and the Web vitals and Load measurements. It asks you before adding any of them.

### Hands back

It lists the files it changed. Open your site and watch the install check on your dashboard turn live.

> **Warning:** Review the changes before you merge them, as you would for any pull request. The prompt tells the agent never to put an API key in browser code.

## With the MCP server

If your agent supports MCP, connect the [MCP server](/docs/api/mcp) with a key that has the `sites:write` scope. The agent can then create the site, get the snippet, add the excluded pages you agree on and confirm the first event itself, so nobody copies a site ID by hand.

## Docs for agents

Every docs page is also plain Markdown, linked as "View as Markdown" under On this page. [llms.txt](/llms.txt) lists every page with a one-line summary, so an agent can read the docs without a browser.
