fix(parser): align ad sales and units regexes to capture standard Amazon header 'Sales within X days'

This commit is contained in:
Christian Vidal Wolf
2026-02-26 08:30:23 +01:00
parent bd85229def
commit 21ec5b63ab
2 changed files with 13 additions and 8 deletions
+9 -4
View File
@@ -473,10 +473,15 @@ const Dashboard: React.FC<DashboardProps> = ({ data, contextData, adsData = [] }
yearMap.set(y, { cost: 0, attributedSales: 0, clicks: 0, impressions: 0 }); yearMap.set(y, { cost: 0, attributedSales: 0, clicks: 0, impressions: 0 });
} }
const t = yearMap.get(y)!; const t = yearMap.get(y)!;
t.cost += ad.cost;
t.attributedSales += ad.attributedSales30d; if (t.cost === 0 && ad.cost > 0) {
t.clicks += ad.clicks; console.log("DASHBOARD AD RECORD:", ad);
t.impressions += ad.impressions; }
t.cost += ad.cost || 0;
t.attributedSales += ad.attributedSales30d || ad.salesAds || 0;
t.clicks += ad.clicks || 0;
t.impressions += ad.impressions || 0;
}); });
const result: Record<string, { totalSpend: number; attributedSales: number; acos: number; roas: number; cpc: number; ctr: number }> = {}; const result: Record<string, { totalSpend: number; attributedSales: number; acos: number; roas: number; cpc: number; ctr: number }> = {};
+4 -4
View File
@@ -455,8 +455,8 @@ export const processAdsCSV = (file: File): Promise<AdsRecord[]> => {
const ctrRaw = getColumnValue(row, ['ctr', 'click-through rate', 'click-through-rate', 'click through rate', /click.*through.*rate/i, /ctr/i]); const ctrRaw = getColumnValue(row, ['ctr', 'click-through rate', 'click-through-rate', 'click through rate', /click.*through.*rate/i, /ctr/i]);
const acosRaw = getColumnValue(row, ['acos', 'advertising cost of sales', 'aCOS', /cost.*of.*sales/i, /acos/i]); const acosRaw = getColumnValue(row, ['acos', 'advertising cost of sales', 'aCOS', /cost.*of.*sales/i, /acos/i]);
const conversionsRaw = getColumnValue(row, ['conversions', 'konversionen', 'orders', 'pedidos', 'total orders', /order/i, /conversion/i]); const conversionsRaw = getColumnValue(row, ['conversions', 'konversionen', 'orders', 'pedidos', 'total orders', /order/i, /conversion/i]);
const unitsRaw = getColumnValue(row, ['units', 'einheiten', 'unidades', 'units sold', 'total units', /\d+\s*day.*unit/i, /total\s+unit/i, /units?\s*sold/i, /^units?$/i, /einheit/i, /unidad/i]); const unitsRaw = getColumnValue(row, ['units', 'einheiten', 'unidades', 'units sold', 'total units', /\d+\s*day.*unit/i, /unit.*within.*\d+\s*day/i, /total\s+unit/i, /units?\s*sold/i, /^units?$/i, /unit/i, /einheit/i, /unidad/i]);
const salesRaw = getColumnValue(row, ['sales', 'umsatz', 'ventas', 'ad sales', 'total sales', 'sales (30d)', /\d+\s*day.*sale/i, /total\s+sale/i, /attributed.*sale/i, /ad\s+sale/i, /^sales$/i, /umsatz/i, /ventas/i]); const salesRaw = getColumnValue(row, ['sales', 'umsatz', 'ventas', 'ad sales', 'total sales', 'sales (30d)', /\d+\s*day.*sale/i, /sale.*within.*\d+\s*day/i, /total\s+sale/i, /attributed.*sale/i, /ad\s+sale/i, /^sales$/i, /(?<!cost of )sale/i, /umsatz/i, /ventas/i]);
if (!asin || !countryRaw || weekRaw === undefined || weekRaw === '') continue; if (!asin || !countryRaw || weekRaw === undefined || weekRaw === '') continue;
@@ -534,8 +534,8 @@ export const processAdsExcel = async (fileOrBuffer: File | ArrayBuffer): Promise
const ctrRaw = getColumnValue(row, ['ctr', 'click-through rate', 'click-through-rate', 'click through rate', /click.*through.*rate/i, /ctr/i]); const ctrRaw = getColumnValue(row, ['ctr', 'click-through rate', 'click-through-rate', 'click through rate', /click.*through.*rate/i, /ctr/i]);
const acosRaw = getColumnValue(row, ['acos', 'advertising cost of sales', 'aCOS', /cost.*of.*sales/i, /acos/i]); const acosRaw = getColumnValue(row, ['acos', 'advertising cost of sales', 'aCOS', /cost.*of.*sales/i, /acos/i]);
const conversionsRaw = getColumnValue(row, ['conversions', 'konversionen', 'orders', 'pedidos', 'total orders', /order/i, /conversion/i]); const conversionsRaw = getColumnValue(row, ['conversions', 'konversionen', 'orders', 'pedidos', 'total orders', /order/i, /conversion/i]);
const unitsRaw = getColumnValue(row, ['units', 'einheiten', 'unidades', 'units sold', 'total units', /\d+\s*day.*unit/i, /total\s+unit/i, /units?\s*sold/i, /^units?$/i, /einheit/i, /unidad/i]); const unitsRaw = getColumnValue(row, ['units', 'einheiten', 'unidades', 'units sold', 'total units', /\d+\s*day.*unit/i, /unit.*within.*\d+\s*day/i, /total\s+unit/i, /units?\s*sold/i, /^units?$/i, /unit/i, /einheit/i, /unidad/i]);
const salesRaw = getColumnValue(row, ['sales', 'umsatz', 'ventas', 'ad sales', 'total sales', 'sales (30d)', /\d+\s*day.*sale/i, /total\s+sale/i, /attributed.*sale/i, /ad\s+sale/i, /^sales$/i, /umsatz/i, /ventas/i]); const salesRaw = getColumnValue(row, ['sales', 'umsatz', 'ventas', 'ad sales', 'total sales', 'sales (30d)', /\d+\s*day.*sale/i, /sale.*within.*\d+\s*day/i, /total\s+sale/i, /attributed.*sale/i, /ad\s+sale/i, /^sales$/i, /(?<!cost of )sale/i, /umsatz/i, /ventas/i]);
// Skip if missing essential data // Skip if missing essential data
if (!asin || !countryRaw || weekRaw === undefined || weekRaw === '') continue; if (!asin || !countryRaw || weekRaw === undefined || weekRaw === '') continue;