np-marketing-metrics
v1.0.0
Published
Pure functions for core marketing metrics: ad performance (CTR/CPC/CPM/CPA/CR), ROMI/ROAS, social engagement (ER/ERR), and A/B incrementality testing with statistical significance. Zero dependencies.
Maintainers
Readme
np-marketing-metrics
Pure functions for the core marketing & advertising metrics: ad performance, ROMI/ROAS, social engagement, and A/B incrementality testing with statistical significance. Zero dependencies, Node + browser.
This is the open-source math behind the free marketing engineering calculators at nepolyakov.ru. Functions return plain numbers, so you format them for any locale yourself. Prefer a UI? Use the live tools linked below.
Install
npm install np-marketing-metricsUsage
const { adMetrics, romi, engagement, incrementality } = require('np-marketing-metrics');
// ESM: import { adMetrics } from 'np-marketing-metrics';Ad performance — CTR, CPC, CPM, CPA, CR
Mirror of the ad metrics calculator.
adMetrics({ impressions: 10000, clicks: 200, cost: 4000, conversions: 20 });
// { ctr: 2, cpc: 20, cpm: 400, cpa: 200, cr: 10 }ROMI / ROAS
Mirror of the ROMI calculator.
const r = romi({ visits: 1000, conversions: 50, cost: 10000, revenue: 30000 });
// { romi: 200, roas: 3, cr: 5, drr: 33.33…, profit: 20000, cpa: 200 }
romiVerdict(r.romi); // 'good'Social engagement — ER / ERR
Mirror of the ER & ERR calculator.
engagement({ likes: 80, comments: 15, shares: 3, saves: 2, followers: 1000, reach: 500 });
// { engagement: 100, er: 10, err: 20, viewRate: 50, likeRate: 16, commentRate: 3, ... }
erBenchmark(5000); // { good: 10, low: 5, label: 'норма для 5–10К: 10–20%' }A/B incrementality testing
Mirror of the incrementality / geo-lift calculator. Two-proportion z-test with p-value, confidence interval, incremental conversions and iROAS.
incrementality({ n1: 10000, c1: 600, n2: 10000, c2: 500, confidence: 95, value: 1000, cost: 50000 });
// {
// cr1: 6, cr2: 5, absLift: 1, relLift: 20,
// z: …, pValue: <0.05, significant: true, verdict: 'significant-positive',
// ciLow: …, ciHigh: …, incremental: 100, iroas: 2
// }Statistics helpers normCDF(z) and invNormCDF(p) are also exported.
API summary
| Function | Returns |
| --- | --- |
| adMetrics(input) | { ctr, cpc, cpm, cpa, cr } |
| romi(input) | { romi, roas, cr, drr, profit, cpa } |
| romiVerdict(romi) | 'loss' \| 'break-even' \| 'modest' \| 'good' |
| engagement(input) | { engagement, er, err, erImpressions, viewRate, likeRate, commentRate } |
| erBenchmark(followers) | { good, low, label } \| null |
| incrementality(input) | full z-test result object |
Related
- All marketing engineering tools — live, no-install versions.
- utm-translit — clean UTM links with Cyrillic transliteration, by the same author.
- About the author — Nikolai Polyakov, performance marketing & analytics.
