Audience Overlap & Wasted Ad Spend | GoMarble
What it does?
A Python script scores audience overlap between your Meta ad sets via histogram intersection, flags cannibalization, and estimates the wasted spend whenever overlap crosses a 0.6 threshold.
What you need
- Meta ad account ID (act_...)
- GoMarble API key
- Anthropic API key
First, connect Claude Code to your ad accounts
Set up GoMarble MCP once, then paste the build prompt below into Claude Code.
1. Install Claude Code and Python
Download Claude Code and Python if you don't already have them installed.
2. Connect your Meta Ads account on GoMarble
Go to apps.gomarble.ai, sign up, and connect your Meta Ads account in the Integrations page.
3. Get your GoMarble API key
In GoMarble, go to Settings → API Key, copy it, and save it somewhere safe.
4. Add GoMarble MCP to Claude Code
Run the command below in your terminal to connect Claude Code to your GoMarble MCP server.
claude mcp add --transport http gomarble https://apps.gomarble.ai/mcp-api/mcp --header "Authorization: Bearer <paste your API key>"
The script
Paste this into Claude Code — it will write the Python CLI script for you, based on this spec.
Build a Python CLI script called audience_overlap.py that detects audience overlap between Meta Ads campaigns using GoMarble MCP.
CLI args: --meta act_123456 (required, Meta only)
Use GoMarble MCP call pattern:
ANTHROPIC_API_KEY = ""
GOMARBLE_API_KEY = ""
POST https://api.anthropic.com/v1/messages, anthropic-version: "2023-06-01", anthropic-beta: "mcp-client-2025-04-04"
mcp_servers: [{type: "url", url: "https://apps.gomarble.ai/mcp-api/sse", name: "gomarble", authorization_token: GOMARBLE_API_KEY}]
6-step pipeline:
1. Account Structure + Targeting — facebook_get_details_of_ad_account, then facebook_get_adset_details for each adset (age, gender, geo, interests, custom audiences)
2. Demographic Breakdown — facebook_get_adaccount_insights with breakdowns: [age, gender], campaign level, last_30d
3. Audience Segments — separate call with breakdowns: [user_segment_key] for New/Engaged/Existing (CANNOT combine breakdowns in one call)
4. Compute Overlap — build spend % profile per age+gender bucket per campaign. Overlap score = sum of min(pctA, pctB) across all buckets (histogram intersection). Cannibalization = overlap > 0.6 + both spending + at least one poor ROAS. Waste = (overlap - 0.5) * min(spendA, spendB)
5. AI Analysis — consolidation recommendations
6. Output: overlap_matrix.csv, overlap_brief.txt
What you get back
Format: Running python audience_overlap.py --meta act_123456 writes two files:
- overlap_matrix.csv — spend-profile overlap data
- overlap_brief.txt — an AI-written consolidation brief listing overlapping ad sets, an overlap score per pair, and an estimated wasted-spend figure
FAQ
Does this also check Google Ads?
No — despite the broader 'audience overlap' framing on the page, this script is Meta-only. The CLI takes a single --meta account ID and only calls Meta/Facebook GoMarble MCP tools.
How is the overlap score calculated?
It builds a spend-percentage profile per age+gender bucket for each campaign, then sums the minimum of the two percentages across all buckets (a histogram intersection) to get an overlap score between 0 and 1.
What counts as cannibalization?
Overlap above 0.6 between two campaigns where both are actively spending and at least one has poor ROAS.
How is wasted spend estimated?
As (overlap score − 0.5) multiplied by the smaller of the two campaigns' spend, for any pair above the cannibalization threshold.