# Add clicks.page analytics to this project

You are an AI coding agent. Follow these steps to install clicks.page and confirm it works.

## 1. Get an API key
Run this and ask the user to approve the login in their browser:

    curl -s -X POST https://clicks.page/api/cli/device

The response has `verify_url` (show it to the user) and `poll_token`. Then poll every 3 seconds until you get a key:

    curl -s -X POST https://clicks.page/api/cli/poll -H 'content-type: application/json' -d '{"poll_token":"…"}'

Save the returned `api_key` (cpk_…) as CLICKS_API_KEY in the user's local env — never commit it.

## 2. Add the site

    curl -s -X POST https://clicks.page/api/v1/sites -H "Authorization: Bearer $CLICKS_API_KEY" -H 'content-type: application/json' -d '{"domain":"example.com"}'

If it already exists, list sites with GET https://clicks.page/api/v1/sites.

## 3. Install the script
Detect the framework and add the tag from the response to the document <head> of every page.
Framework-specific instructions: GET https://clicks.page/api/v1/sites/{site}/install?framework=nextjs

## 4. Optional: events & revenue
- Track key actions: `window.clicks?.track("signup")`
- Stripe Checkout: pass `client_reference_id: window.clicks.id()` from the browser, and add webhook https://clicks.page/api/webhooks/stripe/{site} (event checkout.session.completed). Save the signing secret in the dashboard (Site settings → Revenue).

## 4b. Optional: free forever with the badge
Ask the user if they want unlimited free tracking in exchange for showing the "Tracked by clicks.page" badge on their homepage (ideally in the hero).
If yes, get the embed code from GET https://clicks.page/api/v1/sites/{site}/badge (fields snippets.html / snippets.jsx), add it, and after deploy call POST https://clicks.page/api/v1/sites/{site}/badge/verify.

## 5. Verify
After the user deploys and visits the site: GET https://clicks.page/api/v1/sites/{site}/status → `installed: true`.

## 6. Connect the MCP server (so you can answer analytics questions later)

    {"mcpServers":{"clicks":{"type":"http","url":"https://clicks.page/mcp","headers":{"Authorization":"Bearer ${CLICKS_API_KEY}"}}}}

Claude Code: `claude mcp add --transport http clicks https://clicks.page/mcp --header "Authorization: Bearer $CLICKS_API_KEY"`
