README.md
# Marketing Analytics (AgentRove native agent)
`agentrove.marketing-analytics` 0.2.1 · MIT · Node.js >= 20 · no npm dependencies · fully offline
Published by AgentRove (provisional, configurable name). Package identifiers keep the agentrove prefix for compatibility.
Analyses CSV exports **you provide**: event-level exports (sessions or events with `utm_source`,
`utm_medium`, `utm_campaign`, plus signups, downloads or any other events) and aggregated spend
reports (rows per day, week or campaign with spend, impressions, clicks, conversions, revenue). Every number in the output is a count
or ratio of your rows. Rows it cannot read are counted and reported; nothing is estimated, imputed or
made up. A denominator of zero gives `null` ("n/a"), never 0%.
## Tools
| Tool | What it does |
| --- | --- |
| `funnel` | Ordered funnel over distinct users: step 1 is each user's first step-1 event, each later step is the first matching event at or after the previous step (optional `window_days` from step 1). Users, step-to-step and overall conversion with 95% Wilson intervals. |
| `attribution` | First-touch and last-touch credit for `conversion_events` (e.g. `signup`, `download`): the user's earliest and latest UTM-tagged row within `lookback_days` (default 30) before the conversion. Conversions without a touch are reported as **unattributed**. Direct traffic (`(direct)` / `(none)`) is not a touch. Group by source, source/medium, campaign or all three. |
| `cohort_retention` | Weekly cohorts (ISO weeks, Monday 00:00 UTC) by first event or `cohort_event`; share of the cohort active in each following week (`activity_events` optional). Weeks after your data ends are `observed: false` with `null`, and the last week is flagged `partial`. |
| `campaign_comparison` | Table per UTM group: visitors, sessions, per-event converted users and rate with 95% Wilson interval, `confidence: low` below `min_sample` visitors (default 30), notes for fewer than 5 conversions, and a two-proportion z-test between the two best groups (marked unreliable when any cell count is below 5). Includes a Markdown table. |
| `build_report` | Runs what your inputs allow and returns `report` (JSON) plus `markdown` (summary with tables and notes). |
| `channel_performance` | Spend efficiency from **aggregated** exports (for example a Google Ads or Meta campaign report, or a weekly channel spend sheet): sums of spend, impressions, clicks, conversions and revenue, and CTR, CPC, CPM, conversion rate (95% Wilson interval for whole counts), CPA, ROAS, revenue per conversion, share of spend and share of conversions per `channel`, `campaign`, `channel_campaign`, ISO `week` or `channel_week`. Adds factual comparisons (lowest/highest CPA among groups with at least `min_conversions`, default 10; groups whose share of spend exceeds their share of conversions by 10+ points; ROAS below 1) and a Markdown table. |
All tools are side-effect free and need no keys.
### Input data
```json
{
"data": [
{ "name": "sessions.csv", "csv": "<file text>", "default_event": "session" },
{ "name": "events.csv", "csv": "<file text>" },
{ "name": "signups.csv", "csv": "<file text>", "default_event": "signup" }
],
"columns": { "user_id": "client_id" }
}
```
- Header row required; comma, semicolon or tab delimiters; quoted fields, `""` escapes, embedded
newlines and a UTF-8 BOM are handled. Up to 200,000 rows in total per call.
- Column names are matched case-insensitively. Defaults try `user_id`/`client_id`/`anonymous_id`/...,
`timestamp`/`date`/`created_at`/..., `event`/`event_name`, `utm_source`/`source`,
`utm_medium`/`medium`, `utm_campaign`/`campaign`, `session_id`. Override with `columns`.
- A file without an event column needs `default_event` (for example a signups export).
- Timestamps: ISO 8601 with `Z`/offset, `YYYY-MM-DD[ HH:MM[:SS]]` (read as UTC, with a warning), or
epoch seconds/milliseconds. Ambiguous formats such as `11/05/2026` are rejected per row, not guessed.
- UTM values are trimmed and lowercased before grouping unless `case_sensitive_utm` is true.
### Aggregated spend exports (`channel_performance`)
- Columns are found by common names (`date`/`day`/`week`, `channel`/`source`/`platform`,
`campaign`/`campaign_name`, `spend`/`cost`/`amount_spent`, `impressions`/`impr`,
`clicks`/`link_clicks`, `conversions`/`results`/`purchases`, `revenue`/`conversion_value`), ignoring case,
punctuation and a currency in parentheses such as `Amount spent (USD)`. Override with `columns`.
A file without a channel column is labelled with its file name (one export per platform).
- Money cells may carry `$`, `€`, `£`, `¥`, `₹`, `US$`, `CA$`, `A$` or a three-letter code; thousands
separators and decimal commas are handled. The format (`1,234.56` or `1.234,56`) is inferred per file
or set with `number_format`; a file that mixes both styles is refused. **Mixed currencies are refused**
rather than added together; `currency` labels the result and is checked against the data.
- Platform `Total` / `Grand total` rows are skipped (not double counted); fully empty rows are skipped;
rows with unreadable numbers or negative spend/counts are skipped and counted. Empty or `--` metric
cells count as 0 and are reported per column (`blank_numbers: "skip_row"` drops those rows instead).
- Zero recorded spend gives `null` (n/a) for CPC, CPM, CPA and ROAS, so unpaid channels are never
ranked as the cheapest. Channel and campaign labels are grouped case-insensitively by default.
- Revenue is used exactly as exported (usually platform-attributed); ad platforms can claim the same sale.
## Usage (Node CLI)
```sh
node bin/cli.js --help
node bin/cli.js build_report --input report-input.json
```
On Windows PowerShell, prefer `--input file.json` (or `--input -` with piped JSON).
## Use as an MCP server
```sh
claude mcp add marketing-analytics -- node /absolute/path/to/marketing-analytics/bin/mcp.js
```
`claude-code/SKILL.md` is a Claude Code skill that drives the CLI.
## Testing status
Tested with Node.js (Vitest, `tests/marketing-analytics.test.ts` and `tests/channel-performance.test.ts`,
synthetic fixture CSVs; CLI and MCP stdio runs on synthetic exports). It has
**not yet been verified inside Claude Code** or any other MCP client by AgentRove.
## Limitations
- Analyses only what is in your exports: no GA4, ad-platform or CRM connection, no identity stitching
across devices (one `user_id` column per call). Cost and revenue metrics come only from aggregated
exports passed to `channel_performance`; event-level tools do not join them to users.
- No currency conversion, no tax/fee adjustment, no de-duplication of conversions claimed by several
platforms.
- First/last-touch only; no linear, time-decay or data-driven models.
- Statistics are simple: Wilson intervals and a two-proportion z-test. They do not correct for multiple
comparisons, seasonality or users counted in several campaigns.
- Weeks are UTC; timestamps without a zone are treated as UTC.
- The whole CSV text must fit in the tool input (10 MB per file).