# Set up Convertics

You are an AI coding agent setting up Convertics (https://convertics.ai), real-time analytics for websites and Chrome extensions, in the user's project. There are two steps: the user signs in and gives you their keys, then you install tracking and connect the Convertics MCP.

## Step 1: get the user's keys

1. From the codebase, work out:
   - a project name (the app or package name),
   - the website's domain, if there is one,
   - the type: `extension` if this is a Chrome extension (a `manifest.json` with `"manifest_version": 3`), otherwise `website`.
2. Open this URL in the user's browser. Use `open` on macOS, `xdg-open` on Linux, `start` on Windows. If you can't open a browser, show the link and ask the user to open it. URL-encode the values and leave out any you don't know.

   `https://convertics.ai/platform?connect=agent&name=NAME&domain=DOMAIN&type=TYPE`

3. Tell the user: "Sign in, pick or create your project, then copy the prompt it shows and paste it back here." Then wait for that prompt. Don't guess or invent keys.

## Step 2: install (once the user pastes the prompt with their keys)

The pasted prompt has the public key (`cp_…`), the secret key (`cs_…`) and the MCP URL.

1. **Website:** add this tag before `</head>` in the site's root layout or HTML template:
   `<script src="https://scripts.convertics.ai" data-public-key="PUBLIC_KEY" defer></script>`
   Page views, referrers, UTM tags and AI-assistant traffic are tracked automatically.
2. **Chrome extension (Manifest V3):** the script must be bundled, not loaded from a URL.
   - `npm i @convertics-ai/script`
   - add `"storage"` to `"permissions"` in `manifest.json`
   - in the popup, options page and any content script: `import { init } from "@convertics-ai/script"; init("PUBLIC_KEY", { type: "extension" })`
   - the extension's ID must be listed in the Convertics project (the user adds it when creating the project).
   Installs, uninstalls, versions and surfaces are tracked automatically.
3. **Custom events (optional):** `init()` returns `{ track, identify }`.
   `const convertics = init("PUBLIC_KEY")` then `convertics.track("signup_clicked", { plan: "pro" })`.
4. **Connect the MCP** in the client you are running in:
   - Claude Code: `claude mcp add --transport http convertics-analytics MCP_URL --header "x-api-key: SECRET_KEY"`
   - Cursor: add `{ "mcpServers": { "convertics": { "url": "MCP_URL", "headers": { "x-api-key": "SECRET_KEY" } } } }` to `~/.cursor/mcp.json`
   - Clients that only take a URL: `MCP_URL?key=SECRET_KEY`
5. **Never commit the secret key.** It belongs in the MCP config only, not in the repository. The public key is safe in client code.
6. **Verify:** open the site (or the extension) once, then ask the Convertics MCP: "How many people are on my site right now?"

Prefer to do it by hand? Every key and per-client command is at https://convertics.ai/platform/access.
