Skip to content

Install with an AI agent

Hand this prompt to Claude Code, Codex or Cursor and it installs tracking for you.

Why this exists

Adding a script tag is easy on a plain HTML site. It is more fiddly in Next.js, Remix, Astro or a tag manager, and fiddlier again if you also want product events and machine tracking. Your AI coding agent already knows your file layout and your framework, so the fastest install is to tell it what to do.

Copy the prompt below, paste it into your agent, and replace YOUR_KEY with your tracking key. The prompt is written to give the agent enough context to make correct decisions on its own, including what not to do.

The prompt

Paste into your coding agent
# Task: install Termind analytics in this project

You are adding Termind analytics. Termind is a cookieless web and product
analytics tool. It loads from a single script tag and exposes a global
`termind` object.

## Credentials

Tracking key: `YOUR_KEY`
Script URL:   `https://www.termind.tech/t.js`

## What to do

### 1. Load the tracker on every page

Add this tag so it renders inside `<head>` on all pages:

```html
<script defer src="https://www.termind.tech/t.js" data-key="YOUR_KEY"></script>
```

Put it in the right place for this project's framework:

- Next.js App Router: `app/layout.tsx`, inside `<head>`. Use `next/script`
  with `strategy="afterInteractive"` if the project already uses it elsewhere,
  otherwise a plain `<script>` tag is correct and simpler.
- Next.js Pages Router: `pages/_document.tsx`, inside `<Head>`.
- Remix or React Router: the root route's `<head>`.
- Astro: the shared base layout.
- SvelteKit: `src/app.html`.
- Vue or Nuxt: `nuxt.config` head config, or `index.html` for plain Vue.
- Plain HTML: every page's `<head>`, or the shared header include.

Do not add a client side router hook for page views. The tracker detects SPA
navigation on its own, and a second hook would double count every view.

**Prefer a first-party proxy.** If this project has a server (Next.js, Remix,
Nuxt, or any host with rewrites), set up rewrites and load the script from the
project's own domain instead of ours. It beats ad blockers and sidesteps CSP
entirely:

```javascript
// next.config.js
async rewrites() {
  return [
    { source: "/pulse.js", destination: "https://www.termind.tech/t.js" },
    { source: "/v1/:path*", destination: "https://www.termind.tech/v1/:path*" },
  ];
}
```

Then use `src="/pulse.js"` in the tag. Do not name the file analytics.js,
stats.js or termind.js: blocklists match those words in the path.

Equivalents for other hosts:

- `vercel.json` -> a `rewrites` array with the same two entries.
- Netlify `_redirects` -> `/pulse.js  https://www.termind.tech/t.js  200` and
  `/v1/*  https://www.termind.tech/v1/:splat  200`.
- Nuxt -> `routeRules` with `proxy`.
- Nginx -> two `location` blocks with `proxy_pass`.

**If this project is a single page app, the two rewrites MUST come before the
catch-all that serves index.html.** A catch-all listed first swallows them, and
`/pulse.js` then returns your HTML with a JavaScript content type. The tag looks
present, nothing executes, and there is no error message anywhere.

**Check for a Content Security Policy.** Look for a CSP in the middleware, the
Next.js config, the hosting config (vercel.json, netlify.toml, _headers), or a
meta tag. If one exists, add Termind to BOTH directives:

```
script-src  ... https://www.termind.tech
connect-src ... https://www.termind.tech
```

Adding only script-src is a silent failure: the tag loads, every event is
blocked on the way back, and the dashboard stays empty with no error the site
owner will notice.

### 2. Identify users after authentication

Find where this project confirms a signed in user on the client. That is
usually an auth callback, a session provider, or a post login redirect. Add:

```javascript
window.termind?.identify(user.id, { email: user.email });
```

Rules:
- Use the project's own stable user id, never the email as the id.
- Call it once per session, not on every render. If the project has an auth
  context or session hook, call it in an effect keyed on the user id.
- On sign out, call `window.termind?.reset()`.
- If this project has no authentication, skip this step and say so.

### 3. Track the events that matter

Add `window.termind?.track("event_name", { ...props })` at the moments that
represent real progress in this product. Look at the actual features and pick
the three to five that matter. Typical examples:

```javascript
window.termind?.track("signed_up", { plan: "free" });
window.termind?.track("project_created");
window.termind?.track("invited_teammate");
```

Rules:
- Past tense, snake_case names. `signed_up`, not `Sign Up`.
- Never include passwords, tokens, API keys, card numbers, or full addresses
  in properties.
- Do not instrument every button. Pick the moments that indicate value.

### 4. Machine tracking, only if this project has a server

If the project has middleware or a server runtime, record which AI assistants
and crawlers read the pages. Crawlers do not execute JavaScript, so this cannot
be done from the browser.

```typescript
const ua = request.headers.get("user-agent") ?? "";
fetch(
  `https://www.termind.tech/v1/crawl?key=YOUR_KEY&ua=${encodeURIComponent(ua)}` +
    `&path=${encodeURIComponent(new URL(request.url).pathname)}`,
).catch(() => {});
```

Never await this call and never let it throw. If the project is fully static
with no server, skip this step and say so.

### 5. Verify it before you report success

Do not report this as done because the code looks right. Check it:

1. Build and serve the project.
2. Fetch the script path you used. If you proxied, `curl -sI http://localhost:PORT/pulse.js`
   must return a JavaScript content type. If it returns `text/html`, the
   catch-all swallowed the rewrite and the rewrites need to move above it.
3. Load a page and confirm a request to `/v1/batch` returns 200. A 401 means the
   key is wrong, a 403 means the domain is not on the project's allowed list.

If you cannot run the project, say so explicitly rather than assuming it works.

## Constraints

- Change only what is needed for the above. Do not reformat files, do not
  upgrade dependencies, do not refactor surrounding code.
- Add no npm packages. Termind needs none.
- Match the surrounding code style, including quote style and semicolons.
- If the project already has a Termind script tag, do not add a second one.

## When you are done

State plainly anything you could not verify. A confident "installed
successfully" that turns out to be a rewrite ordering bug costs the owner more
time than saying you were unable to test it.

Report back with:
1. Each file you changed and why.
2. The event names you chose, and what each one means.
3. Whether you added identify and machine tracking, or skipped them and why.
4. Whether you verified the script serves and events return 200, or could not.

What the agent will do

  1. 1
    Add the snippet correctly for your frameworkIn Next.js App Router that means the root layout. In Remix it is the root route. In Astro it is the base layout. The agent picks the right one because it can see your project.
  2. 2
    Wire up identify after sign-inThis is what turns anonymous sessions into people, and people into funnels, retention and revenue attribution. Without it you get traffic numbers and nothing else.
  3. 3
    Add machine tracking if you have a serverOne call from your middleware records which AI assistants and search crawlers read your pages. Crawlers never run JavaScript, so the script tag alone cannot see them.

Read the diff before you accept it. The prompt tells the agent not to touch anything unrelated, but you should still check.

NextEvents and peopleSend custom events, identify users, and group them into accounts.