perf: acortar lookback KPIs y unificar fallback Google warehouse

Quita el suelo de 700 días (basta desde ene-2025) y deja buildGoogleCardsFromDaily solo en ad-creatives-google.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
4Ventures
2026-09-29 09:36:41 +02:00
parent a75f3ae30c
commit 82a910330d
3 changed files with 4 additions and 38 deletions

View File

@@ -20,11 +20,9 @@ import { isAgencyRole, serviceHeaders, supabaseUrl, userRole } from '@/lib/agenc
export const dynamic = 'force-dynamic';
/** Enough history for YoY from Jan 2025 (inclusive). */
const AD_DAILY_LOOKBACK_DAYS = Math.max(
700,
Math.ceil((Date.now() - Date.UTC(2025, 0, 1)) / 86400000) + 14
);
/** Enough history for YoY from Jan 2025 (inclusive). No artificial 700d floor. */
const AD_DAILY_LOOKBACK_DAYS =
Math.ceil((Date.now() - Date.UTC(2025, 0, 1)) / 86400000) + 14;
const AD_DAILY_PAGE = 1000;
async function fetchAdDaily(

View File

@@ -217,7 +217,7 @@ function cardsFromDaily(
}));
}
/** Warehouse-only Google cards (fast path). */
/** Warehouse-only Google cards (fast path for creatives API). */
export function buildGoogleCardsFromDaily(
dailyRows: Parameters<typeof aggregateDailyByAd>[0],
since: string,

View File

@@ -851,38 +851,6 @@ async function fetchMetaCreativeCardsInner(
return { ads: out };
}
/** Google cards from ad_daily only (text fallback). */
export function buildGoogleCardsFromDaily(
dailyRows: Parameters<typeof aggregateDailyByAd>[0],
since: string,
until: string,
limit = 40
): AdCreativeCard[] {
return aggregateDailyByAd(dailyRows, 'google', since, until)
.slice(0, limit)
.map((agg) => ({
platform: 'google' as const,
adId: agg.adId,
adName: agg.adName,
campaignName: agg.campaignName,
spend: Math.round(agg.spend * 100) / 100,
impressions: agg.impressions,
clicks: agg.clicks,
conversions: agg.conversions,
cpl: agg.conversions > 0 ? agg.spend / agg.conversions : null,
mediaType: 'rsa',
thumbnailUrl: '',
imageUrl: '',
headline: agg.adName,
primaryText: agg.campaignName,
headlines: agg.adName ? [agg.adName] : [],
bodies: [],
descriptions: agg.campaignName ? [agg.campaignName] : [],
assets: [],
status: undefined,
}));
}
/**
* Account-level Meta clicks for the period:
* - clicks = todos (Ads Manager)