mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 12:15:23 +02:00
feat: add Detail Level BSR metric to experiments analysis
This commit is contained in:
@@ -783,7 +783,8 @@ export const mergeSalesAndAdsData = (
|
||||
adsData: AdsRecord[],
|
||||
asinMetadataMap?: Map<string, { sku: string; title: string; line: string }>,
|
||||
trafficData?: TrafficRecord[],
|
||||
velocityMap?: Map<string, number>
|
||||
velocityMap?: Map<string, number>,
|
||||
bsrData?: BSRRecord[]
|
||||
): CombinedKPIs[] => {
|
||||
const stringCache: Record<string, string> = {};
|
||||
const getNorm = (s: string) => {
|
||||
@@ -808,6 +809,20 @@ export const mergeSalesAndAdsData = (
|
||||
}
|
||||
}
|
||||
|
||||
// Build BSR lookup map
|
||||
const bsrMap = new Map<string, number>();
|
||||
if (bsrData) {
|
||||
for (let i = 0; i < bsrData.length; i++) {
|
||||
const b = bsrData[i];
|
||||
const year = b.date ? parseInt(b.date.split('-')[0]) : new Date().getFullYear();
|
||||
const country = mapCountryToMarketplace(b.market);
|
||||
const key = `${getNorm(b.asin)}|${getNorm(country)}|${year}|${b.week}`;
|
||||
if (b.detailLevelBSR !== null && b.detailLevelBSR !== undefined) {
|
||||
bsrMap.set(key, b.detailLevelBSR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 1. Initialize metadata lookup map with provided global map if available, otherwise build from current sales
|
||||
const asinMetadata = asinMetadataMap || new Map<string, { sku: string; title: string; line: string }>();
|
||||
|
||||
@@ -942,6 +957,7 @@ export const mergeSalesAndAdsData = (
|
||||
cpc,
|
||||
cvrUnits,
|
||||
glanceViews: trafficMap.get(key) || 0,
|
||||
detailLevelBSR: bsrMap.get(key),
|
||||
avgWeeklySales
|
||||
});
|
||||
});
|
||||
@@ -983,6 +999,7 @@ export const mergeSalesAndAdsData = (
|
||||
cpc: ad.clicks > 0 ? ad.cost / ad.clicks : 0,
|
||||
cvrUnits: ad.clicks > 0 ? (ad.attributedUnits30d / ad.clicks) * 100 : 0,
|
||||
glanceViews: trafficMap.get(key) || 0,
|
||||
detailLevelBSR: bsrMap.get(key),
|
||||
avgWeeklySales
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user