mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 13:35:24 +02:00
fix(parser): prevent regex collision where /sale/i matched ACOS column instead of attributed sales
The generic regex /sale/i in ads column detection was matching "Advertising Cost of Sales" (the ACOS % column) before reaching "7 day total sales" (the actual attributed sales amount). This caused attributedSales30d to receive the ACOS percentage instead of the real sales value, making experiment ACOS = 0 or 100%. - Replace /sale/i with specific regexes: /\d+\s*day.*sale/i, /total\s+sale/i, etc. - Replace /cost/i with regexes that exclude "cost of sales" columns - Replace /unit/i with specific regexes for unit columns - Add diagnostic logging for ads Excel column headers and first-row values - Revert ACOS 100% fallback (root cause now fixed) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
8b774ae7ba
commit
5dfcdd71c0
@@ -110,7 +110,7 @@ function getMetricValue(w: ComputedWeeklyMetrics, metric: string): number {
|
||||
case 'ctr': return w.ctr;
|
||||
case 'roas': return w.roas;
|
||||
case 'revenue': return w.revenue;
|
||||
case 'acos': return w.cost > 0 ? (w.adRevenue > 0 ? (w.cost / w.adRevenue) * 100 : 100) : 0;
|
||||
case 'acos': return w.cost > 0 && w.adRevenue > 0 ? (w.cost / w.adRevenue) * 100 : 0;
|
||||
default: return w.units;
|
||||
}
|
||||
}
|
||||
@@ -173,8 +173,7 @@ function avgMetric(data: ComputedWeeklyMetrics[], metric: string, durationWeeks:
|
||||
if (metric === 'acos') {
|
||||
const totalAdRevenue = data.reduce((s, w) => s + w.adRevenue, 0);
|
||||
const totalCost = data.reduce((s, w) => s + w.cost, 0);
|
||||
if (totalCost === 0) return 0; // No ad spend → ACOS is 0
|
||||
return totalAdRevenue > 0 ? (totalCost / totalAdRevenue) * 100 : 100; // Cost but no ad revenue → 100% ACOS
|
||||
return totalAdRevenue > 0 && totalCost > 0 ? (totalCost / totalAdRevenue) * 100 : 0;
|
||||
}
|
||||
|
||||
// For absolute quantities (units, revenue, sessions), we sum them and divide by the duration
|
||||
|
||||
Reference in New Issue
Block a user