Skip to content

Business operating system for Claude Code — 57 skills, 21 agents, smart daemon. Unified inbox (WhatsApp/Email/Slack/Telegram), autonomous PR merge, full-AWS monitoring, revenue (Stripe+RevenueCat), e-commerce (Shopify), marketing (Klaviyo/Meta/GA4), voice (Bland/ElevenLabs), APM (Datadog/NewRelic/OTEL), YOLO mode.

feat(v1.5): phases 11-15 — Meta Ads management, Instagram, GA4 advanced, WhatsApp Business, cross-platform intelligence

auroracapital97cf63906ac7
diff --git a/claude-ops/agents/marketing-optimizer.md b/claude-ops/agents/marketing-optimizer.md
new file mode 100644
index 00000000..f56f3a38
--- /dev/null
+++ b/claude-ops/agents/marketing-optimizer.md
@@ -0,0 +1,116 @@
+# Marketing Optimizer Agent
+
+**Model:** claude-sonnet-4-5
+**Purpose:** Cross-platform ad budget optimization — reads Meta + Google Ads data, computes blended ROAS, and recommends specific budget shifts.
+
+---
+
+## Instructions
+
+You are the marketing optimizer. Your job is to analyze ad performance across Meta Ads and Google Ads, compute blended ROAS, and produce specific, actionable budget recommendations.
+
+### Input
+
+Read pre-gathered marketing data from the ops-marketing-dash script:
+```bash
+"${CLAUDE_PLUGIN_ROOT:-$HOME/.claude/plugins/ops-ops-marketplace}/bin/ops-marketing-dash" 2>/dev/null
+```
+
+Parse the JSON output. Look for:
+- `meta_ads.spend`, `meta_ads.roas`, `meta_ads.purchases`, `meta_ads.campaigns[]`
+- `google_ads.spend`, `google_ads.conversions_value`, `google_ads.campaigns[]`
+- `klaviyo.attributed_revenue`
+- `ga4.revenue`, `ga4.conversions`
+
+If ops-marketing-dash data is unavailable, pull directly:
+
+**Meta Ads (last 7d):**
+```bash
+META_TOKEN=$(claude plugin config get meta_ads_token 2>/dev/null || echo "$META_ADS_TOKEN")
+META_ACCOUNT=$(claude plugin config get meta_ad_account_id 2>/dev/null || echo "$META_AD_ACCOUNT_ID")
+curl -s "https://graph.facebook.com/v20.0/${META_ACCOUNT}/insights?fields=spend,actions,action_values,impressions,clicks&date_preset=last_7d&level=account" \
+ -H "Authorization: Bearer ${META_TOKEN}"
+```
+
+**Google Ads (last 7d):**
+```bash
+# Use credentials from Credential Resolution in ops-marketing SKILL.md
+# GAQL query:
+# SELECT campaign.name, metrics.cost_micros, metrics.conversions, metrics.conversions_value, metrics.impressions, metrics.clicks
+# FROM campaign WHERE segments.date DURING LAST_7_DAYS AND campaign.status = ENABLED
+# ORDER BY metrics.cost_micros DESC LIMIT 20
+```
+
+### Analysis
+
+1. **Compute blended ROAS**: (Meta revenue + Google revenue) / (Meta spend + Google spend)
+2. **Compare platform ROAS**: Identify which platform has higher ROAS
+3. **Identify campaigns**: Find top 3 and bottom 3 campaigns by ROAS on each platform
+4. **Spot inefficiencies**: Campaigns with spend > $50 and ROAS < 1x
+5. **Budget shift math**: Calculate specific dollar amounts to reallocate
+
+### Output Format
+
+Always output in this exact format:
+
+```
+━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
+ AD OPTIMIZATION REPORT — [date range]
+━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
+
+PERFORMANCE SUMMARY
+ Meta Ads: $[spend] spent | [ROAS]x ROAS | [N] purchases
+ Google Ads: $[spend] spent | [ROAS]x ROAS | [N] conversions
+ Blended: $[total] spent | [ROAS]x ROAS | $[revenue] attributed
+
+HEALTH SCORE: [N]/100 ([Healthy/Warning/Critical])
+ • ROAS: [N pts] — [explanation]
+ • Diversification: [N pts] — [explanation]
+ • Efficiency: [N pts] — [explanation]
+
+RECOMMENDATIONS (by impact)
+
+1. [ACTION]: [Specific campaign or platform]
+ Current: $[X]/day budget | [ROAS]x ROAS
+ Recommended: $[X]/day (+/- $X)
+ Expected impact: +[X]% revenue / +$[X] attributed
+ Rationale: [1 sentence]
+
+2. [ACTION]: [Specific campaign or platform]
+ ...
+
+3. [ACTION]: [Specific campaign or platform]
+ ...
+
+BUDGET REALLOCATION SUMMARY
+ Move $[X]/day: [Source platform/campaign] → [Destination platform/campaign]
+ Net budget change: $0 (reallocation only) OR $+X (increase)
+
+TOP CAMPAIGNS TO SCALE
+ 1. [Name] — [ROAS]x ROAS — increase budget by $[X]/day
+ 2. [Name] — [ROAS]x ROAS — increase budget by $[X]/day
+
+CAMPAIGNS TO REVIEW/PAUSE
+ 1. [Name] — [ROAS]x ROAS — spent $[X] with $[X] revenue — consider pausing
+ 2. [Name] — [ROAS]x ROAS — ...
+
+Note: All recommendations are advisory. Use /ops:marketing meta-manage or google-ads campaigns to execute changes. Budget changes require confirmation per Rule 5.
+```
+
+### Health Score Computation
+
+Score 0-100 based on:
+- Blended ROAS ≥ 3x: +30 | 1-3x: +15 | < 1x: +0
+- Platform diversification (both Meta + Google active): +20 | one platform: +10 | none: +0
+- No campaigns with CPA > 3x target: +20 | some: +10 | many: +0
+- Spend efficiency (clicks/$ improving week-over-week): +20 | stable: +10 | declining: +0
+- Budget utilization (actual spend vs budget): +10 | partial: +5 | over/under: +0
+
+Thresholds: ≥70 = Healthy, 40-69 = Warning, < 40 = Critical.
+
+### Rules
+
+- Never recommend pausing or deleting campaigns directly — say "consider pausing" and direct user to use the management sub-commands
+- All budget numbers must be specific (not "increase by ~20%", but "increase by $15/day")
+- If data is missing for a platform, say so explicitly and compute with available data only
+- Recommendations must be ranked by expected revenue impact (highest first)
diff --git a/claude-ops/bin/ops-marketing-dash b/claude-ops/bin/ops-marketing-dash
index 5f3d05ce..8ac0b9b4 100755
--- a/claude-ops/bin/ops-marketing-dash
+++ b/claude-ops/bin/ops-marketing-dash
@@ -1,6 +1,7 @@
#!/usr/bin/env bash
# ops-marketing-dash — pre-gathers data from all configured marketing channels
# Output: JSON object with data from each channel (null for unconfigured)
+# v1.5: adds Instagram, blended_roas, marketing_health_score
set -euo pipefail
@@ -31,6 +32,7 @@ fi
# Strip dashes from customer ID (API requires no dashes)
GADS_CUSTOMER_ID="${GADS_CUSTOMER_ID//-/}"
+INSTAGRAM_ACCOUNT_ID="${INSTAGRAM_ACCOUNT_ID:-$(claude plugin config get instagram_account_id 2>/dev/null || echo "")}"
TODAY=$(date +%Y-%m-%d)
@@ -179,6 +181,49 @@ gather_gsc() {
'{clicks: $clicks, impressions: $impressions, ctr: $ctr, avg_position: $position}'
}
+# --- Instagram ---
+gather_instagram() {
+ if [ -z "$META_TOKEN" ]; then
+ echo "null"
+ return
+ fi
+
+ # Resolve IG account ID if not cached
+ IG_ID="$INSTAGRAM_ACCOUNT_ID"
+ if [ -z "$IG_ID" ]; then
+ IG_ID=$(curl -s "https://graph.facebook.com/v21.0/me/accounts?fields=instagram_business_account" \
+ -H "Authorization: Bearer ${META_TOKEN}" 2>/dev/null | jq -r '.data[0].instagram_business_account.id // empty')
+ [ -n "$IG_ID" ] && claude plugin config set instagram_account_id "$IG_ID" 2>/dev/null
+ fi
+
+ if [ -z "$IG_ID" ]; then
+ echo "null"
+ return
+ fi
+
+ # Account stats
+ ACCOUNT=$(curl -s "https://graph.facebook.com/v21.0/${IG_ID}?fields=followers_count,media_count" \
+ -H "Authorization: Bearer ${META_TOKEN}" 2>/dev/null)
+ FOLLOWERS=$(echo "$ACCOUNT" | jq -r '.followers_count // 0')
+ MEDIA_COUNT=$(echo "$ACCOUNT" | jq -r '.media_count // 0')
+
+ # Reach last 7d
+ END_DATE=$(date +%Y-%m-%d)
+ START_DATE=$(date -v-7d +%Y-%m-%d 2>/dev/null || date -d '7 days ago' +%Y-%m-%d 2>/dev/null || echo "")
+ REACH=0
+ if [ -n "$START_DATE" ]; then
+ INSIGHTS=$(curl -s "https://graph.facebook.com/v21.0/${IG_ID}/insights?metric=reach&period=day&since=${START_DATE}&until=${END_DATE}" \
+ -H "Authorization: Bearer ${META_TOKEN}" 2>/dev/null)
+ REACH=$(echo "$INSIGHTS" | jq '[.data[]?.values[]?.value | tonumber] | add // 0' 2>/dev/null || echo "0")
+ fi
+
+ jq -n \
+ --argjson followers "$FOLLOWERS" \
+ --argjson media_count "$MEDIA_COUNT" \
+ --argjson reach_7d "$REACH" \
+ '{followers: $followers, media_count: $media_count, reach_7d: $reach_7d}'
+}
+
# --- Google Ads ---
gather_google_ads() {
if [ -z "$GADS_REFRESH_TOKEN" ] || [ -z "$GADS_DEV_TOKEN" ]; then
@@ -212,8 +257,41 @@ META_DATA=$(gather_meta) &
GA4_DATA=$(gather_ga4) &
GSC_DATA=$(gather_gsc) &
GADS_DATA=$(gather_google_ads) &
+INSTAGRAM_DATA=$(gather_instagram) &
wait
+# Compute blended ROAS across Meta + Google Ads
+META_SPEND=$(echo "$META_DATA" | jq -r '.spend // "0"' 2>/dev/null || echo "0")
+META_REV=$(echo "$META_DATA" | jq -r '.purchase_value // "0"' 2>/dev/null || echo "0")
+GADS_SPEND_RAW=$(echo "$GADS_DATA" | jq '[.[].results[]?.metrics.costMicros // "0" | tonumber] | add / 1000000 // 0' 2>/dev/null || echo "0")
+GADS_REV_RAW=$(echo "$GADS_DATA" | jq '[.[].results[]?.metrics.conversionsValue // "0" | tonumber] | add // 0' 2>/dev/null || echo "0")
+TOTAL_SPEND=$(awk "BEGIN { printf \"%.2f\", ${META_SPEND:-0} + ${GADS_SPEND_RAW:-0} }")
+TOTAL_REV=$(awk "BEGIN { printf \"%.2f\", ${META_REV:-0} + ${GADS_REV_RAW:-0} }")
+BLENDED_ROAS=$(awk "BEGIN { if (${TOTAL_SPEND:-0} > 0) printf \"%.2f\", ${TOTAL_REV:-0} / ${TOTAL_SPEND:-1}; else print \"0\" }")
+
+# Compute marketing health score (0-100)
+# ROAS score (0-30)
+ROAS_SCORE=$(awk "BEGIN { r = ${BLENDED_ROAS:-0}; if (r >= 3) print 30; else if (r >= 1) print 15; else print 0 }")
+# Email open rate score — use Klaviyo data if available (0-20)
+EMAIL_SCORE=10 # default medium score if no open rate data available
+# Channel diversification (0-20): count active platforms
+ACTIVE_CHANNELS=0
+[ "$(echo "$META_DATA" | jq -r '.spend // "0"')" != "0" ] && ACTIVE_CHANNELS=$((ACTIVE_CHANNELS + 1))
+[ "$(echo "$GADS_SPEND_RAW" | tr -d ' ')" != "0" ] && ACTIVE_CHANNELS=$((ACTIVE_CHANNELS + 1))
+[ "$(echo "$KLAVIYO_DATA" | jq -r '.subscribers // 0')" != "0" ] && ACTIVE_CHANNELS=$((ACTIVE_CHANNELS + 1))
+[ "$(echo "$INSTAGRAM_DATA" | jq -r '.followers // 0')" != "0" ] && ACTIVE_CHANNELS=$((ACTIVE_CHANNELS + 1))
+DIV_SCORE=$([ $ACTIVE_CHANNELS -ge 3 ] && echo 20 || ([ $ACTIVE_CHANNELS -ge 2 ] && echo 10 || echo 0))
+# GA4 CVR score (0-20)
+GA4_CVR=$(echo "$GA4_DATA" | jq -r '.cvr // "0"' 2>/dev/null || echo "0")
+CVR_SCORE=$(awk "BEGIN { c = ${GA4_CVR:-0}; if (c >= 2) print 20; else if (c >= 1) print 10; else print 0 }")
+# SEO clicks score (0-10)
+GSC_CLICKS=$(echo "$GSC_DATA" | jq -r '.clicks // 0' 2>/dev/null || echo "0")
+SEO_SCORE=$(awk "BEGIN { c = ${GSC_CLICKS:-0}; if (c >= 1000) print 10; else if (c >= 100) print 5; else print 0 }")
+HEALTH_SCORE=$((ROAS_SCORE + EMAIL_SCORE + DIV_SCORE + CVR_SCORE + SEO_SCORE))
+HEALTH_STATUS="Critical"
+[ $HEALTH_SCORE -ge 40 ] && HEALTH_STATUS="Warning"
+[ $HEALTH_SCORE -ge 70 ] && HEALTH_STATUS="Healthy"
+
# Emit unified JSON
jq -n \
--argjson klaviyo "$KLAVIYO_DATA" \
@@ -221,5 +299,9 @@ jq -n \
--argjson ga4 "$GA4_DATA" \
--argjson gsc "$GSC_DATA" \
--argjson google_ads "$GADS_DATA" \
+ --argjson instagram "$INSTAGRAM_DATA" \
+ --arg blended_roas "$BLENDED_ROAS" \
+ --argjson health_score "$HEALTH_SCORE" \
+ --arg health_status "$HEALTH_STATUS" \
--arg date "$TODAY" \
- '{date: $date, klaviyo: $klaviyo, meta: $meta, ga4: $ga4, gsc: $gsc, google_ads: $google_ads}'
+ '{date: $date, klaviyo: $klaviyo, meta: $meta, ga4: $ga4, gsc: $gsc, google_ads: $google_ads, instagram: $instagram, blended_roas: $blended_roas, health_score: $health_score, health_status: $health_status}'
diff --git a/claude-ops/skills/ops-go/SKILL.md b/claude-ops/skills/ops-go/SKILL.md
index 95819675..bb9b5b22 100644
--- a/claude-ops/skills/ops-go/SKILL.md
+++ b/claude-ops/skills/ops-go/SKILL.md
@@ -163,6 +163,12 @@ PORTFOLIO DASHBOARD
EXTERNAL PROJECTS
[table: alias, source, status, details — from ops-external data]
+MARKETING
+ Health: [N]/100 ([Healthy/Warning/Critical]) | Blended ROAS: [X]x | Top channel: [channel]
+ Meta: $[X] spent (7d) [X]x ROAS | Google: $[X] spent (7d) [X]x ROAS | Email: [N] subs
+[If health < 70: "⚠ Run /ops:marketing optimize for recommendations"]
+[If no marketing configured: "(marketing not configured — /ops:marketing setup)"]
+
UNREAD
[WhatsApp: N, Email: N, Slack: check MCP, Notion: N items, Calendar: N events today]
@@ -174,6 +180,8 @@ TODAY'S PRIORITIES (ranked by revenue impact + urgency)
──────────────────────────────────────────────────────
```
+**Marketing section data source**: Read from `ops-marketing-dash` pre-gathered output (see Pre-gathered data section). If marketing data is present in the dash output, compute the health score inline (see ops-marketing SKILL.md health score formula). If ops-marketing-dash is not configured or returns empty marketing data, show `(marketing not configured — /ops:marketing setup)`.
+
**Priority ranking**: fires > degraded infra > CI failures > unread comms > ready-to-merge PRs > revenue-generating GSD work > stale projects.
If `$ARGUMENTS` contains a project alias, focus the briefing on that project only.
diff --git a/claude-ops/skills/ops-marketing/SKILL.md b/claude-ops/skills/ops-marketing/SKILL.md
index 9772b862..61ad7750 100644
--- a/claude-ops/skills/ops-marketing/SKILL.md
+++ b/claude-ops/skills/ops-marketing/SKILL.md
@@ -171,12 +171,17 @@ Route `$ARGUMENTS` to the correct section below:
|---|---|
| (empty), dashboard | Run full marketing dashboard |
| email, klaviyo | Klaviyo email metrics |
-| ads, meta | Meta Ads performance |
+| ads, meta | Meta Ads performance (read-only overview) |
+| meta-manage, meta create-campaign, meta target, meta creative, meta rules, meta audiences, meta advantage | Meta Ads campaign management (see ## meta-manage section) |
| google-ads, gads | Google Ads dashboard + campaign management (see ## google-ads section) |
| analytics, ga4 | GA4 sessions + conversions |
+| ga4 realtime, ga4 funnel, ga4 cohort, ga4 audience, ga4 pivot | GA4 advanced analytics (see ## ga4-advanced section) |
| seo, gsc | Search Console metrics |
| social | Social media aggregator |
-| campaigns | Cross-channel campaign overview |
+| instagram, instagram post, instagram reel, instagram story, instagram insights, instagram demographics | Instagram publishing + insights (see ## instagram section) |
+| campaigns | Cross-channel campaign overview (all platforms) |
+| optimize | Cross-platform ad optimization agent |
+| attribution | Unified attribution table (Meta + Google + Klaviyo + GA4) |
| setup | Configure API keys |
---
@@ -276,6 +281,275 @@ curl -s "https://graph.facebook.com/v18.0/${META_ACCOUNT}/ads?fields=name,adset_
---
+## meta-manage
+
+Full Meta Ads campaign management. Uses same `META_TOKEN` and `META_ACCOUNT` credentials as read-only `ads` section.
+
+**Credential check**: If `META_TOKEN` is empty, print `Meta Ads not configured. Run /ops:marketing setup.` and stop.
+
+Route `$ARGUMENTS` within meta-manage:
+
+| Input | Action |
+|---|---|
+| create-campaign | Create a new campaign (always PAUSED) |
+| target \<ADSET_ID\> | Configure ad set targeting |
+| creative \<CAMPAIGN_ID\> | Upload image + create ad with copy |
+| rules | List / create automation rules |
+| audiences | Create custom or lookalike audiences |
+| advantage | Create Advantage+ AI-optimized campaign |
+
+### create-campaign
+
+Collect via AskUserQuestion (max 4 options each call):
+
+1. Campaign objective — `[OUTCOME_TRAFFIC, OUTCOME_SALES, OUTCOME_LEADS, OUTCOME_AWARENESS]`
+2. Daily budget in dollars (free text)
+3. Campaign name (free text)
+
+Then confirm via AskUserQuestion: `"Create Meta campaign '<NAME>' with $<BUDGET>/day budget?"` options `[Create, Cancel]`
+
+```bash
+BUDGET_CENTS=$(awk "BEGIN {printf \"%d\", ${BUDGET_DOLLARS} * 100}")
+curl -s -X POST "https://graph.facebook.com/v20.0/${META_ACCOUNT}/campaigns" \
+ -H "Authorization: Bearer ${META_TOKEN}" \
+ -F "name=${CAMPAIGN_NAME}" \
+ -F "objective=${OBJECTIVE}" \
+ -F "status=PAUSED" \
+ -F "special_ad_categories=[]" \
+ -F "daily_budget=${BUDGET_CENTS}" | jq '{id: .id, error: .error.message}'
+```
+
+Print: `Campaign "${CAMPAIGN_NAME}" created (ID: <ID>, status: PAUSED, budget: $<BUDGET>/day). Enable via Meta Ads Manager or add ad sets first.`
+
+If error, print the error message.
+
+### target \<ADSET_ID\>
+
+Configure targeting for an existing ad set. Collect via AskUserQuestion:
+
+1. Target countries (comma-separated ISO codes, e.g. `US,CA,GB`) — free text
+2. Age range: `[18-34, 25-54, 35-65, 18-65]`
+3. Gender: `[All, Men only, Women only, Skip]`
+
+```bash
+# Build geo_locations JSON
+GEO_JSON=$(echo "$COUNTRIES" | tr ',' '\n' | jq -Rc '.' | jq -sc '{"countries": .}')
+
+# Build targeting spec
+TARGETING_JSON=$(jq -n \
+ --argjson geo "$GEO_JSON" \
+ --arg age_min "$AGE_MIN" \
+ --arg age_max "$AGE_MAX" \
+ '{
+ geo_locations: $geo,
+ age_min: ($age_min | tonumber),
+ age_max: ($age_max | tonumber)
+ }')
+
+# Add gender filter if requested
+if [ "$GENDER" = "Men only" ]; then
+ TARGETING_JSON=$(echo "$TARGETING_JSON" | jq '. + {"genders": [1]}')
+elif [ "$GENDER" = "Women only" ]; then
+ TARGETING_JSON=$(echo "$TARGETING_JSON" | jq '. + {"genders": [2]}')
+fi
+
+curl -s -X POST "https://graph.facebook.com/v20.0/${ADSET_ID}" \
+ -H "Authorization: Bearer ${META_TOKEN}" \
+ -F "targeting=${TARGETING_JSON}" | jq '{success: .success, error: .error.message}'
+```
+
+Print: `Ad set ${ADSET_ID} targeting updated: ${COUNTRIES}, ages ${AGE_MIN}-${AGE_MAX}${GENDER_LABEL}.`
+
+### creative \<CAMPAIGN_ID\>
+
+Upload an image and create an ad. Collect via AskUserQuestion:
+
+1. Image file path or URL (free text)
+2. Ad set ID to attach the ad to (free text)
+3. Primary text (ad copy, free text — up to 125 characters recommended)
+
+Then collect headline (free text, up to 40 characters) via a second AskUserQuestion.
+
+```bash
+# Step 1: Upload image
+if [[ "$IMAGE_INPUT" == http* ]]; then
+ # Upload by URL
+ UPLOAD_RESP=$(curl -s -X POST "https://graph.facebook.com/v20.0/${META_ACCOUNT}/adimages" \
+ -H "Authorization: Bearer ${META_TOKEN}" \
+ -F "url=${IMAGE_INPUT}")
+else
+ # Upload by file (multipart)
+ UPLOAD_RESP=$(curl -s -X POST "https://graph.facebook.com/v20.0/${META_ACCOUNT}/adimages" \
+ -H "Authorization: Bearer ${META_TOKEN}" \
+ -F "filename=@${IMAGE_INPUT}")
+fi
+IMAGE_HASH=$(echo "$UPLOAD_RESP" | jq -r '.images | to_entries[0].value.hash // empty')
+
+if [ -z "$IMAGE_HASH" ]; then
+ echo "Image upload failed: $(echo "$UPLOAD_RESP" | jq -r '.error.message // "unknown error"')"
+ exit 0
+fi
+
+# Step 2: Create ad creative
+CREATIVE_RESP=$(curl -s -X POST "https://graph.facebook.com/v20.0/${META_ACCOUNT}/adcreatives" \
+ -H "Authorization: Bearer ${META_TOKEN}" \
+ -F "name=Creative for ${AD_NAME}" \
+ -F "object_story_spec={\"page_id\": \"$(echo "$META_ACCOUNT" | sed 's/act_//')\", \"link_data\": {\"image_hash\": \"${IMAGE_HASH}\", \"message\": \"${PRIMARY_TEXT}\", \"name\": \"${HEADLINE}\"}}")
+CREATIVE_ID=$(echo "$CREATIVE_RESP" | jq -r '.id // empty')
+
+if [ -z "$CREATIVE_ID" ]; then
+ echo "Creative creation failed: $(echo "$CREATIVE_RESP" | jq -r '.error.message // "unknown error"')"
+ exit 0
+fi
+
+# Step 3: Create ad (status PAUSED — Rule 5)
+curl -s -X POST "https://graph.facebook.com/v20.0/${META_ACCOUNT}/ads" \
+ -H "Authorization: Bearer ${META_TOKEN}" \
+ -F "name=${AD_NAME}" \
+ -F "adset_id=${ADSET_ID}" \
+ -F "creative={\"creative_id\": \"${CREATIVE_ID}\"}" \
+ -F "status=PAUSED" | jq '{id: .id, error: .error.message}'
+```
+
+Print: `Ad created (ID: <ID>, creative: <CREATIVE_ID>, status: PAUSED). Enable via Meta Ads Manager when ready.`
+
+### rules
+
+List existing rules or create a new automation rule.
+
+**List rules:**
+```bash
+curl -s "https://graph.facebook.com/v20.0/${META_ACCOUNT}/adrules_library?fields=name,status,evaluation_spec,execution_spec" \
+ -H "Authorization: Bearer ${META_TOKEN}" | jq '.data[] | {id: .id, name: .name, status: .status}'
+```
+
+**Create rule** (prompt via AskUserQuestion):
+
+1. Rule type: `[Pause low performers, Scale winners, Increase budget, Decrease budget]`
+
+For "Pause low performers":
+```bash
+# Pause ads where CPA > $50 and spend > $20 in last 7 days
+curl -s -X POST "https://graph.facebook.com/v20.0/${META_ACCOUNT}/adrules_library" \
+ -H "Authorization: Bearer ${META_TOKEN}" \
+ -H "Content-Type: application/json" \
+ -d '{
+ "name": "Pause high CPA ads",
+ "schedule_spec": {"schedule_type": "SEMI_HOURLY"},
+ "evaluation_spec": {
+ "evaluation_type": "SCHEDULE",
+ "filters": [
+ {"field": "cost_per_result", "value": [50], "operator": "GREATER_THAN"},
+ {"field": "spent", "value": [20], "operator": "GREATER_THAN"},
+ {"field": "entity_type", "value": ["AD"], "operator": "EQUAL"},
+ {"field": "time_preset", "value": ["LAST_7_DAYS"], "operator": "EQUAL"}
+ ]
+ },
+ "execution_spec": {
+ "execution_type": "PAUSE"
+ },
+ "status": "ENABLED"
+ }' | jq '{id: .id, error: .error.message}'
+```
+
+For "Scale winners":
+```bash
+# Increase budget 20% for ad sets with ROAS > 3x in last 7 days
+curl -s -X POST "https://graph.facebook.com/v20.0/${META_ACCOUNT}/adrules_library" \
+ -H "Authorization: Bearer ${META_TOKEN}" \
+ -H "Content-Type: application/json" \
+ -d '{
+ "name": "Scale winning ad sets",
+ "schedule_spec": {"schedule_type": "DAILY"},
+ "evaluation_spec": {
+ "evaluation_type": "SCHEDULE",
+ "filters": [
+ {"field": "purchase_roas", "value": [3], "operator": "GREATER_THAN"},
+ {"field": "entity_type", "value": ["ADSET"], "operator": "EQUAL"},
+ {"field": "time_preset", "value": ["LAST_7_DAYS"], "operator": "EQUAL"}
+ ]
+ },
+ "execution_spec": {
+ "execution_type": "INCREASE_BUDGET",
+ "execution_options": [{"field": "budget_value", "value": "20", "operator": "PERCENTAGE"}]
+ },
+ "status": "ENABLED"
+ }' | jq '{id: .id, error: .error.message}'
+```
+
+Print: `Rule created (ID: <ID>). Runs semi-hourly and will auto-pause ads with CPA > $50.`
+
+### audiences
+
+Create Custom Audience or Lookalike Audience.
+
+**Prompt via AskUserQuestion:**
+1. Audience type: `[Custom — website, Custom — customer list, Lookalike, Skip]`
+
+**Custom — website (Pixel-based):**
+```bash
+curl -s -X POST "https://graph.facebook.com/v20.0/${META_ACCOUNT}/customaudiences" \
+ -H "Authorization: Bearer ${META_TOKEN}" \
+ -H "Content-Type: application/json" \
+ -d '{
+ "name": "Website visitors — last 30 days",
+ "subtype": "WEBSITE",
+ "retention_days": 30,
+ "rule": {"inclusions": {"operator": "or", "rules": [{"event_sources": [{"id": "<PIXEL_ID>", "type": "pixel"}], "retention_seconds": 2592000, "filter": {"operator": "and", "filters": [{"field": "event", "operator": "eq", "value": "PageView"}]}}]}}
+ }' | jq '{id: .id, name: .name, error: .error.message}'
+```
+
+Note: Replace `<PIXEL_ID>` with actual pixel ID from Meta Events Manager.
+
+**Lookalike Audience** (requires origin audience with min 100 matched profiles):
+```bash
+# Prompt for origin audience ID via AskUserQuestion (free text)
+curl -s -X POST "https://graph.facebook.com/v20.0/${META_ACCOUNT}/customaudiences" \
+ -H "Authorization: Bearer ${META_TOKEN}" \
+ -H "Content-Type: application/json" \
+ -d "{
+ \"name\": \"Lookalike — ${ORIGIN_AUDIENCE_NAME} 1%\",
+ \"subtype\": \"LOOKALIKE\",
+ \"origin_audience_id\": \"${ORIGIN_AUDIENCE_ID}\",
+ \"lookalike_spec\": {
+ \"country\": \"US\",
+ \"ratio\": 0.01,
+ \"type\": \"similarity\"
+ }
+ }" | jq '{id: .id, name: .name, error: .error.message}'
+```
+
+Print: `Lookalike audience created (ID: <ID>). Typically takes 1-6 hours to populate.`
+
+### advantage
+
+Create an Advantage+ Shopping Campaign (AI-optimized).
+
+Collect via AskUserQuestion:
+1. Daily budget in dollars (free text)
+2. Campaign name (free text)
+
+Then confirm: `"Create Advantage+ campaign '<NAME>' with $<BUDGET>/day?"` options `[Create, Cancel]`
+
+```bash
+BUDGET_CENTS=$(awk "BEGIN {printf \"%d\", ${BUDGET_DOLLARS} * 100}")
+curl -s -X POST "https://graph.facebook.com/v20.0/${META_ACCOUNT}/campaigns" \
+ -H "Authorization: Bearer ${META_TOKEN}" \
+ -H "Content-Type: application/json" \
+ -d "{
+ \"name\": \"${CAMPAIGN_NAME}\",
+ \"objective\": \"OUTCOME_SALES\",
+ \"status\": \"PAUSED\",
+ \"special_ad_categories\": [],
+ \"daily_budget\": ${BUDGET_CENTS},
+ \"smart_promotion_type\": \"AUTOMATED_SHOPPING_ADS\"
+ }" | jq '{id: .id, error: .error.message}'
+```
+
+Print: `Advantage+ campaign "${CAMPAIGN_NAME}" created (ID: <ID>, status: PAUSED). Meta AI will optimize targeting and creative delivery once enabled.`
+
+---
+
## analytics / ga4
Pull GA4 data via the Data API using gcloud ADC.
@@ -353,6 +627,286 @@ If `GA4_TOKEN` is empty or gcloud not available, output: `GA4 not configured —
---
+## ga4-advanced
+
+Advanced GA4 analytics: realtime, funnel, cohort, audience export, and pivot reports.
+
+**Credential check**: If `GA4_TOKEN` is empty or `GA4_PROPERTY` is missing, print `GA4 not configured — run /ops:marketing setup or configure gcloud ADC` and stop.
+
+Route `$ARGUMENTS` within ga4-advanced (matches `ga4 <sub>` pattern):
+
+| Input | Action |
+|---|---|
+| realtime | Active users right now (last 30 min) |
+| funnel | Conversion funnel with step visualization |
+| cohort | Cohort retention analysis by device |
+| audience | Async audience segment export |
+| pivot | Multi-dimensional pivot report |
+
+### realtime
+
+```bash
+GA4_TOKEN=$(gcloud auth application-default print-access-token 2>/dev/null)
+RESULT=$(curl -s -X POST "https://analyticsdata.googleapis.com/v1beta/properties/${GA4_PROPERTY}:runRealtimeReport" \
+ -H "Authorization: Bearer ${GA4_TOKEN}" \
+ -H "Content-Type: application/json" \
+ -d '{
+ "minuteRanges": [{"startMinutesAgo": 29, "endMinutesAgo": 0}],
+ "dimensions": [
+ {"name": "unifiedScreenName"},
+ {"name": "deviceCategory"}
+ ],
+ "metrics": [{"name": "activeUsers"}],
+ "orderBys": [{"metric": {"metricName": "activeUsers"}, "desc": true}],
+ "limit": 10
+ }')
+
+TOTAL=$(echo "$RESULT" | jq '[.rows[]?.metricValues[0].value | tonumber] | add // 0')
+
+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+echo " GA4 REALTIME — Last 30 Minutes"
+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+echo ""
+echo "Active Users Right Now: ${TOTAL}"
+echo ""
+echo "Top Pages:"
+printf "| %-40s | %-8s | %-7s |\n" "Page" "Device" "Users"
+printf "|%s|%s|%s|\n" "------------------------------------------" "----------" "---------"
+echo "$RESULT" | jq -r '.rows[]? | [.dimensionValues[0].value, .dimensionValues[1].value, .metricValues[0].value] | @tsv' 2>/dev/null | \
+ while IFS=$'\t' read -r page device users; do
+ printf "| %-40s | %-8s | %-7s |\n" "${page:0:40}" "$device" "$users"
+ done
+```
+
+### funnel
+
+Ask user for funnel steps via AskUserQuestion (free text). Default template uses session_start → page_view → purchase.
+
+```bash
+# NOTE: Uses v1alpha — breaking changes possible per Google's versioning policy
+GA4_TOKEN=$(gcloud auth application-default print-access-token 2>/dev/null)
+
+# Prompt for funnel type first
+# AskUserQuestion: "Funnel mode?" options [Closed funnel, Open funnel]
+
+IS_OPEN=$([ "$FUNNEL_MODE" = "Open funnel" ] && echo "true" || echo "false")
+
+RESULT=$(curl -s -X POST "https://analyticsdata.googleapis.com/v1alpha/properties/${GA4_PROPERTY}:runFunnelReport" \
+ -H "Authorization: Bearer ${GA4_TOKEN}" \
+ -H "Content-Type: application/json" \
+ -d "{
+ \"dateRanges\": [{\"startDate\": \"30daysAgo\", \"endDate\": \"today\"}],
+ \"funnel\": {
+ \"isOpenFunnel\": ${IS_OPEN},
+ \"steps\": [
+ {
+ \"name\": \"Session Start\",
+ \"filterExpression\": {\"funnelEventFilter\": {\"eventName\": \"session_start\"}}
+ },
+ {
+ \"name\": \"Page View\",
+ \"filterExpression\": {\"funnelEventFilter\": {\"eventName\": \"page_view\"}}
+ },
+ {
+ \"name\": \"Purchase\",
+ \"filterExpression\": {\"funnelEventFilter\": {\"eventName\": \"purchase\"}}
+ }
+ ]
+ },
+ \"funnelBreakdown\": {
+ \"breakdownDimension\": {\"name\": \"deviceCategory\"},
+ \"limit\": 4
+ }
+ }")
+
+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+echo " GA4 FUNNEL — Last 30 Days (${FUNNEL_MODE})"
+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+echo ""
+echo "$RESULT" | jq -r '
+ .funnelTable.rows[]? |
+ "Step: \(.dimensionValues[0].value) Users: \(.metricValues[0].value) Completion: \(.metricValues[1].value)% Abandoned: \(.metricValues[2].value)"
+' 2>/dev/null || echo "No funnel data — ensure purchase events are firing in GA4."
+```
+
+### cohort
+
+Weekly cohort retention for users acquired in the past month, broken down by device.
+
+```bash
+GA4_TOKEN=$(gcloud auth application-default print-access-token 2>/dev/null)
+START_DATE=$(date -v-30d +%Y-%m-%d 2>/dev/null || date -d '30 days ago' +%Y-%m-%d)
+END_DATE=$(date +%Y-%m-%d)
+
+RESULT=$(curl -s -X POST "https://analyticsdata.googleapis.com/v1beta/properties/${GA4_PROPERTY}:runReport" \
+ -H "Authorization: Bearer ${GA4_TOKEN}" \
+ -H "Content-Type: application/json" \
+ -d "{
+ \"dimensions\": [
+ {\"name\": \"cohort\"},
+ {\"name\": \"cohortNthWeek\"},
+ {\"name\": \"deviceCategory\"}
+ ],
+ \"metrics\": [
+ {\"name\": \"cohortActiveUsers\"},
+ {\"name\": \"cohortRetentionFraction\"}
+ ],
+ \"cohortSpec\": {
+ \"cohorts\": [{
+ \"dimension\": \"firstSessionDate\",
+ \"dateRange\": {\"startDate\": \"${START_DATE}\", \"endDate\": \"${END_DATE}\"}
+ }],
+ \"cohortsRange\": {
+ \"granularity\": \"WEEKLY\",
+ \"startOffset\": 0,
+ \"endOffset\": 5
+ }
+ }
+ }")
+
+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+echo " GA4 COHORT RETENTION — Last 30 Days"
+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+echo ""
+printf "| %-12s | %-6s | %-8s | %-10s | %-10s |\n" "Cohort" "Week" "Device" "Users" "Retention%"
+printf "|%s|%s|%s|%s|%s|\n" "--------------" "--------" "----------" "------------" "------------"
+echo "$RESULT" | jq -r '.rows[]? | [
+ .dimensionValues[0].value,
+ .dimensionValues[1].value,
+ .dimensionValues[2].value,
+ .metricValues[0].value,
+ (.metricValues[1].value | tonumber * 100 | tostring | split(".")[0])
+] | @tsv' 2>/dev/null | \
+ while IFS=$'\t' read -r cohort week device users retention; do
+ printf "| %-12s | %-6s | %-8s | %-10s | %-10s |\n" "$cohort" "$week" "$device" "$users" "${retention}%"
+ done
+```
+
+### audience
+
+Async audience export: create → poll until ACTIVE → show user count.
+
+```bash
+GA4_TOKEN=$(gcloud auth application-default print-access-token 2>/dev/null)
+
+# Step 1: List available audiences so user can pick one
+AUDIENCES=$(curl -s "https://analyticsadmin.googleapis.com/v1alpha/properties/${GA4_PROPERTY}/audiences" \
+ -H "Authorization: Bearer ${GA4_TOKEN}")
+echo "Available audiences:"
+echo "$AUDIENCES" | jq -r '.audiences[]? | "\(.name | split("/") | last): \(.displayName)"' 2>/dev/null
+
+# AskUserQuestion: "Enter audience ID from list above:" (free text)
+
+# Step 2: Create export
+EXPORT_RESP=$(curl -s -X POST \
+ "https://analyticsdata.googleapis.com/v1beta/properties/${GA4_PROPERTY}/audienceExports" \
+ -H "Authorization: Bearer ${GA4_TOKEN}" \
+ -H "Content-Type: application/json" \
+ -d "{
+ \"audience\": \"properties/${GA4_PROPERTY}/audiences/${AUDIENCE_ID}\",
+ \"dimensions\": [
+ {\"dimensionName\": \"deviceId\"},
+ {\"dimensionName\": \"isAdsPersonalizationAllowed\"}
+ ]
+ }")
+EXPORT_NAME=$(echo "$EXPORT_RESP" | jq -r '.name // empty')
+
+if [ -z "$EXPORT_NAME" ]; then
+ echo "Failed to create export: $(echo "$EXPORT_RESP" | jq -r '.error.message // "unknown error"')"
+ exit 0
+fi
+
+echo "Export created: ${EXPORT_NAME}"
+echo "Polling for completion (small audiences: ~30s, large: up to 15 min)..."
+
+# Step 3: Poll until ACTIVE or FAILED
+ATTEMPTS=0
+while [ $ATTEMPTS -lt 60 ]; do
+ STATUS_RESP=$(curl -s "https://analyticsdata.googleapis.com/v1beta/${EXPORT_NAME}" \
+ -H "Authorization: Bearer ${GA4_TOKEN}")
+ STATE=$(echo "$STATUS_RESP" | jq -r '.state // "UNKNOWN"')
+ PCT=$(echo "$STATUS_RESP" | jq -r '.percentageCompleted // 0')
+
+ if [ "$STATE" = "ACTIVE" ]; then break; fi
+ if [ "$STATE" = "FAILED" ]; then
+ echo "Export failed. Try again or check GA4 audience configuration."
+ exit 0
+ fi
+ echo " State: ${STATE} (${PCT}% complete)..."
+ sleep 10
+ ATTEMPTS=$((ATTEMPTS + 1))
+done
+
+# Step 4: Query results
+QUERY_RESP=$(curl -s -X POST \
+ "https://analyticsdata.googleapis.com/v1beta/${EXPORT_NAME}:query" \
+ -H "Authorization: Bearer ${GA4_TOKEN}")
+ROW_COUNT=$(echo "$QUERY_RESP" | jq '.rowCount // 0')
+
+echo ""
+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+echo " GA4 AUDIENCE EXPORT"
+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+echo " Audience ID: ${AUDIENCE_ID}"
+echo " Users exported: ${ROW_COUNT}"
+echo " Ads-eligible: $(echo "$QUERY_RESP" | jq '[.audienceRows[]? | select(.dimensionValues[1].value == "true")] | length') users"
+echo ""
+echo "Export ready. Use this audience for retargeting in Meta or Google Ads."
+```
+
+### pivot
+
+Multi-dimensional pivot: channel group × device category × conversions.
+
+```bash
+GA4_TOKEN=$(gcloud auth application-default print-access-token 2>/dev/null)
+
+RESULT=$(curl -s -X POST "https://analyticsdata.googleapis.com/v1beta/properties/${GA4_PROPERTY}:runPivotReport" \
+ -H "Authorization: Bearer ${GA4_TOKEN}" \
+ -H "Content-Type: application/json" \
+ -d '{
+ "dateRanges": [{"startDate": "30daysAgo", "endDate": "today"}],
+ "dimensions": [
+ {"name": "sessionDefaultChannelGrouping"},
+ {"name": "deviceCategory"}
+ ],
+ "metrics": [
+ {"name": "sessions"},
+ {"name": "conversions"},
+ {"name": "totalRevenue"}
+ ],
+ "pivots": [
+ {
+ "fieldNames": ["sessionDefaultChannelGrouping"],
+ "limit": 6
+ },
+ {
+ "fieldNames": ["deviceCategory"],
+ "limit": 3
+ }
+ ]
+ }')
+
+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+echo " GA4 PIVOT — Channel × Device (Last 30 Days)"
+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+echo ""
+printf "| %-20s | %-8s | %-10s | %-11s | %-10s |\n" "Channel" "Device" "Sessions" "Conversions" "Revenue"
+printf "|%s|%s|%s|%s|%s|\n" "----------------------" "----------" "------------" "-------------" "------------"
+echo "$RESULT" | jq -r '.rows[]? | [
+ .dimensionValues[0].value,
+ .dimensionValues[1].value,
+ .metricValues[0].value,
+ .metricValues[1].value,
+ (.metricValues[2].value | tonumber | . * 100 | round / 100 | tostring)
+] | @tsv' 2>/dev/null | \
+ while IFS=$'\t' read -r channel device sessions convs revenue; do
+ printf "| %-20s | %-8s | %-10s | %-11s | \$%-9s |\n" "${channel:0:20}" "$device" "$sessions" "$convs" "$revenue"
+ done
+```
+
+---
+
## seo / gsc
Pull Google Search Console data.
@@ -461,6 +1015,245 @@ Show `[not configured]` for any unconfigured channels rather than failing.
---
+## instagram
+
+Instagram publishing and insights via Instagram Graph API (same `META_TOKEN` as Meta Ads).
+
+**Prerequisites:**
+- `META_TOKEN` configured (same as Meta Ads)
+- Instagram Business account linked to a Facebook Page
+- `IG_ACCOUNT_ID` resolved via: `curl "https://graph.facebook.com/v21.0/me/accounts?fields=instagram_business_account" -H "Authorization: Bearer ${META_TOKEN}"` → `data[0].instagram_business_account.id`
+
+**Rate limit:** 200 API calls/hour per app. Demographics require 48h reporting delay. Media insights require account with >1,000 followers.
+
+**Resolve IG account ID at the start of every instagram invocation:**
+```bash
+IG_ACCOUNT_ID=$(claude plugin config get instagram_account_id 2>/dev/null)
+if [ -z "$IG_ACCOUNT_ID" ]; then
+ IG_ACCOUNT_ID=$(curl -s "https://graph.facebook.com/v21.0/me/accounts?fields=instagram_business_account" \
+ -H "Authorization: Bearer ${META_TOKEN}" | jq -r '.data[0].instagram_business_account.id // empty')
+ # Cache it
+ [ -n "$IG_ACCOUNT_ID" ] && claude plugin config set instagram_account_id "$IG_ACCOUNT_ID" 2>/dev/null
+fi
+if [ -z "$IG_ACCOUNT_ID" ]; then
+ echo "Instagram Business account not linked to your Meta token. Ensure your Facebook Page has an Instagram Business account connected."
+ exit 0
+fi
+```
+
+Route `$ARGUMENTS` within instagram:
+
+| Input | Action |
+|---|---|
+| post \<IMAGE_URL\> | Publish image post to feed |
+| reel \<VIDEO_URL\> | Publish a Reel |
+| story \<IMAGE_URL\|VIDEO_URL\> | Publish a Story |
+| insights \<MEDIA_ID\> | Per-post metrics |
+| account-insights [days] | Account-level reach + impressions |
+| demographics | Audience age/gender/location |
+
+### post
+
+Publish an image post (two-step: create container → publish).
+
+Collect via AskUserQuestion:
+1. Image URL (publicly accessible HTTPS URL) — free text
+2. Caption — free text
+
+```bash
+# Step 1: Create media container
+CONTAINER=$(curl -s -X POST "https://graph.facebook.com/v21.0/${IG_ACCOUNT_ID}/media" \
+ -H "Authorization: Bearer ${META_TOKEN}" \
+ -F "image_url=${IMAGE_URL}" \
+ -F "caption=${CAPTION}" \
+ -F "media_type=IMAGE")
+CONTAINER_ID=$(echo "$CONTAINER" | jq -r '.id // empty')
+
+if [ -z "$CONTAINER_ID" ]; then
+ echo "Failed to create media container: $(echo "$CONTAINER" | jq -r '.error.message // "unknown error"')"
+ exit 0
+fi
+
+# Step 2: Publish
+PUBLISH=$(curl -s -X POST "https://graph.facebook.com/v21.0/${IG_ACCOUNT_ID}/media_publish" \
+ -H "Authorization: Bearer ${META_TOKEN}" \
+ -F "creation_id=${CONTAINER_ID}")
+MEDIA_ID=$(echo "$PUBLISH" | jq -r '.id // empty')
+
+if [ -n "$MEDIA_ID" ]; then
+ echo "Post published (Media ID: ${MEDIA_ID}). View at https://www.instagram.com/ — may take 1-2 min to appear."
+else
+ echo "Publish failed: $(echo "$PUBLISH" | jq -r '.error.message // "unknown error"')"
+fi
+```
+
+### reel
+
+Publish a Reel. Video must be an HTTPS URL (MP4, H.264, max 15 min, min 500px width).
+
+Collect via AskUserQuestion:
+1. Video URL (HTTPS) — free text
+2. Caption — free text
+
+```bash
+# Step 1: Create video container (async — must poll for status)
+CONTAINER=$(curl -s -X POST "https://graph.facebook.com/v21.0/${IG_ACCOUNT_ID}/media" \
+ -H "Authorization: Bearer ${META_TOKEN}" \
+ -F "media_type=REELS" \
+ -F "video_url=${VIDEO_URL}" \
+ -F "caption=${CAPTION}" \
+ -F "share_to_feed=true")
+CONTAINER_ID=$(echo "$CONTAINER" | jq -r '.id // empty')
+
+if [ -z "$CONTAINER_ID" ]; then
+ echo "Failed to create Reel container: $(echo "$CONTAINER" | jq -r '.error.message // "unknown error"')"
+ exit 0
+fi
+
+echo "Reel uploading... polling for ready status."
+
+# Poll until status is FINISHED
+ATTEMPTS=0
+while [ $ATTEMPTS -lt 30 ]; do
+ STATUS=$(curl -s "https://graph.facebook.com/v21.0/${CONTAINER_ID}?fields=status_code" \
+ -H "Authorization: Bearer ${META_TOKEN}" | jq -r '.status_code // "UNKNOWN"')
+ [ "$STATUS" = "FINISHED" ] && break
+ [ "$STATUS" = "ERROR" ] && echo "Reel processing failed." && exit 0
+ sleep 10
+ ATTEMPTS=$((ATTEMPTS + 1))
+done
+
+# Step 2: Publish
+PUBLISH=$(curl -s -X POST "https://graph.facebook.com/v21.0/${IG_ACCOUNT_ID}/media_publish" \
+ -H "Authorization: Bearer ${META_TOKEN}" \
+ -F "creation_id=${CONTAINER_ID}")
+MEDIA_ID=$(echo "$PUBLISH" | jq -r '.id // empty')
+
+if [ -n "$MEDIA_ID" ]; then
+ echo "Reel published (Media ID: ${MEDIA_ID}). Reach and plays metrics available after 24-48h."
+else
+ echo "Reel publish failed: $(echo "$PUBLISH" | jq -r '.error.message // "unknown error"')"
+fi
+```
+
+### story
+
+Publish a Story (image or video, 24h expiry).
+
+Collect via AskUserQuestion:
+1. Content URL (HTTPS image or video) — free text
+2. Content type: `[Image story, Video story]`
+
+```bash
+if [ "$CONTENT_TYPE" = "Video story" ]; then
+ MEDIA_TYPE="VIDEO"
+ URL_FIELD="video_url"
+else
+ MEDIA_TYPE="IMAGE"
+ URL_FIELD="image_url"
+fi
+
+CONTAINER=$(curl -s -X POST "https://graph.facebook.com/v21.0/${IG_ACCOUNT_ID}/media" \
+ -H "Authorization: Bearer ${META_TOKEN}" \
+ -F "media_type=${MEDIA_TYPE}" \
+ -F "${URL_FIELD}=${CONTENT_URL}" \
+ -F "media_type=STORIES")
+CONTAINER_ID=$(echo "$CONTAINER" | jq -r '.id // empty')
+
+if [ -z "$CONTAINER_ID" ]; then
+ echo "Failed to create Story container: $(echo "$CONTAINER" | jq -r '.error.message // "unknown error"')"
+ exit 0
+fi
+
+PUBLISH=$(curl -s -X POST "https://graph.facebook.com/v21.0/${IG_ACCOUNT_ID}/media_publish" \
+ -H "Authorization: Bearer ${META_TOKEN}" \
+ -F "creation_id=${CONTAINER_ID}")
+MEDIA_ID=$(echo "$PUBLISH" | jq -r '.id // empty')
+
+if [ -n "$MEDIA_ID" ]; then
+ echo "Story published (Media ID: ${MEDIA_ID}). Expires after 24 hours."
+else
+ echo "Story publish failed: $(echo "$PUBLISH" | jq -r '.error.message // "unknown error"')"
+fi
+```
+
+### insights \<MEDIA_ID\>
+
+Per-post metrics. Note: reach, saves, shares deprecated for non-Reels video; plays only for Reels/video.
+
+```bash
+METRICS="reach,saved,shares,comments_count,like_count,impressions"
+# For Reels, add plays: detect via media_type field
+MEDIA_TYPE=$(curl -s "https://graph.facebook.com/v21.0/${MEDIA_ID}?fields=media_type" \
+ -H "Authorization: Bearer ${META_TOKEN}" | jq -r '.media_type // "IMAGE"')
+[ "$MEDIA_TYPE" = "VIDEO" ] || [ "$MEDIA_TYPE" = "REEL" ] && METRICS="${METRICS},plays"
+
+RESULT=$(curl -s "https://graph.facebook.com/v21.0/${MEDIA_ID}/insights?metric=${METRICS}&period=lifetime" \
+ -H "Authorization: Bearer ${META_TOKEN}")
+
+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+echo " INSTAGRAM POST INSIGHTS — ${MEDIA_ID}"
+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+echo ""
+echo "$RESULT" | jq -r '.data[]? | " \(.name): \(.values[0].value)"' 2>/dev/null || \
+ echo "No insights data — account must have >1,000 followers for insights access."
+```
+
+### account-insights [days]
+
+Account-level reach and impressions. Default: last 7 days.
+
+```bash
+DAYS="${DAYS:-7}"
+END_DATE=$(date +%Y-%m-%d)
+START_DATE=$(date -v-${DAYS}d +%Y-%m-%d 2>/dev/null || date -d "${DAYS} days ago" +%Y-%m-%d)
+
+RESULT=$(curl -s "https://graph.facebook.com/v21.0/${IG_ACCOUNT_ID}/insights?metric=reach,impressions,profile_views&period=day&since=${START_DATE}&until=${END_DATE}" \
+ -H "Authorization: Bearer ${META_TOKEN}")
+
+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+echo " INSTAGRAM ACCOUNT INSIGHTS — Last ${DAYS} Days"
+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+echo " Note: Data reflects 24-48h reporting delay"
+echo ""
+
+REACH=$(echo "$RESULT" | jq '[.data[]? | select(.name == "reach") | .values[]?.value | tonumber] | add // 0')
+IMPRESSIONS=$(echo "$RESULT" | jq '[.data[]? | select(.name == "impressions") | .values[]?.value | tonumber] | add // 0')
+PROFILE_VIEWS=$(echo "$RESULT" | jq '[.data[]? | select(.name == "profile_views") | .values[]?.value | tonumber] | add // 0')
+
+echo " Reach: ${REACH}"
+echo " Impressions: ${IMPRESSIONS}"
+echo " Profile Views: ${PROFILE_VIEWS}"
+```
+
+### demographics
+
+Audience breakdown by age/gender and top locations. Requires lifetime period (48h delay).
+
+```bash
+RESULT=$(curl -s "https://graph.facebook.com/v21.0/${IG_ACCOUNT_ID}/insights?metric=audience_gender_age,audience_city,audience_country&period=lifetime" \
+ -H "Authorization: Bearer ${META_TOKEN}")
+
+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+echo " INSTAGRAM DEMOGRAPHICS"
+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+echo " Note: Top 45 segments shown. Data has 48h delay."
+echo ""
+
+echo "AGE / GENDER BREAKDOWN:"
+echo "$RESULT" | jq -r '.data[]? | select(.name == "audience_gender_age") | .values[0].value | to_entries[] | " \(.key): \(.value)%"' 2>/dev/null | head -20
+
+echo ""
+echo "TOP CITIES:"
+echo "$RESULT" | jq -r '.data[]? | select(.name == "audience_city") | .values[0].value | to_entries | sort_by(-.value) | .[0:10][] | " \(.key): \(.value)%"' 2>/dev/null
+
+echo ""
+echo "TOP COUNTRIES:"
+echo "$RESULT" | jq -r '.data[]? | select(.name == "audience_country") | .values[0].value | to_entries | sort_by(-.value) | .[0:10][] | " \(.key): \(.value)%"' 2>/dev/null
+```
+
+---
+
## google-ads
**Credential check**: If `GADS_DEV_TOKEN` or `GADS_REFRESH_TOKEN` is empty after resolution, print:
@@ -994,12 +1787,33 @@ Print: `✓ Keyword bid updated to $X.XX`
## campaigns
-Cross-channel campaign overview — unified view of active campaigns across all configured channels.
+Cross-channel campaign overview — unified view of active campaigns across all configured channels (Klaviyo, Meta Ads, Google Ads).
Run in parallel:
1. Klaviyo active campaigns (status: draft + scheduled + sending)
-2. Meta Ads active campaigns (status: ACTIVE)
-3. Show GA4 conversion goals if available
+2. Meta Ads active campaigns (status ACTIVE) — reuse `META_TOKEN` / `META_ACCOUNT`
+3. Google Ads active campaigns (status ENABLED) — reuse `GADS_*` credentials if configured
+4. Google Ads: refresh access token first (see Credential Resolution)
+
+```bash
+# Meta Ads campaigns
+META_CAMPAIGNS=$(curl -s "https://graph.facebook.com/v20.0/${META_ACCOUNT}/campaigns?fields=name,status,daily_budget,lifetime_budget,objective&filtering=[{\"field\":\"effective_status\",\"operator\":\"IN\",\"value\":[\"ACTIVE\"]}]" \
+ -H "Authorization: Bearer ${META_TOKEN}" 2>/dev/null)
+
+# Klaviyo campaigns
+KLAVIYO_CAMPAIGNS=$(curl -s "https://a.klaviyo.com/api/campaigns/?filter=equals(messages.channel,'email')&sort=-created_at&page[size]=10" \
+ -H "Authorization: Klaviyo-API-Key ${KLAVIYO_KEY}" \
+ -H "revision: 2024-10-15" 2>/dev/null)
+
+# Google Ads campaigns (if configured)
+GADS_CAMPAIGNS=""
+if [ -n "$GADS_ACCESS_TOKEN" ] && [ "$GADS_ACCESS_TOKEN" != "null" ]; then
+ GADS_CAMPAIGNS=$(curl -s -X POST \
+ "https://googleads.googleapis.com/${GADS_API_VERSION}/customers/${GADS_CUSTOMER_ID}/googleAds:searchStream" \
+ "${GADS_HEADERS[@]}" \
+ --data-binary '{"query": "SELECT campaign.id, campaign.name, campaign.status, campaign_budget.amount_micros, metrics.cost_micros FROM campaign WHERE campaign.status = ENABLED ORDER BY metrics.cost_micros DESC LIMIT 10"}' 2>/dev/null)
+fi
+```
### Output format
```
@@ -1009,13 +1823,112 @@ Run in parallel:
EMAIL (Klaviyo)
[campaign name] [status] [send date or "scheduled for X"]
- PAID (Meta Ads)
+ PAID — META ADS
[campaign name] [status] $[daily_budget]/day [objective]
+ PAID — GOOGLE ADS
+ [campaign name] [status] $[budget]/day $[spend 7d]
+
FLOWS (Always-on automation)
[flow name] [trigger type] [status: live/draft]
```
+For any channel not configured, show `[not configured — /ops:marketing setup]`.
+
+---
+
+## optimize
+
+Cross-platform ad optimization agent. Reads Meta + Google Ads data, computes blended ROAS, and recommends where to shift budget.
+
+Spawn the marketing optimizer agent:
+```
+Agent(prompt="Run the marketing optimizer agent. Read ops-marketing-dash data for Meta Ads and Google Ads spend/conversions/ROAS. Compute blended ROAS across platforms. Identify the highest-ROAS platform. Recommend budget shifts with specific dollar amounts. List top 3 actions by expected impact. Use the marketing-optimizer.md agent instructions.", model="claude-sonnet-4-5")
+```
+
+If Agent Teams are available (`CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1`):
+```
+TeamCreate("optimizer")
+Agent(team_name="optimizer", name="marketing-optimizer", prompt="You are the marketing optimizer. Read ops-marketing-dash pre-gathered data. Compute blended ROAS for Meta + Google. Recommend budget reallocation. Show unified attribution table.")
+```
+
+### Output format
+```
+━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
+ AD OPTIMIZATION REPORT
+━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
+ Blended ROAS: [X]x (Meta: [X]x Google: [X]x)
+ Total Spend: $[X] Total Revenue: $[X]
+
+ RECOMMENDATIONS
+ 1. [Action] Expected impact: [+X% ROAS / +$X revenue]
+ 2. [Action] ...
+ 3. [Action] ...
+
+ BUDGET REALLOCATION
+ Move $[X]/day from [Platform A] → [Platform B]
+ Rationale: [X]x ROAS vs [X]x ROAS
+```
+
+---
+
+## attribution
+
+Unified attribution table showing spend, conversions, revenue, and ROAS side-by-side across all configured platforms.
+
+```bash
+# Gather all platform data in parallel
+# Meta Ads — last 7d
+META_DATA=$(curl -s "https://graph.facebook.com/v20.0/${META_ACCOUNT}/insights?fields=spend,actions,action_values&date_preset=last_7d&level=account" \
+ -H "Authorization: Bearer ${META_TOKEN}" 2>/dev/null)
+META_SPEND=$(echo "$META_DATA" | jq -r '.data[0].spend // "0"')
+META_CONV=$(echo "$META_DATA" | jq '[.data[0].actions[]? | select(.action_type == "purchase") | .value | tonumber] | add // 0' 2>/dev/null)
+META_REV=$(echo "$META_DATA" | jq '[.data[0].action_values[]? | select(.action_type == "purchase") | .value | tonumber] | add // 0' 2>/dev/null)
+META_ROAS=$(awk "BEGIN { if (${META_SPEND:-0} > 0) printf \"%.2f\", ${META_REV:-0} / ${META_SPEND:-1}; else print \"—\" }")
+
+# Google Ads — last 7d
+GADS_DATA=""
+GADS_SPEND="0"; GADS_CONV="0"; GADS_REV="0"; GADS_ROAS="—"
+if [ -n "$GADS_ACCESS_TOKEN" ] && [ "$GADS_ACCESS_TOKEN" != "null" ]; then
+ GADS_DATA=$(curl -s -X POST \
+ "https://googleads.googleapis.com/${GADS_API_VERSION}/customers/${GADS_CUSTOMER_ID}/googleAds:searchStream" \
+ "${GADS_HEADERS[@]}" \
+ --data-binary '{"query": "SELECT metrics.cost_micros, metrics.conversions, metrics.conversions_value FROM customer WHERE segments.date DURING LAST_7_DAYS"}' 2>/dev/null)
+ GADS_SPEND=$(echo "$GADS_DATA" | jq '[.[].results[]?.metrics.costMicros // "0" | tonumber] | add / 1000000 // 0' 2>/dev/null || echo "0")
+ GADS_CONV=$(echo "$GADS_DATA" | jq '[.[].results[]?.metrics.conversions // "0" | tonumber] | add // 0' 2>/dev/null || echo "0")
+ GADS_REV=$(echo "$GADS_DATA" | jq '[.[].results[]?.metrics.conversionsValue // "0" | tonumber] | add // 0' 2>/dev/null || echo "0")
+ GADS_ROAS=$(awk "BEGIN { if (${GADS_SPEND:-0} > 0) printf \"%.2f\", ${GADS_REV:-0} / ${GADS_SPEND:-1}; else print \"—\" }")
+fi
+
+# Klaviyo attributed revenue
+KLAVIYO_REV="—"
+# (Pull from metric aggregates if needed — complex, show as note)
+
+# GA4 conversions + revenue
+GA4_DATA=$(curl -s -X POST "https://analyticsdata.googleapis.com/v1beta/properties/${GA4_PROPERTY}:runReport" \
+ -H "Authorization: Bearer ${GA4_TOKEN}" \
+ -H "Content-Type: application/json" \
+ -d '{"dateRanges": [{"startDate": "7daysAgo", "endDate": "today"}], "metrics": [{"name": "conversions"}, {"name": "totalRevenue"}]}' 2>/dev/null)
+GA4_CONV=$(echo "$GA4_DATA" | jq -r '.rows[0].metricValues[0].value // "—"')
+GA4_REV=$(echo "$GA4_DATA" | jq -r '.rows[0].metricValues[1].value // "—"')
+
+TOTAL_AD_SPEND=$(awk "BEGIN { printf \"%.2f\", ${META_SPEND:-0} + ${GADS_SPEND:-0} }")
+TOTAL_AD_REV=$(awk "BEGIN { printf \"%.2f\", ${META_REV:-0} + ${GADS_REV:-0} }")
+BLENDED_ROAS=$(awk "BEGIN { if (${TOTAL_AD_SPEND:-0} > 0) printf \"%.2f\", ${TOTAL_AD_REV:-0} / ${TOTAL_AD_SPEND:-1}; else print \"—\" }")
+
+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+echo " UNIFIED ATTRIBUTION — Last 7 Days"
+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+printf "| %-14s | %-10s | %-12s | %-12s | %-8s |\n" "Platform" "Spend" "Conversions" "Revenue" "ROAS"
+printf "|%s|%s|%s|%s|%s|\n" "----------------" "------------" "--------------" "--------------" "----------"
+printf "| %-14s | \$%-9s | %-12s | \$%-11s | %-8s |\n" "Meta Ads" "$META_SPEND" "$META_CONV" "$META_REV" "${META_ROAS}x"
+printf "| %-14s | \$%-9s | %-12s | \$%-11s | %-8s |\n" "Google Ads" "$(printf "%.2f" ${GADS_SPEND})" "$GADS_CONV" "$(printf "%.2f" ${GADS_REV})" "${GADS_ROAS}x"
+printf "| %-14s | %-10s | %-12s | %-12s | %-8s |\n" "Klaviyo" "—" "—" "${KLAVIYO_REV}" "—"
+printf "| %-14s | %-10s | %-12s | %-12s | %-8s |\n" "GA4 (organic)" "—" "$GA4_CONV" "\$${GA4_REV}" "—"
+printf "|%s|%s|%s|%s|%s|\n" "----------------" "------------" "--------------" "--------------" "----------"
+printf "| %-14s | \$%-9s | %-12s | \$%-11s | %-8s |\n" "TOTAL (ads)" "$TOTAL_AD_SPEND" "—" "$TOTAL_AD_REV" "${BLENDED_ROAS}x"
+```
+
---
## dashboard (default — no args)
@@ -1035,11 +1948,25 @@ Parse the JSON output and display:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Email (Klaviyo) [N] subs | [X]% open rate | $[X] attributed
Paid (Meta) $[X] spent | [X]x ROAS | [N] purchases
+ Paid (Google) $[X] spent | [X]x ROAS | [N] conversions
Organic (GA4) [N] sessions | [X]% CVR | $[X] revenue
SEO (GSC) [N] clicks | [N] impressions | [X] avg pos
+ Instagram [N] followers | [N] reach (7d)
+━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
+ Marketing Health Score: [N]/100 ([status: Healthy/Warning/Critical])
+ Blended ROAS: [X]x Top channel: [channel]
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
```
+**Marketing Health Score computation** (0-100, shown at bottom of dashboard):
+- Blended ROAS ≥ 3x: +30 pts; 1-3x: +15 pts; < 1x: +0 pts
+- Email open rate ≥ 20%: +20 pts; 10-20%: +10 pts; < 10%: +0 pts
+- Channel diversity (3+ platforms active): +20 pts; 2 platforms: +10 pts; 1: +0 pts
+- GA4 CVR ≥ 2%: +20 pts; 1-2%: +10 pts; < 1%: +0 pts
+- Organic SEO clicks > 1,000/mo: +10 pts; 100-1000: +5 pts; < 100: +0 pts
+
+Status thresholds: ≥70 = Healthy, 40-69 = Warning, < 40 = Critical.
+
For any channel with missing credentials, show `[not configured — /ops:marketing setup]`.
---
diff --git a/claude-ops/skills/ops-whatsapp-biz/SKILL.md b/claude-ops/skills/ops-whatsapp-biz/SKILL.md
new file mode 100644
index 00000000..90699813
--- /dev/null
+++ b/claude-ops/skills/ops-whatsapp-biz/SKILL.md
@@ -0,0 +1,378 @@
+---
+name: ops-whatsapp-biz
+description: WhatsApp Business Cloud API — send approved template messages at scale, manage templates with approval tracking, and integrate product catalogs. Separate from wacli personal WhatsApp.
+argument-hint: "[send-template|list-templates|create-template|check-template|catalog|setup]"
+allowed-tools:
+ - Bash
+ - Read
+ - Write
+ - Grep
+ - AskUserQuestion
+effort: medium
+maxTurns: 30
+---
+
+# OPS ► WHATSAPP BUSINESS
+
+WhatsApp Business Cloud API — distinct from wacli personal WhatsApp.
+
+**Key difference:** This skill uses the WhatsApp Business Cloud API (Meta Graph API) for business-to-customer messaging at scale. `wacli` is for personal WhatsApp messaging. Different credentials, different phone numbers, different use cases.
+
+## Credential Resolution
+
+```bash
+PREFS_PATH="${CLAUDE_PLUGIN_DATA_DIR:-$HOME/.claude/plugins/data/ops-ops-marketplace}/preferences.json"
+
+# WhatsApp Business credentials (separate from wacli personal)
+WABA_TOKEN="${WHATSAPP_BUSINESS_TOKEN:-$(claude plugin config get whatsapp_business_token 2>/dev/null)}"
+WABA_PHONE_ID="${WHATSAPP_PHONE_NUMBER_ID:-$(claude plugin config get whatsapp_phone_number_id 2>/dev/null)}"
+WABA_ACCOUNT_ID="${WHATSAPP_BUSINESS_ACCOUNT_ID:-$(claude plugin config get whatsapp_business_account_id 2>/dev/null)}"
+
+# Doppler fallback
+if [ -z "$WABA_TOKEN" ]; then
+ WABA_TOKEN="$(doppler secrets get WHATSAPP_BUSINESS_TOKEN --plain 2>/dev/null)"
+fi
+if [ -z "$WABA_PHONE_ID" ]; then
+ WABA_PHONE_ID="$(doppler secrets get WHATSAPP_PHONE_NUMBER_ID --plain 2>/dev/null)"
+fi
+if [ -z "$WABA_ACCOUNT_ID" ]; then
+ WABA_ACCOUNT_ID="$(doppler secrets get WHATSAPP_BUSINESS_ACCOUNT_ID --plain 2>/dev/null)"
+fi
+```
+
+**Credential check**: If `WABA_TOKEN` or `WABA_PHONE_ID` is empty, print:
+`WhatsApp Business not configured. Run /ops:whatsapp-biz setup to configure credentials.`
+and stop.
+
+---
+
+## Sub-command Routing
+
+Route `$ARGUMENTS`:
+
+| Input | Action |
+|---|---|
+| (empty), list-templates | List all templates with approval status |
+| send-template | Send an approved template message to one or more recipients |
+| create-template | Guided template creation wizard |
+| check-template \<NAME\> | Poll approval status for a specific template |
+| catalog | View and manage linked product catalog |
+| setup | Configure WhatsApp Business API credentials |
+
+---
+
+## list-templates
+
+List all message templates for the WhatsApp Business Account.
+
+```bash
+RESULT=$(curl -s "https://graph.facebook.com/v20.0/${WABA_ACCOUNT_ID}/message_templates?fields=name,status,category,language,components&limit=50" \
+ -H "Authorization: Bearer ${WABA_TOKEN}")
+
+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+echo " WHATSAPP BUSINESS TEMPLATES"
+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+echo ""
+printf "| %-30s | %-10s | %-12s | %-8s |\n" "Template Name" "Status" "Category" "Language"
+printf "|%s|%s|%s|%s|\n" "--------------------------------" "------------" "--------------" "----------"
+
+echo "$RESULT" | jq -r '.data[]? | [.name, .status, .category, .language] | @tsv' 2>/dev/null | \
+ while IFS=$'\t' read -r name status category language; do
+ STATUS_ICON="○"
+ [ "$status" = "APPROVED" ] && STATUS_ICON="✓"
+ [ "$status" = "REJECTED" ] && STATUS_ICON="✗"
+ [ "$status" = "PENDING" ] && STATUS_ICON="…"
+ printf "| %-30s | %s %-9s | %-12s | %-8s |\n" "${name:0:30}" "$STATUS_ICON" "$status" "${category:0:12}" "$language"
+ done
+
+TOTAL=$(echo "$RESULT" | jq '.data | length // 0')
+APPROVED=$(echo "$RESULT" | jq '[.data[]? | select(.status == "APPROVED")] | length')
+echo ""
+echo "Total: ${TOTAL} templates | Approved: ${APPROVED}"
+echo ""
+echo "Note: Per-template pricing applies since July 2025. Check Meta pricing page for current rates."
+```
+
+---
+
+## send-template
+
+Send an approved template message to one or more recipients.
+
+**Before sending**, collect via AskUserQuestion:
+
+1. Template name (free text — use `list-templates` first to see available)
+2. Recipient phone number(s) — free text (single number or comma-separated list, include country code, e.g. +14155552671)
+
+If template has variables, ask for each parameter value via AskUserQuestion (free text).
+
+**Cost note**: Always display approximate cost before sending. Utility templates: ~$0.005/msg; Marketing: ~$0.025/msg (US rates — varies by country). Show AskUserQuestion to confirm before bulk sends > 10 recipients.
+
+```bash
+# Parse recipients
+IFS=',' read -ra RECIPIENTS <<< "$PHONE_NUMBERS"
+RECIPIENT_COUNT=${#RECIPIENTS[@]}
+
+# For bulk sends > 10, confirm
+if [ $RECIPIENT_COUNT -gt 10 ]; then
+ # AskUserQuestion: "Send to ${RECIPIENT_COUNT} recipients? Estimated cost: ~$$(awk "BEGIN {printf \"%.2f\", $RECIPIENT_COUNT * 0.025}") for marketing templates." options [Send, Cancel]
+ [ "$CONFIRM" = "Cancel" ] && echo "Cancelled." && exit 0
+fi
+
+# Send to each recipient
+SUCCESS=0; FAILED=0
+for PHONE in "${RECIPIENTS[@]}"; do
+ PHONE=$(echo "$PHONE" | tr -d ' ')
+
+ RESP=$(curl -s -X POST "https://graph.facebook.com/v20.0/${WABA_PHONE_ID}/messages" \
+ -H "Authorization: Bearer ${WABA_TOKEN}" \
+ -H "Content-Type: application/json" \
+ -d "{
+ \"messaging_product\": \"whatsapp\",
+ \"to\": \"${PHONE}\",
+ \"type\": \"template\",
+ \"template\": {
+ \"name\": \"${TEMPLATE_NAME}\",
+ \"language\": {\"code\": \"en_US\"},
+ \"components\": ${TEMPLATE_COMPONENTS_JSON:-[]}
+ }
+ }")
+
+ MSG_ID=$(echo "$RESP" | jq -r '.messages[0].id // empty')
+ if [ -n "$MSG_ID" ]; then
+ SUCCESS=$((SUCCESS + 1))
+ else
+ FAILED=$((FAILED + 1))
+ ERR=$(echo "$RESP" | jq -r '.error.message // "unknown error"')
+ echo " Failed for ${PHONE}: ${ERR}"
+ fi
+done
+
+echo ""
+echo "Sent: ${SUCCESS}/${RECIPIENT_COUNT} messages delivered"
+[ $FAILED -gt 0 ] && echo "Failed: ${FAILED} — check phone number format (+country_code + number)"
+```
+
+**Template components format** (build `TEMPLATE_COMPONENTS_JSON` from user input):
+
+For templates with header + body variables:
+```json
+[
+ {
+ "type": "header",
+ "parameters": [{"type": "text", "text": "{{header_value}}"}]
+ },
+ {
+ "type": "body",
+ "parameters": [
+ {"type": "text", "text": "{{var1}}"},
+ {"type": "text", "text": "{{var2}}"}
+ ]
+ }
+]
+```
+
+For templates with no variables: `TEMPLATE_COMPONENTS_JSON=[]`
+
+---
+
+## create-template
+
+Guided template creation wizard.
+
+Step 1 — Collect basic info:
+
+AskUserQuestion: "Template category?" options `[MARKETING, UTILITY, AUTHENTICATION, More...]`
+
+If More: AskUserQuestion: `[AUTHENTICATION, UTILITY, Skip]`
+
+Step 2 — AskUserQuestion: "Template name (lowercase, underscores only, e.g. order_confirmation):" (free text)
+
+Step 3 — AskUserQuestion: "Language?" options `[en_US, en_GB, es, fr]`
+
+Step 4 — Collect body text (free text). Instruct user: "Use {{1}}, {{2}} etc for variables."
+
+Step 5 — AskUserQuestion: "Add a header?" options `[Text header, Image header, No header, Video header]`
+
+Step 6 — AskUserQuestion: "Add call-to-action button?" options `[URL button, Phone button, No button, Quick reply]`
+
+```bash
+# Build components array
+COMPONENTS='[{"type":"BODY","text":"'"${BODY_TEXT}"'"}]'
+
+# Add header if selected
+if [ "$HEADER_TYPE" = "Text header" ]; then
+ HEADER_TEXT_INPUT="..." # collected via AskUserQuestion
+ COMPONENTS=$(echo "$COMPONENTS" | jq '. + [{"type":"HEADER","format":"TEXT","text":"'"${HEADER_TEXT_INPUT}"'"}]')
+elif [ "$HEADER_TYPE" = "Image header" ]; then
+ COMPONENTS=$(echo "$COMPONENTS" | jq '. + [{"type":"HEADER","format":"IMAGE","example":{"header_handle":["<upload_handle>"]}}]')
+fi
+
+# Add button if selected
+if [ "$BUTTON_TYPE" = "URL button" ]; then
+ BUTTON_URL="..." # collected via AskUserQuestion: "Button URL:"
+ BUTTON_TEXT="..." # collected via AskUserQuestion: "Button text:"
+ COMPONENTS=$(echo "$COMPONENTS" | jq '. + [{"type":"BUTTONS","buttons":[{"type":"URL","text":"'"${BUTTON_TEXT}"'","url":"'"${BUTTON_URL}"'"}]}]')
+elif [ "$BUTTON_TYPE" = "Phone button" ]; then
+ BUTTON_PHONE="..." # collected via AskUserQuestion: "Phone number for button:"
+ BUTTON_TEXT="..."
+ COMPONENTS=$(echo "$COMPONENTS" | jq '. + [{"type":"BUTTONS","buttons":[{"type":"PHONE_NUMBER","text":"'"${BUTTON_TEXT}"'","phone_number":"'"${BUTTON_PHONE}"'"}]}]')
+fi
+
+RESP=$(curl -s -X POST "https://graph.facebook.com/v20.0/${WABA_ACCOUNT_ID}/message_templates" \
+ -H "Authorization: Bearer ${WABA_TOKEN}" \
+ -H "Content-Type: application/json" \
+ -d "{
+ \"name\": \"${TEMPLATE_NAME}\",
+ \"category\": \"${CATEGORY}\",
+ \"language\": \"${LANGUAGE}\",
+ \"components\": ${COMPONENTS}
+ }")
+
+TEMPLATE_ID=$(echo "$RESP" | jq -r '.id // empty')
+STATUS=$(echo "$RESP" | jq -r '.status // empty')
+
+if [ -n "$TEMPLATE_ID" ]; then
+ echo "Template submitted (ID: ${TEMPLATE_ID}, status: ${STATUS})."
+ echo "Approval typically takes 24-48 hours. Check status with: /ops:whatsapp-biz check-template ${TEMPLATE_NAME}"
+else
+ echo "Template creation failed: $(echo "$RESP" | jq -r '.error.message // "unknown error"')"
+fi
+```
+
+---
+
+## check-template \<NAME\>
+
+Poll approval status for a specific template by name.
+
+```bash
+TEMPLATE_NAME_ARG=$(echo "$ARGUMENTS" | awk '{print $2}')
+if [ -z "$TEMPLATE_NAME_ARG" ]; then
+ # AskUserQuestion: "Template name to check:" (free text)
+ TEMPLATE_NAME_ARG="$USER_INPUT"
+fi
+
+RESULT=$(curl -s "https://graph.facebook.com/v20.0/${WABA_ACCOUNT_ID}/message_templates?name=${TEMPLATE_NAME_ARG}&fields=name,status,rejected_reason,quality_score" \
+ -H "Authorization: Bearer ${WABA_TOKEN}")
+
+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+echo " TEMPLATE STATUS: ${TEMPLATE_NAME_ARG}"
+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+echo ""
+
+echo "$RESULT" | jq -r '.data[]? | "Status: \(.status)\nQuality: \(.quality_score.score // "N/A")\nRejection reason: \(.rejected_reason // "—")"' 2>/dev/null
+
+STATUS=$(echo "$RESULT" | jq -r '.data[0].status // "NOT_FOUND"')
+case "$STATUS" in
+ APPROVED) echo "Template is ready to use with send-template." ;;
+ REJECTED) echo "Template was rejected. Review the rejection reason and create a revised template." ;;
+ PENDING) echo "Template is pending review (typically 24-48h)." ;;
+ NOT_FOUND) echo "Template '${TEMPLATE_NAME_ARG}' not found. Run list-templates to see available templates." ;;
+esac
+```
+
+---
+
+## catalog
+
+View and manage the product catalog linked to your WhatsApp Business Account.
+
+```bash
+# List linked catalogs
+CATALOGS=$(curl -s "https://graph.facebook.com/v20.0/${WABA_ACCOUNT_ID}?fields=catalog_id" \
+ -H "Authorization: Bearer ${WABA_TOKEN}")
+CATALOG_ID=$(echo "$CATALOGS" | jq -r '.catalog_id // empty')
+
+if [ -z "$CATALOG_ID" ]; then
+ echo "No product catalog linked to this WhatsApp Business Account."
+ echo "To link a catalog: go to Meta Business Manager → Commerce Manager → link your catalog to WhatsApp."
+ exit 0
+fi
+
+# List products in catalog
+PRODUCTS=$(curl -s "https://graph.facebook.com/v20.0/${CATALOG_ID}/products?fields=id,name,retailer_id,price,availability,url&limit=20" \
+ -H "Authorization: Bearer ${WABA_TOKEN}")
+
+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+echo " WHATSAPP PRODUCT CATALOG"
+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+echo "Catalog ID: ${CATALOG_ID}"
+echo ""
+printf "| %-25s | %-12s | %-10s | %-12s |\n" "Product Name" "SKU" "Price" "Availability"
+printf "|%s|%s|%s|%s|\n" "---------------------------" "--------------" "------------" "--------------"
+echo "$PRODUCTS" | jq -r '.data[]? | [.name, (.retailer_id // "—"), (.price // "—"), (.availability // "—")] | @tsv' 2>/dev/null | \
+ while IFS=$'\t' read -r name sku price avail; do
+ printf "| %-25s | %-12s | %-10s | %-12s |\n" "${name:0:25}" "${sku:0:12}" "$price" "$avail"
+ done
+
+PRODUCT_COUNT=$(echo "$PRODUCTS" | jq '.data | length // 0')
+echo ""
+echo "Total products shown: ${PRODUCT_COUNT} (use catalog in message templates with product cards)"
+```
+
+**MM Lite note**: Marketing Messages Lite (AI-optimized sends) is a beta API as of 2026. It is not implemented here — check Meta's developer documentation for current availability and enrollment requirements.
+
+---
+
+## setup
+
+Configure WhatsApp Business API credentials.
+
+**Before asking**, auto-scan for existing credentials:
+
+```bash
+# Scan env vars
+printenv WHATSAPP_BUSINESS_TOKEN WHATSAPP_PHONE_NUMBER_ID WHATSAPP_BUSINESS_ACCOUNT_ID 2>/dev/null
+
+# Scan Doppler
+for proj in $(doppler projects --json 2>/dev/null | jq -r '.[].slug'); do
+ for cfg in dev stg prd; do
+ doppler secrets --project "$proj" --config "$cfg" --json 2>/dev/null | \
+ jq -r --arg p "$proj" --arg c "$cfg" 'to_entries[] | select(.key | test("WHATSAPP_BUSINESS|WHATSAPP_PHONE"; "i")) | "\(.key)=\(.value.computed) (doppler:\($p)/\($c))"'
+ done
+done
+
+# Shell profiles
+grep -h 'WHATSAPP_BUSINESS\|WHATSAPP_PHONE' ~/.zshrc ~/.bashrc ~/.zprofile ~/.envrc 2>/dev/null | grep -v '^#'
+
+# Existing plugin config
+claude plugin config get whatsapp_business_token 2>/dev/null && echo "✓ whatsapp_business_token already configured"
+claude plugin config get whatsapp_phone_number_id 2>/dev/null && echo "✓ whatsapp_phone_number_id already configured"
+claude plugin config get whatsapp_business_account_id 2>/dev/null && echo "✓ whatsapp_business_account_id already configured"
+```
+
+**If credentials not found**, guide user:
+
+1. AskUserQuestion: "Where do you have your WhatsApp Business credentials?" options `[Paste token now, Find in Meta dashboard, Skip]`
+
+**Where to find credentials in Meta:**
+- `WHATSAPP_BUSINESS_TOKEN`: Meta Developer Portal → Your App → WhatsApp → API Setup → Temporary access token (or generate a permanent System User token)
+- `WHATSAPP_PHONE_NUMBER_ID`: Same page → "From" phone number → Phone Number ID
+- `WHATSAPP_BUSINESS_ACCOUNT_ID`: Meta Business Manager → Business Settings → WhatsApp Accounts → Account ID
+
+2. Collect each value via AskUserQuestion (free text):
+ - WhatsApp Business Token
+ - Phone Number ID
+ - Business Account ID (WABA ID)
+
+3. Save via plugin config:
+```bash
+claude plugin config set whatsapp_business_token "$WABA_TOKEN"
+claude plugin config set whatsapp_phone_number_id "$WABA_PHONE_ID"
+claude plugin config set whatsapp_business_account_id "$WABA_ACCOUNT_ID"
+```
+
+4. Smoke test:
+```bash
+TEST=$(curl -s "https://graph.facebook.com/v20.0/${WABA_PHONE_ID}" \
+ -H "Authorization: Bearer ${WABA_TOKEN}")
+NAME=$(echo "$TEST" | jq -r '.display_phone_number // empty')
+if [ -n "$NAME" ]; then
+ echo "WhatsApp Business ✓ connected — Phone: ${NAME}"
+else
+ echo "WhatsApp Business ✗ connection failed: $(echo "$TEST" | jq -r '.error.message // "invalid token or phone ID"')"
+fi
+```
+
+Report: `WhatsApp Business ✓ connected` or `✗ invalid — [error]`.
diff --git a/claude-ops/skills/setup/SKILL.md b/claude-ops/skills/setup/SKILL.md
index 5157a434..f68102de 100644
--- a/claude-ops/skills/setup/SKILL.md
+++ b/claude-ops/skills/setup/SKILL.md
@@ -1851,10 +1851,12 @@ Ask which marketing integrations to configure via two sequential `AskUserQuestio
If user selects `[More...]`, present **second call**:
-| Option | Header | Description |
-| ----------------------- | -------- | --------------------------------------------- |
-| Google Analytics 4 | ga4 | Web analytics — GA4 property ID |
-| Google Search Console | gsc | SEO data — site URL (uses gcloud auth) |
+| Option | Header | Description |
+| --------------------------- | -------- | ------------------------------------------------------ |
+| Google Analytics 4 | ga4 | Web analytics — GA4 property ID |
+| Google Search Console | gsc | SEO data — site URL (uses gcloud auth) |
+| WhatsApp Business API | waba | Template messaging at scale — Business token + IDs |
+| Skip | skip | Done with marketing setup |
Run the selected sub-step(s) below in the order selected.
@@ -2003,6 +2005,38 @@ curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \
"https://searchconsole.googleapis.com/webmasters/v3/sites" | jq '.siteEntry | length'
```
+#### WhatsApp Business API
+
+**Separate from wacli personal WhatsApp.** Used for Business-to-customer template messaging at scale.
+
+Auto-scan for:
+```bash
+printenv WHATSAPP_BUSINESS_TOKEN WHATSAPP_PHONE_NUMBER_ID WHATSAPP_BUSINESS_ACCOUNT_ID 2>/dev/null
+claude plugin config get whatsapp_business_token 2>/dev/null && echo "waba_token: already configured"
+claude plugin config get whatsapp_phone_number_id 2>/dev/null && echo "waba_phone_id: already configured"
+claude plugin config get whatsapp_business_account_id 2>/dev/null && echo "waba_account_id: already configured"
+```
+
+Where to find credentials:
+- `WHATSAPP_BUSINESS_TOKEN`: Meta Developer Portal → Your App → WhatsApp → API Setup → Temporary or System User token
+- `WHATSAPP_PHONE_NUMBER_ID`: Same page → "From" phone number → Phone Number ID
+- `WHATSAPP_BUSINESS_ACCOUNT_ID`: Meta Business Manager → Business Settings → WhatsApp Accounts → ID
+
+Collect each via AskUserQuestion (free text) if not found. Save:
+```bash
+claude plugin config set whatsapp_business_token "$WABA_TOKEN"
+claude plugin config set whatsapp_phone_number_id "$WABA_PHONE_ID"
+claude plugin config set whatsapp_business_account_id "$WABA_ACCOUNT_ID"
+```
+
+Smoke test:
+```bash
+curl -s "https://graph.facebook.com/v20.0/${WABA_PHONE_ID}" \
+ -H "Authorization: Bearer ${WABA_TOKEN}" | jq '.display_phone_number // empty'
+```
+
+If returns phone number: `WhatsApp Business ✓ connected — Phone: <number>`. Else show error.
+
#### Save to preferences
Write to `$PREFS_PATH` (merge):
@@ -2012,7 +2046,8 @@ Write to `$PREFS_PATH` (merge):
"klaviyo": { "api_key": "<pk_...>" },
"meta": { "access_token": "<token>", "ad_account_id": "act_XXXXXXXXXX" },
"ga4": { "property_id": "123456789" },
- "gsc": { "site_url": "https://example.com/" }
+ "gsc": { "site_url": "https://example.com/" },
+ "whatsapp_business": { "phone_number_id": "<ID>", "business_account_id": "<WABA_ID>" }
}
}
```