Campaign analytics

Analyzes campaign performance with multi-touch attribution, funnel conversion analysis, and ROI calculation for marketing optimization.

How to use it

Claude Code
  1. Run the line below. It pulls the whole folder into ~/.claude/skills/campaign-analytics, including the files SKILL.md points to.
  2. Describe your job in plain words. Claude Code follows the skill from there.
Claude Code — installs the whole folder, not just SKILL.md
npx degit alirezarezvani/claude-skills/marketing-skill/skills/campaign-analytics#main ~/.claude/skills/campaign-analytics

For 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)
  1. On this page open ⋯ → Download .md.
  2. Save it as SKILL.md in a folder, zip the folder, then Customize → Skills → + → Create skill → Upload a skill.
  3. Pick the file and Save. Claude shows the name and description and runs a security scan.
  4. Check the skill is switched on.
  5. Start a new chat and describe your job in plain words. The AI follows the skill from there.
ChatGPT or another app
  1. ChatGPT: make a Project and paste it into Instructions.
  2. 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.
Step-by-step guide with screenshots · Ask in the forum

Paste into Claude, ChatGPT or Cursor.

Source of Campaign analytics

Show the full text229 lines
namedescriptionlicensemetadata
campaign-analyticsAnalyzes 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 descriptive KeyError
  • Mismatched array lengths in funnel data (stages and counts must be the same length) → raises ValueError
  • 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

  1. Use multiple attribution models -- Compare at least 3 models to triangulate channel value; no single model tells the full story.
  2. Set appropriate lookback windows -- Match your time-decay half-life to your average sales cycle length.
  3. Segment your funnels -- Compare segments (channel, cohort, geography) to identify performance drivers.
  4. Benchmark against your own history first -- Industry benchmarks provide context, but historical data is the most relevant comparison.
  5. Run ROI analysis at regular intervals -- Weekly for active campaigns, monthly for strategic review.
  6. Include all costs -- Factor in creative, tooling, and labor costs alongside media spend for accurate ROI.
  7. 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.
  • 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---
2name: "campaign-analytics"
3description: 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.
4license: MIT
5metadata:
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 
17Production-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 
23All scripts accept a JSON file as positional input argument. See `assets/sample_campaign_data.json` for complete examples.
24 
25### Attribution Analyzer
26 
27```json
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```json
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```json
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 
76Before 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 
82Use `python -m json.tool your_file.json` to validate JSON syntax before passing it to any script.
83 
84---
85 
86## Output Formats
87 
88All 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 
97For a complete campaign review, run the three scripts in sequence:
98 
99```bash
100# Step 1 — Attribution: understand which channels drive conversions
101python 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
104python scripts/funnel_analyzer.py funnel_data.json
105 
106# Step 3 — ROI: calculate profitability and benchmark against industry standards
107python scripts/campaign_roi_calculator.py campaign_data.json
108```
109 
110Use 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```bash
119# Run all 5 attribution models
120python scripts/attribution_analyzer.py campaign_data.json
121 
122# Run a specific model
123python scripts/attribution_analyzer.py campaign_data.json --model time-decay
124 
125# JSON output for pipeline integration
126python scripts/attribution_analyzer.py campaign_data.json --format json
127 
128# Custom time-decay half-life (default: 7 days)
129python scripts/attribution_analyzer.py campaign_data.json --model time-decay --half-life 14
130```
131 
132### Funnel Analysis
133 
134```bash
135# Basic funnel analysis
136python scripts/funnel_analyzer.py funnel_data.json
137 
138# JSON output
139python scripts/funnel_analyzer.py funnel_data.json --format json
140```
141 
142### Campaign ROI Calculation
143 
144```bash
145# Calculate ROI metrics for all campaigns
146python scripts/campaign_roi_calculator.py campaign_data.json
147 
148# JSON output
149python scripts/campaign_roi_calculator.py campaign_data.json --format json
150```
151 
152---
153 
154## Scripts
155 
156### 1. attribution_analyzer.py
157 
158Implements 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 
170Analyzes 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 
179Calculates 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 
2041. **Use multiple attribution models** -- Compare at least 3 models to triangulate channel value; no single model tells the full story.
2052. **Set appropriate lookback windows** -- Match your time-decay half-life to your average sales cycle length.
2063. **Segment your funnels** -- Compare segments (channel, cohort, geography) to identify performance drivers.
2074. **Benchmark against your own history first** -- Industry benchmarks provide context, but historical data is the most relevant comparison.
2085. **Run ROI analysis at regular intervals** -- Weekly for active campaigns, monthly for strategic review.
2096. **Include all costs** -- Factor in creative, tooling, and labor costs alongside media spend for accurate ROI.
2107. **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

Alternatives

Also in AttributionSee all 364 in Marketing →
Attribution AuditPaste the sales and spend numbers each ad platform claims, and get back a plain explanation of why they disagree and which figure to trust.Data & AI · MITPaid Media Tracking & Measurement Specialist AgentExpert in conversion tracking architecture, tag management, and attribution modeling across Google Tag Manager, GA4, Google Ads, Meta CAPI, LinkedIn Insight Tag, and server-side implementations. Ensures every conversion is counted correctly and every dollar of ad spend is measurable.Business & ops · MITAnalytics TrackingWhen the user wants to set up, improve, or audit analytics tracking and measurement. Also use when the user mentions "set up tracking," "GA4," "Google Analytics," "conversion tracking," "event tracking," "UTM parameters," "tag manager," "GTM," "analytics implementation," "tracking plan," "how do I measure this," "track conversions," "Mixpanel," "Segment," "are my events firing," or "analytics isn't working." Use this whenever someone asks how to know if something is working or wants to measure marketing results. For choosing attribution models, comparing multi-touch/MMM/incrementality, or reconciling conflicting numbers across tools, see attribution. For A/B test measurement, see ab-testing.Marketing · MITFind Out Which Marketing Actually Made The SalePaste the conflicting numbers from your ad accounts, website stats and sales records; get back one honest read on which channels really drove sales and where to put your budget.Data & AI · MIT