Skip to content
Back to skills

Campaign Analytics

ASecurity

Attribution, funnel and ROI analysis from your own campaign data. Use when you need to split conversion credit across channels, find the funnel step that loses the most users, or check whether campaigns beat break-even and your own CPA/ROAS targets. Every finding quotes your input and gives a fix.

  • 1,271 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added May 30, 2026
ai-agentspythongobashtestingperformance

Works with

  • cli

Security analysis

A100/100

Pro scans all 12 files and shows the line behind each finding

Scanned December 4, 2026

npx -y skills add borghei/Claude-Skills --skill campaign-analytics --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Campaign Analytics?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Campaign Analytics
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/borghei-campaign-analytics/badge)](https://www.skillsdirectory.com/skills/borghei-campaign-analytics)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: campaign-analytics
description: >
  Attribution, funnel and ROI analysis from your own campaign data. Use when
  you need to split conversion credit across channels, find the funnel step
  that loses the most users, or check whether campaigns beat break-even and
  your own CPA/ROAS targets. Every finding quotes your input and gives a fix.
license: MIT + Commons Clause
metadata:
  version: 1.0.0
  author: borghei
  category: marketing
  domain: campaign-analytics
  updated: 2026-09-21
  python-tools: attribution_analyzer.py, funnel_analyzer.py, campaign_roi_calculator.py
  tech-stack: marketing-analytics, attribution-modeling
  tags:
    - campaign-analytics
    - attribution
    - funnel
    - roi
    - marketing-performance
---

# Campaign Analytics

Three stdlib-only Python tools that read your JSON export and return findings with fixes. No network, no built-in industry benchmarks: campaigns are judged against break-even maths and targets you supply.

## When to use

- Which channels deserve credit for revenue: `attribution_analyzer.py`
- Where prospects drop off, per segment: `funnel_analyzer.py`
- Is a campaign profitable, and does it meet your ROAS/CPA/CPL targets: `campaign_roi_calculator.py`

## Quick start (real output)

```bash
python3 scripts/funnel_analyzer.py assets/flawed_funnel.json
```

```
FINDINGS
  1. Signup -> Activation: Activation = 5,600 is larger than Signup = 5,000
     rule: a funnel stage cannot exceed the stage before it (unique users)
     fix:  recount Activation as unique users who also reached Signup, or reorder the stages
  2. Trial -> Paid: drop-off 92.5% vs median step 39.3% (300 of 4,000 continue)
     rule: step drop-off >= 1.5x the median step and >= 10 points above it (internal heuristic)
     fix:  bring this step to the median (39.3% drop): 2,429 would continue, +2,129 users at 'Paid' ...

FIX 2 issues
```

## Exit codes (all three tools)

| Code | Meaning |
|------|---------|
| 0 | Clean: `PASS` |
| 1 | Findings: `FIX n issues`, each with the quoted value, rule and fix |
| 2 | Unusable input: unreadable file, invalid JSON, wrong shape, mismatched lengths, negative or non-numeric counts. One-line message on stderr, no traceback |

`--format text|json` on every tool (`--json` is an alias). Text output ends with the verdict line; JSON carries `verdict`, `findings` and what was read.

## Commands

### Attribution

```bash
python3 scripts/attribution_analyzer.py assets/sample_journeys.json
python3 scripts/attribution_analyzer.py assets/sample_journeys.json --model time-decay --half-life 14
python3 scripts/attribution_analyzer.py assets/flawed_journeys.json --format json
```

Input: `{"journeys": [{"journey_id": "j1", "touchpoints": [{"channel": "email", "timestamp": "2025-10-05T14:30:00"}], "converted": true, "revenue": 500}]}`

- Models: first-touch, last-touch, linear, time-decay (`--half-life` days, must be > 0), position-based (40/20/40; 50/50 with two touchpoints).
- Findings (exit 1): journeys that cannot be used, namely bad or missing timestamp, empty touchpoints, non-boolean `converted`, converted without numeric `revenue`. They are skipped and listed; revenue is never defaulted. Exit 2 if no usable converted journey remains.
- Observations (do not change the exit code): channels whose share moves 20+ points between first and last touch, and `direct` holding 50%+ of last-touch revenue (both internal heuristics).
- AI assistants: touchpoints whose channel, `referrer`, `source` or `utm_source` match chatgpt.com, perplexity.ai, claude.ai, gemini.google.com and similar (list as of September 2026) become `ai_assistant`. Google AI Overviews clicks arrive from google.com and are not reclassified. Disable with `--no-ai-reclassify`.

### Funnel

```bash
python3 scripts/funnel_analyzer.py assets/sample_funnel.json
python3 scripts/funnel_analyzer.py assets/sample_segments.json --format json
```

Input: `{"funnel": {"stages": [...], "counts": [...]}}` or `{"stages": [...], "segments": {"organic": {"counts": [...]}}}`

- Findings: a stage larger than the one before it; a step whose drop-off is at least 1.5x the median step and 10+ points above it (needs 3+ steps; heuristic), with the users recovered if it matched the median; a segment converting under half the best segment.
- Exit 2: stages/counts length mismatch, negative or non-numeric count, zero entries at the first stage.

### ROI

```bash
python3 scripts/campaign_roi_calculator.py assets/sample_campaigns.json
python3 scripts/campaign_roi_calculator.py assets/flawed_campaigns.json --format json
```

Input: `{"targets": {"min_roas": 2, "max_cpa": 150, "max_cpl": 25, "gross_margin_pct": 40}, "campaigns": [{"name": "...", "channel": "email", "spend": 5000, "revenue": 25000, "impressions": 50000, "clicks": 2500, "leads": 300, "customers": 45}]}`

- Only `spend` is required. Other fields left out are listed under `not_provided` and are never scored as zero. A campaign may carry its own `targets`.
- Findings: revenue missing; clicks > impressions, leads > clicks, customers > leads; revenue below spend (or below spend after `gross_margin_pct`, with break-even ROAS = 100 / margin); ROAS, CPA or CPL worse than your target. Each fix states the revenue, spend or customer count that closes the gap.
- Metrics: ROI, ROAS, CPA (= CAC), CPL, CTR, lead-to-customer CVR, CPC, CPM, click-to-lead rate.

## Samples

`assets/sample_*.json` (exit 0), `flawed_*.json` (exit 1), `malformed_*.json` (exit 2) for each tool, plus `assets/contract.json`. Check with `python3 scripts/skill_contract_check.py --skill marketing/campaign-analytics` from the repo root. `assets/sample_campaign_data.json` is a combined example of all three input shapes. Templates: `ab_test_template.md`, `campaign_report_template.md`, `channel_comparison_template.md`.

## References

| Guide | Purpose |
|-------|---------|
| `references/attribution-models-guide.md` | Formulas, pros/cons, model selection |
| `references/campaign-metrics-benchmarks.md` | Rule-of-thumb ranges by channel. Unsourced heuristics: context only, the tools do not apply them |
| `references/funnel-optimization-framework.md` | Stage-by-stage optimization strategies |

## Practice notes

1. Compare at least 3 attribution models before moving budget; set `--half-life` near half your sales cycle (e.g. 30 for 60-day cycles, 3 for e-commerce).
2. Use your own history for targets; put them in `targets`.
3. Include creative, tooling and labour in `spend` for true ROI; use `gross_margin_pct` so loss is judged on margin.
4. Keep UTM values lowercase and consistent (GA4 treats `Email` and `email` as different).
5. Funnel counts should be unique users per stage, top to bottom.

## Limitations

- No significance testing for A/B tests (descriptive metrics only; templates provided).
- Single currency, no cross-device identity resolution, static JSON snapshots, not tuned beyond ~100K journeys.
- Time-decay ignores weekday and seasonal effects.
- Direct visits with no referrer (app handoffs, copy-paste) cannot be recovered and are under-counted.

## Related skills

marketing-demand-acquisition, social-media-analyzer, marketing-strategy-pmm, content-creator.

Files in this skill

  • SKILL.md18.8 KB
  • assets/ab_test_template.md3.4 KB
  • assets/campaign_report_template.md3.9 KB
  • assets/channel_comparison_template.md4.9 KB
  • assets/expected_output.json3.8 KB
  • assets/sample_campaign_data.json4.6 KB
  • references/attribution-models-guide.md9.4 KB
  • references/campaign-metrics-benchmarks.md8.8 KB
  • references/funnel-optimization-framework.md10.7 KB
  • scripts/attribution_analyzer.py12.2 KB
  • scripts/campaign_roi_calculator.py17.7 KB
  • scripts/funnel_analyzer.py10.6 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.