mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 11:05:23 +02:00
fix: include empty-ASIN ad records so MKT total matches ADs Weekly
Removed the `if (asin)` guard so records without a product ASIN (e.g. campaign-level rows) accumulate in adsSpendMap and appear as an 'Unassigned Ad Spend' row, ensuring the total PPC spend is the same as in the ADs Weekly tab. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
36fa63b6c1
commit
910e6d2a4d
@@ -169,10 +169,11 @@ export default function MktDataView({ rawData, adsData }: MktDataViewProps) {
|
||||
});
|
||||
|
||||
// ASIN → global ad spend (all filtered data, no hardcoded year)
|
||||
// Include ALL records (even empty ASIN) so total matches ADs Weekly tab
|
||||
const adsSpendMap = new Map<string, number>();
|
||||
adsData.forEach(r => {
|
||||
const asin = r.asin.trim().toUpperCase();
|
||||
if (asin) adsSpendMap.set(asin, (adsSpendMap.get(asin) || 0) + r.cost);
|
||||
adsSpendMap.set(asin, (adsSpendMap.get(asin) || 0) + r.cost);
|
||||
});
|
||||
|
||||
// Deals/Promos/Chargebacks are 2025-only data — only apply when 2025 is in scope
|
||||
@@ -201,23 +202,23 @@ export default function MktDataView({ rawData, adsData }: MktDataViewProps) {
|
||||
cogs: 0,
|
||||
}));
|
||||
|
||||
// Add ASINs that have ad spend but no sales records (so total matches ADs tab)
|
||||
// Add ASINs (or unassigned spend) that have ad spend but no sales records
|
||||
adsSpendMap.forEach((spend, asin) => {
|
||||
if (!metaMap.has(asin) && spend > 0) {
|
||||
products.push({
|
||||
id: asin,
|
||||
asin,
|
||||
id: asin || '__unassigned__',
|
||||
asin: asin || '—',
|
||||
sku: '',
|
||||
name: asin,
|
||||
name: asin ? asin : 'Unassigned Ad Spend',
|
||||
image: '',
|
||||
category: 'Other',
|
||||
brand: '',
|
||||
grossSales: 0,
|
||||
unitsSold: 0,
|
||||
ppcSpend: spend,
|
||||
deals: getDeals(asin),
|
||||
promos: getPromos(asin),
|
||||
chargebacks: getChargebacks(asin),
|
||||
deals: asin ? getDeals(asin) : 0,
|
||||
promos: asin ? getPromos(asin) : 0,
|
||||
chargebacks: asin ? getChargebacks(asin) : 0,
|
||||
chargebacksPrevMonth: 0,
|
||||
cogs: 0,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user