3 Commits

Author SHA1 Message Date
0016809ece Fix creative-analysis JSON truncation bug; add Meta/Airtable split to dashboard
- analyze_creative_deep was truncating mid-JSON ~50-75% of the time
  (max_tokens=700 too low once the analysis text runs long), silently
  falling back to score=0/"Error parseando respuesta." Confirmed via
  stop_reason=max_tokens on real API calls. Raised to 1400, and bumped
  analyze_creative/compare_adset_creatives (600→900) as the same risk
  applies there. Verified 6/6 clean parses after the fix (was failing
  ~3/4 before).
- Dashboard tabs "Campañas", "Familias", and the per-day breakdown in
  "Por día" still showed a single Meta-only Leads/CPL number; added the
  Leads/CPL según Airtable (leadform+landing) columns alongside, matching
  the Slack report so the dashboard never shows a different figure than
  what's already trusted from the daily report.
- Validated both end-to-end with real data: dashboard via Streamlit's
  AppTest headless runner (0 exceptions across all 5 tabs), creative
  analyzer via a live run against one campaign (real scores, fatigue
  detection, comparison, Baserow save, Slack send all confirmed).
2026-07-09 16:47:13 +02:00
769d86c896 Unified Formación report: leadform+landing leads, AT/Meta daily table, per-curso contrast, strategic diagnosis
- Broaden Airtable lead counting to attr_utm_source IN ('Lead ads','landingpage')
  — the 'landingpage' leads (100% fbclid, 0% gclid) were being missed entirely,
  undercounting real leads for '_web' suffixed campaigns and skewing
  capping/pacing decisions since yesterday's first production run.
- Add airtable_client.get_meta_leads_bulk() for day/curso-level aggregation.
- Drop per-familia Slack sectioning in favor of a single Formación block,
  chunked by campaign batches instead.
- Add daily AT-vs-Meta table, per-curso PPL/CPL contrast table (leadform vs
  landing breakdown), and a Claude-generated portfolio strategic diagnosis
  (ported from leads-optimizer's portfolio_daily_analysis).
- Persist daily aggregate totals to a new Baserow table (daily_metrics) so
  the dashboard and future reports don't depend on Meta's historical API
  access remaining available indefinitely.
- Surface adset/ad-level recommendations in the campaign cards instead of
  only numeric tables.
2026-07-09 11:02:19 +02:00
9239e2f67f Initial scaffold: Meta Optimizer for RoiFormacion campaigns
Ports meta-optimizer's Meta Ads execution/approval/creative-analysis layer
(agent.py, meta_ads_client.py, baserow_client.py, slack_notifier.py,
approval_server.py) and replaces the per-vertical CPL model with the
PPL + monthly-capping-per-course model already used by leads-optimizer,
via a new airtable_client.py that shares Cursos/Familias/CentroCurso/
CursoMes/Leads Lake with that project and adds Meta Ads Campaigns /
MetaCampaignMes alongside its Google Ads Campaigns / GACampaignMes.
2026-07-07 16:53:03 +02:00