8 Commits

Author SHA1 Message Date
b315c51c16 Fix creative analysis language: force Spanish in CREATIVE_SYSTEM prompt
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-29 10:56:35 +02:00
deed1db80e Add deep creative analysis: standalone script, dashboard tab, compact Slack scorecard
- analyze_creatives.py: nuevo script independiente que analiza visualmente todos los
  anuncios activos, detecta fatiga creativa (CTR 3d vs 7d) y compara creatividades
  dentro del mismo adset usando Claude Sonnet con visión
- agent.py: analyze_creative_deep() con métricas de rendimiento + detección de fatiga,
  compare_adset_creatives() para comparativa multi-imagen, fallback de descarga de
  imágenes por lista de URLs, prompts en español
- meta_ads_client.py: get_ads_with_creatives() incluye adset_id, image_url separado de
  thumbnail_url, y video_thumbnail_url via AdVideo.picture para vídeos
- baserow_client.py: get_all_creative_analyses() y get_creative_history_by_ad()
- dashboard.py: nueva pestaña Creatividades con tabla seleccionable, panel lateral con
  thumbnail + análisis + recomendaciones + gráfico de evolución del score
- slack_notifier.py: scorecard compacto (una línea por anuncio con acción breve),
  fix del límite de 50 bloques via flush proactivo antes de cada adset

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-19 12:03:10 +02:00
c46baad502 Fix ad analysis: exclude paused ads, dual 3d/7d window, clearer Slack labels
- meta_ads_client: filter currently-paused ads from analysis (they have
  historic spend in the window but shouldn't get PAUSE recommendations)
- run.py: fetch both 3d and 7d ad metrics; merge cpl_3d/cpl_7d into each ad
- agent.py AD_SYSTEM: base PAUSE on 7d window (more stable for low-volume ads);
  treat high cpl_3d with acceptable cpl_7d as statistical noise
- slack_notifier: campaign header shows yesterday's spend/leads explicitly;
  ad table shows CPL(3d) and CPL(7d) side by side; labels include time period

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-16 16:32:54 +02:00
6ec3342661 Add 3-day/7-day multi-window analysis for trend-based decisions
- Fetch campaign metrics for 1d/3d/7d windows at run start (2 extra API calls total)
- Pass spend_3d/leads_3d/cpl_3d and spend_7d/leads_7d/cpl_7d to Claude decide()
- DECIDE_SYSTEM: decisions based on cpl_3d (primary) vs cpl_7d (trend direction)
- PAUSE rule now uses leads_3d==0 + spend_3d >= 3x max_cpl threshold
- Adset and ad analysis now use 3-day aggregated data (get_period_*_metrics)
- Add get_period_campaign_metrics/adset/ad methods to MetaAdsClient
- Print shows 1d/3d/7d CPL and leads per campaign for easy trend reading
- UNIT_SYSTEM and AD_SYSTEM note data covers last 3 days

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-13 22:48:04 +02:00
8b6ec106ee Fix lead counting, call tracking, pause thresholds, and ABO budget detection
- _count_conversions: prioritize 'lead' over 'lead_grouped' to fix double-counting
  (optimizer was showing 2x actual leads on all campaigns)
- Add call_confirm/contact fallbacks for call-objective campaigns (Vodafone, Lowi)
- PAUSE at campaign level only when leads==0 AND spend >= 3x max_cpl (technical failure)
- Ad-level PAUSE threshold raised from 5€ fixed to 3x max_cpl (context-aware)
- Pass max_cpl to ad analysis so Claude uses the correct campaign target
- Skip INCREASE/REDUCE_BUDGET for ABO campaigns (no campaign-level daily budget)
- Fetch bid config before action save to enable ABO detection pre-Baserow

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-13 21:34:48 +02:00
e5c0c9f6a6 Add ad-level pause actions via Baserow and Slack
- AD_SYSTEM prompt for per-ad PAUSE/MAINTAIN decisions (>5€ spend with 0 leads)
- pause_ad() in MetaAdsClient for individual ad pausing via Meta API
- Ad PAUSE actions saved to Baserow with "ad:{id}" campaign_id prefix
- _ad_action_blocks() in Slack notifier renders pause buttons per ad
- _table_name() strips diacritics (NFKD) for monospace column alignment
- Wider name column (45 chars) in adset/ad tables to reduce truncation
- Guard in _effect_text to suppress "+0% budget adjustment" when no change
- _execute_action handles "ad:" prefix to route pause to correct API method

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-07 21:48:16 +02:00
8fb0b69896 Add Baserow persistence, Slack interactive reports, Streamlit dashboard, and full analysis pipeline
- Migrate from Airtable to Baserow: BaserowClient with snapshots, actions, creatives, logs
- Claude agents (Haiku for decisions/units, Sonnet for creatives) with cost_cap_eur vs CPL comparison
- Slack bot with colored action emojis, effect text before approval buttons, 500-char justifications
- Streamlit dashboard with date-range navigation, campaign drill-down (adsets/ads), Histórico tab
- Approval server (FastAPI + ngrok) for Slack button callbacks
- backfill.py for historical snapshot regeneration with Claude re-analysis
- Margin fix: 0-lead campaigns contribute -spend (not 0) to margin
- CTR fix: Meta returns CTR as percentage already, removed *100
- Parameter fix: pass decision parameter to Slack action for correct budget effect display

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-07 09:30:13 +02:00
92786e94a8 Initial structure: Meta Optimizer
- meta_ads_client.py: Meta Marketing API client (facebook-business SDK)
- agent.py: Claude-powered campaign decision engine
- run.py: main orchestration script
- config.py: environment variables
- .github/workflows/daily.yml: GitHub Actions cron (8am CEST)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-22 12:22:11 +02:00