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:
@@ -2,6 +2,7 @@
|
||||
|
||||
import { resolveMetaAccessToken } from '@/lib/ads-discovery';
|
||||
import { serviceHeaders, supabaseUrl } from '@/lib/agency';
|
||||
import { leadFromMetaActions } from '@/lib/meta-leads';
|
||||
|
||||
const META_GRAPH = 'https://graph.facebook.com/v21.0';
|
||||
|
||||
@@ -434,18 +435,9 @@ async function fetchMetaAdLevelInsights(
|
||||
for (const row of raw.data || []) {
|
||||
const adId = str(row.ad_id);
|
||||
if (!adId) continue;
|
||||
let conversions = 0;
|
||||
for (const a of row.actions || []) {
|
||||
const t = (a.action_type || '').toLowerCase();
|
||||
if (
|
||||
t === 'offsite_conversion.fb_pixel_complete_registration' ||
|
||||
t === 'lead' ||
|
||||
t === 'onsite_conversion.lead_grouped' ||
|
||||
t.includes('complete_registration')
|
||||
) {
|
||||
conversions += n(a.value);
|
||||
}
|
||||
}
|
||||
// Same metric as ad_daily / Ads Manager «Clientes potenciales»
|
||||
// (do not sum lead + lead_grouped + registration — they overlap ~3×).
|
||||
const conversions = leadFromMetaActions(row.actions);
|
||||
out.push({
|
||||
adId,
|
||||
adName: str(row.ad_name),
|
||||
|
||||
Reference in New Issue
Block a user