feat: add Detail Level BSR metric to experiments analysis

This commit is contained in:
Christian Vidal Wolf
2026-03-10 13:58:44 +01:00
parent 2363982144
commit c15642d62d
7 changed files with 70 additions and 24 deletions
+18 -1
View File
@@ -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
});
}