mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 12:35:24 +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)
|
// 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>();
|
const adsSpendMap = new Map<string, number>();
|
||||||
adsData.forEach(r => {
|
adsData.forEach(r => {
|
||||||
const asin = r.asin.trim().toUpperCase();
|
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
|
// 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,
|
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) => {
|
adsSpendMap.forEach((spend, asin) => {
|
||||||
if (!metaMap.has(asin) && spend > 0) {
|
if (!metaMap.has(asin) && spend > 0) {
|
||||||
products.push({
|
products.push({
|
||||||
id: asin,
|
id: asin || '__unassigned__',
|
||||||
asin,
|
asin: asin || '—',
|
||||||
sku: '',
|
sku: '',
|
||||||
name: asin,
|
name: asin ? asin : 'Unassigned Ad Spend',
|
||||||
image: '',
|
image: '',
|
||||||
category: 'Other',
|
category: 'Other',
|
||||||
brand: '',
|
brand: '',
|
||||||
grossSales: 0,
|
grossSales: 0,
|
||||||
unitsSold: 0,
|
unitsSold: 0,
|
||||||
ppcSpend: spend,
|
ppcSpend: spend,
|
||||||
deals: getDeals(asin),
|
deals: asin ? getDeals(asin) : 0,
|
||||||
promos: getPromos(asin),
|
promos: asin ? getPromos(asin) : 0,
|
||||||
chargebacks: getChargebacks(asin),
|
chargebacks: asin ? getChargebacks(asin) : 0,
|
||||||
chargebacksPrevMonth: 0,
|
chargebacksPrevMonth: 0,
|
||||||
cogs: 0,
|
cogs: 0,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user