fix: Ads Meta conv/CPL = Clientes potenciales (sin sumar acciones solapadas)

Las creatividades inflaban ~3× al sumar lead + lead_grouped + registration.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
4Ventures
2026-09-28 18:32:51 +02:00
parent 990915a051
commit 6d8dfaa79c
4 changed files with 36 additions and 30 deletions

20
src/lib/meta-leads.ts Normal file
View File

@@ -0,0 +1,20 @@
/** Meta Ads «Clientes potenciales» ↔ platform_leads (same metric as Ads Manager). */
export function nMeta(v: unknown): number {
const x = Number(v);
return Number.isFinite(x) ? x : 0;
}
/**
* Exact Ads Manager «Clientes potenciales» for Meta Leads CRM campaigns.
* Do not sum lead / lead_grouped / pixel — those overlap and inflate totals.
*/
export function leadFromMetaActions(
actions?: { action_type?: string; value?: string }[]
): number {
if (!actions?.length) return 0;
const primary = actions.find(
(a) => a.action_type === 'offsite_complete_registration_add_meta_leads'
);
return primary ? nMeta(primary.value) : 0;
}