Set up tracking with a coding agent or AI builder
Copy one setup prompt into Claude Code, Cursor, Codex, Lovable, Bolt, v0 or Replit to install the script, track goals, identify users and attribute revenue.
Claude Code, Cursor, Codex, Lovable, Bolt, v0 and Replit can set up SuprAnalytics for you from one prompt. It installs the script in the right place for your framework, tracks your key actions as goals, identifies signed-in users and passes the visitor id to your checkout for revenue attribution.
The easiest way: open Settings → General → Tracking of the website, pick the AI agent tab and click Copy prompt. That one has your website's id and domain filled in. Here it is with YOUR_WEBSITE_ID and yourdomain.com to replace:
# Add SuprAnalytics to this app
SuprAnalytics is a privacy-friendly web analytics tool that also attributes revenue to the traffic that produced it. Set it up in this codebase: install the tracking script, track the key actions as goals, identify signed-in users, and link checkouts to visitors so payments show up next to their traffic source.
Work in this order and keep every change minimal. Don't refactor unrelated code.
## Values for this website
- Website id: `YOUR_WEBSITE_ID`
- Domain: `yourdomain.com`
- Script: `https://supranalytics.app/js/script.js`
## 1. Install the tracking script
Find out which framework this app uses, then add this tag once, to the `<head>` of every page (the root layout or the HTML template, never a single page):
```html
<script
defer
supr-website-id="YOUR_WEBSITE_ID"
supr-domain="yourdomain.com"
src="https://supranalytics.app/js/script.js"
></script>
```
Where it goes:
- Plain HTML, Vite, Create React App, Vue, Svelte (Vite): `index.html`, inside `<head>`.
- Next.js App Router: `app/layout.tsx` (or `.jsx`), using `next/script`:
```tsx
import Script from "next/script";
// inside <head> or at the top of <body> in the root layout:
<Script
defer
supr-website-id="YOUR_WEBSITE_ID"
supr-domain="yourdomain.com"
src="https://supranalytics.app/js/script.js"
/>
```
- Next.js Pages Router: the same `<Script>` in `pages/_app.tsx` (or `pages/_document.tsx` as a plain `<script>` in `<Head>`).
- Nuxt: `nuxt.config` → `app.head.script`, with the same attributes (`defer: true`, `"supr-website-id": "YOUR_WEBSITE_ID"`, `"supr-domain": "yourdomain.com"`, `src`).
- Astro: the base layout's `<head>`, as `<script is:inline defer …>` so Astro doesn't bundle it.
- SvelteKit: `src/app.html`, inside `<head>`.
- Remix / React Router: the `<head>` in `app/root.tsx`.
- Server-rendered apps (Laravel, Django, Rails, Express templates…): the base layout template's `<head>`.
- Anything else: wherever the app's shared `<head>` is rendered.
Rules:
- Keep every attribute exactly as written, including `defer`. Don't change the id, the domain or the `src` URL.
- Load it as a normal external script: don't import it, bundle it, inline its code, or move it into a component that loads later.
- Single-page app navigation is tracked automatically; don't add pageview calls on route changes.
- Visits from `localhost` count only when Track localhost is on in SuprAnalytics (Settings → General). Don't add `supr-allow-localhost` to the tag.
- Don't add `supr-cookieless` to the tag: this website is tracked with its two first-party cookies, so returning visitors are recognised. Cookieless tracking is a setting in SuprAnalytics (Settings → General → Tracking), which changes the snippet.
- If the app has a Content-Security-Policy, allow `https://supranalytics.app` in `script-src` and `connect-src`.
## 2. Track key actions as goals
Look through the app for the 3 to 6 actions that matter most to the business, for example: signup, trial started, checkout started, a key feature used, a lead or newsletter form submitted. Track each one right after it succeeds:
```js
window.supr("signup");
window.supr("start_trial", { plan: "pro" });
```
- Names: lowercase letters, digits, `_` and `-`, at most 64 characters.
- Properties are optional: up to 10, flat string or number values (keys up to 32 characters, values up to 255). Never send passwords, payment details or other secrets.
- If a call can run before the script has loaded, add this stub once in `<head>`, before the tracking script; it queues calls until the script is ready:
```html
<script>window.supr=window.supr||function(){(supr.q=supr.q||[]).push(arguments)}</script>
```
Otherwise guard the calls: `window.supr?.("signup")`.
- For plain links and buttons, an attribute works with no JavaScript: `<button supr-goal="start_trial" supr-goal-plan="pro">` (each `supr-goal-*` becomes a property).
- In TypeScript, declare it once: `declare global { interface Window { supr?: (...args: unknown[]) => void } }`.
## 3. Identify signed-in users
If the app has accounts, call this after login, after signup, and when a signed-in session loads:
```js
window.supr("identify", { user_id: user.id, email: user.email, name: user.name });
```
Only `user_id` is required. This links the visitor to the customer, and lets payments be matched by email.
## 4. Link payments to visitors (revenue attribution)
The script keeps the visitor id in a first-party cookie, `supr_visitor_id` (and the visit in `supr_session_id`); in the browser it's also `window.supr.visitorId()` and `window.supr.sessionId()`. Find how this app takes payments and pass the visitor id to the checkout:
- Stripe, Checkout Sessions created on the server: read the cookies from the request and add `metadata: { supr_visitor_id, supr_session_id }` to the session. For subscriptions, also add `subscription_data: { metadata: { supr_visitor_id } }` so renewals carry it.
- Stripe Payment Links (`buy.stripe.com`): before redirecting, add `client_reference_id=<window.supr.visitorId()>` to the link's URL.
- Polar: checkout links (`buy.polar.sh`) need nothing, the script adds the visitor id. For checkouts created on the server, add `metadata: { supr_visitor_id, supr_session_id }` from the cookies.
- Dodo Payments: payment links need nothing. For checkout sessions created on the server, add `metadata: { supr_visitor_id, supr_session_id }` from the cookies.
- Paddle: `paddle_button` checkout buttons need nothing. For `Paddle.Checkout.open()`, pass `customData: { supr_visitor_id: window.supr.visitorId(), supr_session_id: window.supr.sessionId() }`.
- Lemon Squeezy: on checkout links add `checkout[custom][supr_visitor_id]=<window.supr.visitorId()>`; with the API, put it in `checkout_data.custom.supr_visitor_id`.
- Another provider or your own billing: after a successful payment, send it from the server to `POST https://supranalytics.app/api/v1/payments` with a website API key (see https://supranalytics.app/docs/api/payments). Keep the key in an environment variable such as `SUPRANALYTICS_API_KEY`; never commit it.
If the app takes no payments, skip this step.
## When you're done
Tell me:
1. Which files you changed and where the script tag is.
2. The goal names you added and when each fires.
3. Which payment provider you found and how the visitor id is passed.
4. What's left for me to do:
- Deploy, then visit https://yourdomain.com in a normal browser window. The first visit shows up on the dashboard within seconds.
- If payments were linked, connect the provider's webhook in SuprAnalytics: https://supranalytics.app/YOUR_WEBSITE_ID/settings?tab=revenue
- Add any API key the code now reads from the environment.
Docs: https://supranalytics.app/docsThe agent tells you what it changed and what's left for you, like connecting your payment provider's webhook.
Check it works
Open your website in a normal browser window, then the dashboard: the visit shows up within seconds, and the install card on a new website turns into the dashboard by itself. Nothing after a minute? See Not seeing any data.
AI agent or LLM? Read this page as Markdown