Wildberries API TypeScript SDK / computeROAS
Function: computeROAS()
ts
function computeROAS(stats:
| FullStatsItem
| DaysV3Item[], options?: ComputeROASOptions): ROASResult;Defined in: utils/roas.ts:80
Compute ROAS (Return on Ad Spend) from WB fullstats per-day data.
Semantics (confirmed empirically against a live cabinet, task-136 AC#1):
sum= ad spend (Затраты, RUB) — proportional toclicks × cpc, same-day.sum_price= order revenue (Сумма заказов, RUB) — attributed to the click day.
ROAS = Σ(sum_price) / Σ(sum) over a rolling window.
Why exclude the freshest day: WB's sum_price finalization lags ~1-2 days, so the most recent day undercounts revenue → same-day ROAS is a known footgun (Q6). The default excludeLastDays: 1 drops it. (0-rev-on-clicked-days is mostly genuine zero-conversion, not lag — but the freshest day is where the undercount concentrates.)
Parameters
| Parameter | Type | Description |
|---|---|---|
stats | | FullStatsItem | DaysV3Item[] | Either a FullStatsItem (uses its .days) or a DaysV3Item[] directly (e.g. FullStatsItem.days). |
options? | ComputeROASOptions | ComputeROASOptions. |
Returns
ROASResult. roas is null when spend === 0 (no ad spend) or when the window is empty.
See
PromotionModule.getAdvFullstats for the source data.
Example
typescript
const stats = await sdk.promotion.getAdvFullstats({
ids: '36508180',
beginDate: '2026-06-28',
endDate: '2026-07-11',
});
const { roas, revenue, spend } = computeROAS(stats); // default: exclude freshest 1 day
if (roas !== null) {
console.log(`ROAS ${roas.toFixed(2)}x (spent ${spend} RUB, earned ${revenue} RUB)`);
}