Expand description
Search-console arithmetic for SERP performance data.
This crate does the small pile of arithmetic that sits between a Search Console export and a decision: click-through rate, impression-weighted average position, position movement between two periods, and a projection of clicks at a different position using a CTR-by-position curve.
§What this crate deliberately does not ship
There is no built-in CTR curve. Published “average CTR by position” tables are
third-party estimates that differ by study, by query intent and by SERP layout, and
baking one in would turn somebody else’s sample into this crate’s constant. So
CtrCurve is something you construct from your own measured data — for example
the impressions and clicks your own Search Console reports at each position. A
projection is then a statement about your own history, not about the internet.
Every function here is pure integer or f64 arithmetic. No I/O, no dependencies.
§Example
use serp_ctr::{ctr, weighted_average_position, PositionRow};
let ctr = ctr(7, 1_000).unwrap();
assert!((ctr - 0.007).abs() < 1e-12);
let rows = vec![
PositionRow { position: 3.0, impressions: 900 },
PositionRow { position: 40.0, impressions: 100 },
];
let avg = weighted_average_position(&rows).unwrap();
assert!((avg - 6.7).abs() < 1e-12);Built for the pipeline behind https://toolsthatrank.com/, which verifies a figure against its source before it ships one.
Structs§
- CtrCurve
- A CTR-by-position curve built from observed data.
- Position
Row - One row of a search-performance export: an average position and the impressions behind it.
- Totals
- Aggregate totals for a set of rows: clicks, impressions and the pooled CTR.
Enums§
- Serp
Error - Errors returned when an input cannot support the requested arithmetic.
Functions§
- ctr
- Click-through rate as a fraction in
0.0..=1.0. - ctr_
percent - Click-through rate expressed in percent, rounded to
decimalsplaces. - page_
of_ position - The SERP page a position falls on, given
per_pageresults per page. - pooled_
totals - Pool
(clicks, impressions)rows into a singleTotals. - position_
gain - Change in position between two periods, positive when the position improved.
- weighted_
average_ position - Impression-weighted average position across many rows.