Agent setup
Paste one prompt into your coding agent. It does the setup.
Claude Code, Codex or Cursor installs the tracker, writes your tracking plan, connects payments and checks that the first events arrive. You review the changes before you merge them.
twelvebit is privacy-friendly web analytics that your coding agent installs. Paste one prompt into Claude Code, Codex or Cursor. The agent adds a 5 KB script, writes the tracking plan as analytics.yaml, connects your payment provider and checks the first events. Later it reads the numbers through the MCP server.
A setup run, replayed
Prompt: Set up twelvebit analytics in this project for demo.twelvebit.app. [Pasted text +12 lines]
Read (package.json, app/layout.tsx)
Next.js 16, App Router, Stripe Checkout
Update (app/layout.tsx)
+4 lines · tracking script in <head>
Write (analytics.yaml)
+28 lines · 4 events, 1 funnel
Write (lib/track.ts)
+22 lines · typed helpers
Update (app/api/checkout/route.ts)
+3 lines · visitor ID in checkout metadata
Bash (curl -X PUT …/api/v1/tracking-plan)
200 · plan saved, 4 events added
Bash (claude mcp add --transport http twelvebit …/api/mcp)
MCP server connected
Bash (curl …/api/v1/install-check)
4 events received in the last minute
Done. I added 4 events (signup, submit_tool, bump, checkout) and passed the visitor ID to Stripe Checkout, so payments are attributed. Review the diff before you merge.
- Site addeddemo.twelvebit.app
- First page view14:02:07
- Tracking plan4 events
- First goal: signup14:02:31
- Revenue: first payment$29 · test mode
- A twelvebit account and a site (14-day free trial)
- A coding agent with access to your repo and a terminal
- About five minutes to read the diff
npx -y twelvebit@latest initStep by step
What the agent does, in order.
Each step comes straight from the setup prompt. Nothing happens that you cannot see in the diff or in the terminal.
Reads your project
The agent finds the framework, the root layout, the sign-up flow and the checkout code. It reuses an analytics.yaml that is already there.
package.jsonapp/layout.tsxAdds the tracking script
One deferred script tag in the <head>, added the way your framework adds head scripts. For Next.js that is next/script in the root layout.
app/layout.tsxTracks the actions that matter
It picks the 3 to 8 actions that matter most for your product, such as signup, start_trial or purchase, and tracks each one where it happens. Plain links and buttons can use a data-tb-goal attribute instead.
window.twelvebit?.("signup", { plan: "pro" })Writes the tracking plan
analytics.yaml lists every event with a description and its props. A small typed helper wraps the tracker, so event names and props match the plan.
analytics.yamllib/track.tsConnects payments
On the server, the agent reads the _tb_vid and _tb_sid cookies and adds them to the checkout metadata. Each payment then joins the visit that started it. This works with Stripe, Polar, Lemon Squeezy, Paddle and Dodo Payments.
twelvebit_visitor_idtwelvebit_session_idPushes the plan and connects MCP
The agent sends analytics.yaml to twelvebit, so the dashboard knows your events. Then it adds the twelvebit MCP server, so it can read the numbers later.
PUT /api/v1/tracking-plan/api/mcpVerifies the first events
It runs the app, asks the install check for the last events, and lists what it added and where. The dashboard shows the same events live while you watch.
GET /api/v1/install-check
The prompt
Read the whole prompt before you paste it.
This is the prompt for the demo site, demo.twelvebit.app. In your dashboard the prompt has your own site ID, and the key stays in an environment variable.
Set up twelvebit analytics in this project for demo.twelvebit.app. Before you do anything else, tell me: "A browser tab opens in a few seconds. Approve the connection there. One approval is enough." 1. Run this first, from the project root, before you read the rest of the project or the guide: npx -y twelvebit@latest init demo.twelvebit.app It prints a link and a code and opens the browser. I approve it once. The sign-in is then saved on this computer, and every later command uses it: do not start another sign-in. The command waits for me (up to 10 minutes), so give it a long timeout or run it in the background. If it stops before I approve, run the same command again: it continues with the same code and does not open a new tab. It saves the site key in .env by itself: do not print the key or put it in chat. It also writes analytics.yaml and a twelvebit section in AGENTS.md. 2. Follow the twelvebit section in AGENTS.md: add the script tag that init printed to the shared layout, track the 3 to 8 actions that matter, and describe them in analytics.yaml. 3. Run npx -y twelvebit@latest codegen, then npx -y twelvebit@latest check --strict. 4. Verify on production only. twelvebit does not track local development, by design: the script ignores localhost and 127.0.0.1, and the server accepts events only from demo.twelvebit.app and its subdomains. Do not start a local copy, add data-allow-localhost or set up local tracking, unless I ask for it. Deploy the change to demo.twelvebit.app (or tell me what to deploy and wait for me), then run npx -y twelvebit@latest status until it shows the first event from demo.twelvebit.app. 5. Optional, at the end: connect the MCP server so that you can read the data later. npx -y twelvebit@latest mcp claude --run (it uses the site key in .env: no new approval in the browser). The tools load the next time Claude Code starts. Full guide, if you need more: https://twelvebit.app/setup.md. At the end, tell me whether the first event from demo.twelvebit.app has arrived (that is when the setup is complete), and list the events you added and where.
Tracking plan
The plan is a file in your repo.
analytics.yaml is the source of truth for your events. It goes through code review, and the agent pushes it to twelvebit so the dashboard can show the health of each event.
# analytics.yaml · written by your agent, reviewed by you version: 1 project: demo.twelvebit.app integrations: [stripe] events: signup: description: A visitor creates an account props: role: { type: string, enum: [maker, buyer] } submit_tool: description: A maker submits a tool to the directory checkout: description: A maker opens the checkout for a paid plan props: plan: { type: string } value: { type: number } bump: description: A signed-in user bumps a listing props: tool: { type: string } dashboards: funnels: - name: Visit to paid listing steps: ["page:/pricing", signup, checkout, payment]
// lib/track.ts · typed helpers from analytics.yaml type Plan = "boost" | "featured" | "lifetime"; export const track = { submitTool: (p: { category: string }) => window.twelvebit?.("submit_tool", p), checkout: (p: { plan: Plan; value: number }) => window.twelvebit?.("checkout", p), }; track.submitTool({ category: "ai-coding" }); track.checkout({ plan: "featured", value: 29 });
MCP server
Your agent can read the numbers too.
The twelvebit MCP server gives your agent read access to your analytics. Ask which page brought the most customers, then ask it to improve that page.
claude mcp add \ --transport http twelvebit \ https://twelvebit.app/api/mcp
codex mcp add twelvebit \ --url https://twelvebit.app/api/mcp codex mcp login twelvebit
{
"mcpServers": {
"twelvebit": {
"url": "https://twelvebit.app/api/mcp"
}
}
}Each one opens a browser to sign in, with no key to copy. For CI or a server without a browser, send an API key instead:
claude mcp add \ --transport http twelvebit \ https://twelvebit.app/api/mcp \ --header "Authorization: Bearer $TWELVEBIT_API_KEY"
get_overviewVisitors, revenue, customers and conversion, with the previous periodget_revenueRevenue by channel and plan, and recent payments with their credited channelget_breakdownTop channels, pages, countries or devices, with attributed revenueget_funnelCounts per step, conversion by channel and days to convertget_journeyOne person's visits, events and paymentsget_realtimeVisitors online now and visitors per minuteget_install_statusWhich planned events have arrivedupdate_tracking_planValidate and save a new analytics.yaml
Guardrails
Rules the agent follows.
Keys stay out of chat and git
The agent writes the API key to .env only when .env is in .gitignore. The tracker in the browser needs no secret.
No personal data in events
Event props are flat strings, numbers or booleans. The prompt tells the agent not to put names or emails in them.
You review every change
The agent keeps changes small and follows your code style. You read the diff and merge it like any other pull request.
Safe to run again
Run the prompt again after a refactor. The agent reuses the plan that is already in your repo and fills in what is missing.
Paste one prompt. Watch the first events arrive.
Start free. Your agent does the setup, and you see revenue next to the traffic that brought it.
14-day free trial · cancel any time