# Add analytics with your coding agent (Claude Code, Cursor, Codex)

Dataflare was built to be installed and queried by coding agents. Paste this into Claude Code, Cursor, Codex or any agent that can run commands:

> Add Dataflare analytics to this project: run `npx dataflare-cli init`, track signups and purchases, then show me today's visitors.

## What the agent gets

`dataflare init` deploys Dataflare into your Cloudflare account, then writes three files into your project:

- **`AGENTS.md`** (and `CLAUDE.md` if you have one): how to name events, how to document them, and how to verify they arrive.
- **`.claude/skills/glass/SKILL.md`**: a skill with the query recipes below.
- **`.mcp.json`**: an MCP server entry (`npx dataflare-cli mcp`) that forwards to your Worker with the key from `.glass/credentials.json`, so no secret goes into the config file.

From then on the agent has the [MCP tools](/docs/agents/#tools): overview, trends, funnels, retention, sources, site health, people, cohorts, replays, flags, experiments and read-only SQL. Every result includes a one-sentence summary, the SQL that ran and a link to the same view in the dashboard, so you can check its work.

## Questions that work well

- *"Why did signups drop last week?"* The agent compares periods, runs the funnel broken down by browser, finds sessions that started signup and didn't finish, and reads their replay transcripts.
- *"Add tracking for invites and show me a funnel from signup to first invite."*
- *"Which campaigns bring people who pay?"*
- *"Test a shorter pricing page against the current one."* It creates a flag and an experiment, branches on `glass.flag()` in your code, and reads the result when it's ready.

## Keep agents read-only if you prefer

```sh
npx dataflare-cli key --read
```

Use the read key for agents that shouldn't change flags or experiments; write tools then return a clear error.

## Without MCP

The same operations are available as a CLI with `--json` on every command, and as an HTTP API (`GET <worker>/api` lists every endpoint). See [Agents: MCP, CLI and HTTP](/docs/agents/).
