Campaign analytics
Analyzes campaign performance with multi-touch attribution, funnel conversion analysis, and ROI calculation for marketing optimization.
How to use it
Claude Code
- Run the line below. It pulls the whole folder into
~/.claude/skills/campaign-analytics, including the files SKILL.md points to. - Describe your job in plain words. Claude Code follows the skill from there.
npx degit alirezarezvani/claude-skills/marketing-skill/skills/campaign-analytics#main ~/.claude/skills/campaign-analyticsFor one project only, change the path to .claude/skills/campaign-analytics. This skill also uses attribution_analyzer.py, funnel_analyzer.py, campaign_roi_calculator.py, your_file.json, campaign_data.json, funnel_data.json — copying SKILL.md alone won't be enough. See the folder on GitHub.
Claude (web or desktop app)
- On this page open ⋯ → Download .md.
- Save it as SKILL.md in a folder, zip the folder, then Customize → Skills → + → Create skill → Upload a skill.
- Pick the file and Save. Claude shows the name and description and runs a security scan.
- Check the skill is switched on.
- Start a new chat and describe your job in plain words. The AI follows the skill from there.
ChatGPT or another app
- ChatGPT: make a Project and paste it into Instructions.
- Neither? Paste it at the top of a new chat — it works for that chat.
Not working?
- Check which app you pasted it into — the steps above name the right one.
- Some skills need the paid tier of Claude or ChatGPT.
Paste into Claude, ChatGPT or Cursor.
Source of Campaign analytics
Show the full text229 lines
| name | description | license | metadata |
|---|---|---|---|
| campaign-analytics | Analyzes campaign performance with multi-touch attribution, funnel conversion analysis, and ROI calculation for marketing optimization. Use when analyzing marketing campaigns, ad performance, attribution models, conversion rates, or calculating marketing ROI, ROAS, CPA, and campaign metrics across channels. | MIT | version: 1.0.0 author: Alireza Rezvani category: marketing domain: campaign-analytics updated: 2026-02-06 python-tools: attribution_analyzer.py, funnel_analyzer.py, campaign_roi_calculator.py tech-stack: marketing-analytics, attribution-modeling |
Campaign Analytics
Production-grade campaign performance analysis with multi-touch attribution modeling, funnel conversion analysis, and ROI calculation. Three Python CLI tools provide deterministic, repeatable analytics using standard library only -- no external dependencies, no API calls, no ML models.
Input Requirements
All scripts accept a JSON file as positional input argument. See assets/sample_campaign_data.json for complete examples.
Attribution Analyzer
{
"journeys": [
{
"journey_id": "j1",
"touchpoints": [
{"channel": "organic_search", "timestamp": "2025-10-01T10:00:00", "interaction": "click"},
{"channel": "email", "timestamp": "2025-10-05T14:30:00", "interaction": "open"},
{"channel": "paid_search", "timestamp": "2025-10-08T09:15:00", "interaction": "click"}
],
"converted": true,
"revenue": 500.00
}
]
}
Funnel Analyzer
{
"funnel": {
"stages": ["Awareness", "Interest", "Consideration", "Intent", "Purchase"],
"counts": [10000, 5200, 2800, 1400, 420]
}
}
Campaign ROI Calculator
{
"campaigns": [
{
"name": "Spring Email Campaign",
"channel": "email",
"spend": 5000.00,
"revenue": 25000.00,
"impressions": 50000,
"clicks": 2500,
"leads": 300,
"customers": 45
}
]
}
Input Validation
Before running scripts, verify your JSON is valid and matches the expected schema. Common errors:
- Missing required keys (e.g.,
journeys,funnel.stages,campaigns) → script exits with a descriptiveKeyError - Mismatched array lengths in funnel data (
stagesandcountsmust be the same length) → raisesValueError - Non-numeric monetary values in ROI data → raises
TypeError
Use python -m json.tool your_file.json to validate JSON syntax before passing it to any script.
Output Formats
All scripts support two output formats via the --format flag:
--format text(default): Human-readable tables and summaries for review--format json: Machine-readable JSON for integrations and pipelines
Typical Analysis Workflow
For a complete campaign review, run the three scripts in sequence:
# Step 1 — Attribution: understand which channels drive conversions
python scripts/attribution_analyzer.py campaign_data.json --model time-decay
# Step 2 — Funnel: identify where prospects drop off on the path to conversion
python scripts/funnel_analyzer.py funnel_data.json
# Step 3 — ROI: calculate profitability and benchmark against industry standards
python scripts/campaign_roi_calculator.py campaign_data.json
Use attribution results to identify top-performing channels, then focus funnel analysis on those channels' segments, and finally validate ROI metrics to prioritize budget reallocation.
How to Use
Attribution Analysis
# Run all 5 attribution models
python scripts/attribution_analyzer.py campaign_data.json
# Run a specific model
python scripts/attribution_analyzer.py campaign_data.json --model time-decay
# JSON output for pipeline integration
python scripts/attribution_analyzer.py campaign_data.json --format json
# Custom time-decay half-life (default: 7 days)
python scripts/attribution_analyzer.py campaign_data.json --model time-decay --half-life 14
Funnel Analysis
# Basic funnel analysis
python scripts/funnel_analyzer.py funnel_data.json
# JSON output
python scripts/funnel_analyzer.py funnel_data.json --format json
Campaign ROI Calculation
# Calculate ROI metrics for all campaigns
python scripts/campaign_roi_calculator.py campaign_data.json
# JSON output
python scripts/campaign_roi_calculator.py campaign_data.json --format json
Scripts
1. attribution_analyzer.py
Implements five industry-standard attribution models to allocate conversion credit across marketing channels:
| Model | Description | Best For |
|---|---|---|
| First-Touch | 100% credit to first interaction | Brand awareness campaigns |
| Last-Touch | 100% credit to last interaction | Direct response campaigns |
| Linear | Equal credit to all touchpoints | Balanced multi-channel evaluation |
| Time-Decay | More credit to recent touchpoints | Short sales cycles |
| Position-Based | 40/20/40 split (first/middle/last) | Full-funnel marketing |
2. funnel_analyzer.py
Analyzes conversion funnels to identify bottlenecks and optimization opportunities:
- Stage-to-stage conversion rates and drop-off percentages
- Automatic bottleneck identification (largest absolute and relative drops)
- Overall funnel conversion rate
- Segment comparison when multiple segments are provided
3. campaign_roi_calculator.py
Calculates comprehensive ROI metrics with industry benchmarking:
- ROI: Return on investment percentage
- ROAS: Return on ad spend ratio
- CPA: Cost per acquisition
- CPL: Cost per lead
- CAC: Customer acquisition cost
- CTR: Click-through rate
- CVR: Conversion rate (leads to customers)
- Flags underperforming campaigns against industry benchmarks
Reference Guides
| Guide | Location | Purpose |
|---|---|---|
| Attribution Models Guide | references/attribution-models-guide.md |
Deep dive into 5 models with formulas, pros/cons, selection criteria |
| Campaign Metrics Benchmarks | references/campaign-metrics-benchmarks.md |
Industry benchmarks by channel and vertical for CTR, CPC, CPM, CPA, ROAS |
| Funnel Optimization Framework | references/funnel-optimization-framework.md |
Stage-by-stage optimization strategies, common bottlenecks, best practices |
Best Practices
- Use multiple attribution models -- Compare at least 3 models to triangulate channel value; no single model tells the full story.
- Set appropriate lookback windows -- Match your time-decay half-life to your average sales cycle length.
- Segment your funnels -- Compare segments (channel, cohort, geography) to identify performance drivers.
- Benchmark against your own history first -- Industry benchmarks provide context, but historical data is the most relevant comparison.
- Run ROI analysis at regular intervals -- Weekly for active campaigns, monthly for strategic review.
- Include all costs -- Factor in creative, tooling, and labor costs alongside media spend for accurate ROI.
- Document A/B tests rigorously -- Use the provided template to ensure statistical validity and clear decision criteria.
Limitations
- No statistical significance testing -- Scripts provide descriptive metrics only; p-value calculations require external tools.
- Standard library only -- No advanced statistical libraries. Suitable for most campaign sizes but not optimized for datasets exceeding 100K journeys.
- Offline analysis -- Scripts analyze static JSON snapshots; no real-time data connections or API integrations.
- Single-currency -- All monetary values assumed to be in the same currency; no currency conversion support.
- Simplified time-decay -- Exponential decay based on configurable half-life; does not account for weekday/weekend or seasonal patterns.
- No cross-device tracking -- Attribution operates on provided journey data as-is; cross-device identity resolution must be handled upstream.
Related Skills
- analytics-tracking: For setting up tracking. NOT for analyzing data (that's this skill).
- ab-test-setup: For designing experiments to test what analytics reveals.
- marketing-ops: For routing insights to the right execution skill.
- paid-ads: For optimizing ad spend based on analytics findings.
| 1 | |
| 2 | name "campaign-analytics" |
| 3 | description Analyzes campaign performance with multi-touch attribution, funnel conversion analysis, and ROI calculation for marketing optimization. Use when analyzing marketing campaigns, ad performance, attribution models, conversion rates, or calculating marketing ROI, ROAS, CPA, and campaign metrics across channels. |
| 4 | license MIT |
| 5 | metadata |
| 6 | version 1.0.0 |
| 7 | author Alireza Rezvani |
| 8 | category marketing |
| 9 | domain campaign-analytics |
| 10 | updated 2026-02-06 |
| 11 | python-tools attribution_analyzer.py, funnel_analyzer.py, campaign_roi_calculator.py |
| 12 | tech-stack marketing-analytics, attribution-modeling |
| 13 | |
| 14 | |
| 15 | # Campaign Analytics |
| 16 | |
| 17 | Production-grade campaign performance analysis with multi-touch attribution modeling, funnel conversion analysis, and ROI calculation. Three Python CLI tools provide deterministic, repeatable analytics using standard library only -- no external dependencies, no API calls, no ML models. |
| 18 | |
| 19 | |
| 20 | |
| 21 | ## Input Requirements |
| 22 | |
| 23 | All scripts accept a JSON file as positional input argument. See `assets/sample_campaign_data.json` for complete examples. |
| 24 | |
| 25 | ### Attribution Analyzer |
| 26 | |
| 27 | |
| 28 | { |
| 29 | "journeys": [ |
| 30 | { |
| 31 | "journey_id": "j1", |
| 32 | "touchpoints": [ |
| 33 | {"channel": "organic_search", "timestamp": "2025-10-01T10:00:00", "interaction": "click"}, |
| 34 | {"channel": "email", "timestamp": "2025-10-05T14:30:00", "interaction": "open"}, |
| 35 | {"channel": "paid_search", "timestamp": "2025-10-08T09:15:00", "interaction": "click"} |
| 36 | ], |
| 37 | "converted": true, |
| 38 | "revenue": 500.00 |
| 39 | } |
| 40 | ] |
| 41 | } |
| 42 | |
| 43 | |
| 44 | ### Funnel Analyzer |
| 45 | |
| 46 | |
| 47 | { |
| 48 | "funnel": { |
| 49 | "stages": ["Awareness", "Interest", "Consideration", "Intent", "Purchase"], |
| 50 | "counts": [10000, 5200, 2800, 1400, 420] |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | |
| 55 | ### Campaign ROI Calculator |
| 56 | |
| 57 | |
| 58 | { |
| 59 | "campaigns": [ |
| 60 | { |
| 61 | "name": "Spring Email Campaign", |
| 62 | "channel": "email", |
| 63 | "spend": 5000.00, |
| 64 | "revenue": 25000.00, |
| 65 | "impressions": 50000, |
| 66 | "clicks": 2500, |
| 67 | "leads": 300, |
| 68 | "customers": 45 |
| 69 | } |
| 70 | ] |
| 71 | } |
| 72 | |
| 73 | |
| 74 | ### Input Validation |
| 75 | |
| 76 | Before running scripts, verify your JSON is valid and matches the expected schema. Common errors: |
| 77 | |
| 78 | **Missing required keys** (e.g., `journeys`, `funnel.stages`, `campaigns`) → script exits with a descriptive `KeyError` |
| 79 | **Mismatched array lengths** in funnel data (`stages` and `counts` must be the same length) → raises `ValueError` |
| 80 | **Non-numeric monetary values** in ROI data → raises `TypeError` |
| 81 | |
| 82 | Use `python -m json.tool your_file.json` to validate JSON syntax before passing it to any script. |
| 83 | |
| 84 | |
| 85 | |
| 86 | ## Output Formats |
| 87 | |
| 88 | All scripts support two output formats via the `--format` flag: |
| 89 | |
| 90 | `--format text` (default): Human-readable tables and summaries for review |
| 91 | `--format json`: Machine-readable JSON for integrations and pipelines |
| 92 | |
| 93 | |
| 94 | |
| 95 | ## Typical Analysis Workflow |
| 96 | |
| 97 | For a complete campaign review, run the three scripts in sequence: |
| 98 | |
| 99 | |
| 100 | # Step 1 — Attribution: understand which channels drive conversions |
| 101 | python scripts/attribution_analyzer.py campaign_data.json --model time-decay |
| 102 | |
| 103 | # Step 2 — Funnel: identify where prospects drop off on the path to conversion |
| 104 | python scripts/funnel_analyzer.py funnel_data.json |
| 105 | |
| 106 | # Step 3 — ROI: calculate profitability and benchmark against industry standards |
| 107 | python scripts/campaign_roi_calculator.py campaign_data.json |
| 108 | |
| 109 | |
| 110 | Use attribution results to identify top-performing channels, then focus funnel analysis on those channels' segments, and finally validate ROI metrics to prioritize budget reallocation. |
| 111 | |
| 112 | |
| 113 | |
| 114 | ## How to Use |
| 115 | |
| 116 | ### Attribution Analysis |
| 117 | |
| 118 | |
| 119 | # Run all 5 attribution models |
| 120 | python scripts/attribution_analyzer.py campaign_data.json |
| 121 | |
| 122 | # Run a specific model |
| 123 | python scripts/attribution_analyzer.py campaign_data.json --model time-decay |
| 124 | |
| 125 | # JSON output for pipeline integration |
| 126 | python scripts/attribution_analyzer.py campaign_data.json --format json |
| 127 | |
| 128 | # Custom time-decay half-life (default: 7 days) |
| 129 | python scripts/attribution_analyzer.py campaign_data.json --model time-decay --half-life 14 |
| 130 | |
| 131 | |
| 132 | ### Funnel Analysis |
| 133 | |
| 134 | |
| 135 | # Basic funnel analysis |
| 136 | python scripts/funnel_analyzer.py funnel_data.json |
| 137 | |
| 138 | # JSON output |
| 139 | python scripts/funnel_analyzer.py funnel_data.json --format json |
| 140 | |
| 141 | |
| 142 | ### Campaign ROI Calculation |
| 143 | |
| 144 | |
| 145 | # Calculate ROI metrics for all campaigns |
| 146 | python scripts/campaign_roi_calculator.py campaign_data.json |
| 147 | |
| 148 | # JSON output |
| 149 | python scripts/campaign_roi_calculator.py campaign_data.json --format json |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | ## Scripts |
| 155 | |
| 156 | ### 1. attribution_analyzer.py |
| 157 | |
| 158 | Implements five industry-standard attribution models to allocate conversion credit across marketing channels: |
| 159 | |
| 160 | | Model | Description | Best For | |
| 161 | |-------|-------------|----------| |
| 162 | | First-Touch | 100% credit to first interaction | Brand awareness campaigns | |
| 163 | | Last-Touch | 100% credit to last interaction | Direct response campaigns | |
| 164 | | Linear | Equal credit to all touchpoints | Balanced multi-channel evaluation | |
| 165 | | Time-Decay | More credit to recent touchpoints | Short sales cycles | |
| 166 | | Position-Based | 40/20/40 split (first/middle/last) | Full-funnel marketing | |
| 167 | |
| 168 | ### 2. funnel_analyzer.py |
| 169 | |
| 170 | Analyzes conversion funnels to identify bottlenecks and optimization opportunities: |
| 171 | |
| 172 | Stage-to-stage conversion rates and drop-off percentages |
| 173 | Automatic bottleneck identification (largest absolute and relative drops) |
| 174 | Overall funnel conversion rate |
| 175 | Segment comparison when multiple segments are provided |
| 176 | |
| 177 | ### 3. campaign_roi_calculator.py |
| 178 | |
| 179 | Calculates comprehensive ROI metrics with industry benchmarking: |
| 180 | |
| 181 | **ROI**: Return on investment percentage |
| 182 | **ROAS**: Return on ad spend ratio |
| 183 | **CPA**: Cost per acquisition |
| 184 | **CPL**: Cost per lead |
| 185 | **CAC**: Customer acquisition cost |
| 186 | **CTR**: Click-through rate |
| 187 | **CVR**: Conversion rate (leads to customers) |
| 188 | Flags underperforming campaigns against industry benchmarks |
| 189 | |
| 190 | |
| 191 | |
| 192 | ## Reference Guides |
| 193 | |
| 194 | | Guide | Location | Purpose | |
| 195 | |-------|----------|---------| |
| 196 | | Attribution Models Guide | `references/attribution-models-guide.md` | Deep dive into 5 models with formulas, pros/cons, selection criteria | |
| 197 | | Campaign Metrics Benchmarks | `references/campaign-metrics-benchmarks.md` | Industry benchmarks by channel and vertical for CTR, CPC, CPM, CPA, ROAS | |
| 198 | | Funnel Optimization Framework | `references/funnel-optimization-framework.md` | Stage-by-stage optimization strategies, common bottlenecks, best practices | |
| 199 | |
| 200 | |
| 201 | |
| 202 | ## Best Practices |
| 203 | |
| 204 | **Use multiple attribution models** -- Compare at least 3 models to triangulate channel value; no single model tells the full story. |
| 205 | **Set appropriate lookback windows** -- Match your time-decay half-life to your average sales cycle length. |
| 206 | **Segment your funnels** -- Compare segments (channel, cohort, geography) to identify performance drivers. |
| 207 | **Benchmark against your own history first** -- Industry benchmarks provide context, but historical data is the most relevant comparison. |
| 208 | **Run ROI analysis at regular intervals** -- Weekly for active campaigns, monthly for strategic review. |
| 209 | **Include all costs** -- Factor in creative, tooling, and labor costs alongside media spend for accurate ROI. |
| 210 | **Document A/B tests rigorously** -- Use the provided template to ensure statistical validity and clear decision criteria. |
| 211 | |
| 212 | |
| 213 | |
| 214 | ## Limitations |
| 215 | |
| 216 | **No statistical significance testing** -- Scripts provide descriptive metrics only; p-value calculations require external tools. |
| 217 | **Standard library only** -- No advanced statistical libraries. Suitable for most campaign sizes but not optimized for datasets exceeding 100K journeys. |
| 218 | **Offline analysis** -- Scripts analyze static JSON snapshots; no real-time data connections or API integrations. |
| 219 | **Single-currency** -- All monetary values assumed to be in the same currency; no currency conversion support. |
| 220 | **Simplified time-decay** -- Exponential decay based on configurable half-life; does not account for weekday/weekend or seasonal patterns. |
| 221 | **No cross-device tracking** -- Attribution operates on provided journey data as-is; cross-device identity resolution must be handled upstream. |
| 222 | |
| 223 | ## Related Skills |
| 224 | |
| 225 | **analytics-tracking**: For setting up tracking. NOT for analyzing data (that's this skill). |
| 226 | **ab-test-setup**: For designing experiments to test what analytics reveals. |
| 227 | **marketing-ops**: For routing insights to the right execution skill. |
| 228 | **paid-ads**: For optimizing ad spend based on analytics findings. |
| 229 |
Discussion
Browse more free Claude skills or everything in Marketing.