How to Build AI-Powered Audience Targeting Suggestions
Use AI to analyze your data and suggest new audience segments to test.
Jay Banlasan
The AI Systems Guy
AI audience targeting suggestions for Meta Ads take the manual research out of finding new segments. Instead of guessing which interests to test, you feed your performance data and customer profiles into Claude and get back specific, testable audience ideas ranked by potential.
I use this system whenever a client's current audiences start fatiguing. It consistently finds segments the team never considered.
What You Need Before Starting
- Historical ad performance data (at least 30 days)
- Customer profile data (demographics, interests, purchase behavior)
- Anthropic API key
- Python 3.8+ with
anthropicandsqlite3
Step 1: Gather Your Performance Data
import sqlite3
def get_audience_performance(db_path, days=30):
conn = sqlite3.connect(db_path)
rows = conn.execute("""
SELECT adset_name,
SUM(spend) as total_spend,
SUM(leads) as total_leads,
SUM(impressions) as total_impressions,
CASE WHEN SUM(leads) > 0 THEN SUM(spend)/SUM(leads) ELSE 0 END as cpa
FROM ad_daily
WHERE date >= DATE('now', ? || ' days')
GROUP BY adset_name
HAVING SUM(spend) > 10
ORDER BY cpa ASC
""", (f"-{days}",)).fetchall()
conn.close()
return [{"adset": r[0], "spend": r[1], "leads": r[2], "impressions": r[3], "cpa": r[4]} for r in rows]
Step 2: Build the Customer Profile Summary
def build_profile_summary(customer_data):
summary = {
"top_demographics": [],
"common_interests": [],
"purchase_patterns": [],
"geographic_clusters": [],
}
# Extract patterns from your CRM or customer list
for customer in customer_data:
summary["top_demographics"].append(f"{customer.get('age_range', 'unknown')}, {customer.get('gender', 'unknown')}")
if customer.get("interests"):
summary["common_interests"].extend(customer["interests"])
return summary
Step 3: Generate Targeting Suggestions with AI
import anthropic
import json
def suggest_audiences(performance_data, profile_summary, business_context):
client = anthropic.Anthropic()
perf_text = "\n".join([
f"- {a['adset']}: ${a['spend']:.0f} spent, {a['leads']} leads, ${a['cpa']:.2f} CPA"
for a in performance_data
])
prompt = f"""You are a Meta Ads audience strategist. Analyze this data and suggest 10 new audience segments to test.
BUSINESS CONTEXT:
{business_context}
CURRENT AUDIENCE PERFORMANCE (sorted by CPA, best first):
{perf_text}
CUSTOMER PROFILE:
Demographics: {profile_summary['top_demographics'][:10]}
Common interests: {list(set(profile_summary['common_interests']))[:15]}
For each suggestion, provide:
1. Audience name (how to name it in Ads Manager)
2. Targeting details (interests, behaviors, demographics)
3. Hypothesis (why this should work based on the data)
4. Estimated potential (high/medium/low based on current data patterns)
5. Suggested daily budget for testing
Focus on:
- Adjacent interests to your best performers
- Behavioral signals that match your customer profile
- Lookalike seed recommendations
- Untested demographic combinations
Return as JSON array."""
resp = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=2000,
messages=[{"role": "user", "content": prompt}]
)
return resp.content[0].text
Step 4: Score and Prioritize Suggestions
def prioritize_suggestions(suggestions_json):
suggestions = json.loads(suggestions_json)
priority_order = {"high": 1, "medium": 2, "low": 3}
sorted_suggestions = sorted(suggestions, key=lambda x: priority_order.get(x.get("estimated_potential", "low"), 3))
for i, s in enumerate(sorted_suggestions, 1):
print(f"\n#{i}: {s['audience_name']}")
print(f" Targeting: {s['targeting_details']}")
print(f" Hypothesis: {s['hypothesis']}")
print(f" Potential: {s['estimated_potential']}")
print(f" Test budget: {s['suggested_daily_budget']}")
return sorted_suggestions
Step 5: Create a Test Plan
Take the top 3-5 suggestions and build them as ad sets:
def create_test_plan(top_suggestions):
plan = {
"total_daily_budget": sum(float(s.get("suggested_daily_budget", "10").replace("$", "")) for s in top_suggestions),
"test_duration_days": 7,
"success_criteria": "CPA at or below current best performer",
"audiences": top_suggestions,
}
print(f"\nTest Plan: {len(top_suggestions)} new audiences")
print(f"Daily budget: ${plan['total_daily_budget']:.2f}")
print(f"7-day test cost: ${plan['total_daily_budget'] * 7:.2f}")
return plan
Run this monthly. Your best audiences today will fatigue. Having a pipeline of tested alternatives keeps performance steady.
What to Build Next
Connect the output directly to Meta's Marketing API to create the ad sets automatically. Then build a feedback loop that sends test results back to the AI so it learns which suggestion patterns actually convert.
Related Reading
- Audience Research with AI - the foundation of AI-powered audience research
- Lead Scoring with AI - scoring leads to find your best customer profile
- The Data Flywheel Explained - how data compounds into better targeting
Want this system built for your business?
Get a free assessment. We will map every system your business needs and show you the ROI.
Get Your Free Assessment