Phase 7 part 2: ranked by what converts

Push pages and change candidates are ordered by the sign-ups a page
would bring if clicked as usual for its position (impressions × the
clicks it misses × its sign-up rate, or the site's), and say so. What
ranks flags pages by what they convert: traffic with no sign-ups, and
pages that convert but Google hardly shows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-24 07:11:16 -07:00
co-authored by Claude Opus 5.5
parent e9871082b5
commit 77f6e1e1d1
9 changed files with 325 additions and 11 deletions
+167
View File
@@ -0,0 +1,167 @@
package seo
import (
"fmt"
"math"
"net/url"
"slices"
"strings"
)
// What the website's pages turn visits into, from Plausible (the tracking
// package reads it), so suggestions can rank by sign-ups, not by
// impressions alone.
// PageConv is a page's visits, and the visits that went on to sign up or
// send a form, over the same 90 days What ranks covers.
type PageConv struct {
Visitors int
Conversions int
}
// Thresholds for the page rates and flags.
const (
minVisitsForRate = 30 // fewer visits than this: the site's rate is used
noSignupsVisits = 100 // this many visits and no sign-up: flagged
hiddenMaxImpr = 300 // converts well, but shown less than this: flagged
hiddenMinVisits = 10
)
// Flags for pages.
const (
FlagNoSignups = "traffic, no sign-ups"
FlagHidden = "converts, hardly found"
)
// PathKey is the key Conv uses for a page's address: its path in lower
// case, with a trailing slash. Same as the tracking package's.
func PathKey(page string) string {
p := page
if u, err := url.Parse(page); err == nil && u.Path != "" {
p = u.Path
} else if err == nil && u.Host != "" {
p = "/"
}
p = strings.ToLower(strings.TrimSuffix(p, "index.html"))
if !strings.HasSuffix(p, "/") {
p += "/"
}
if !strings.HasPrefix(p, "/") {
p = "/" + p
}
return p
}
// HasConv says whether the scope knows what pages convert.
func (s Scope) HasConv() bool {
t := s.siteConv()
return t.Visitors > 0
}
func (s Scope) siteConv() PageConv {
var t PageConv
for _, c := range s.Conv {
t.Visitors += c.Visitors
t.Conversions += c.Conversions
}
return t
}
// Rate is the share of a page's visits that sign up: its own with enough
// visits, else the site's. own says which.
func (s Scope) Rate(page string) (rate float64, own bool) {
if c, ok := s.Conv[PathKey(page)]; ok && c.Visitors >= minVisitsForRate {
return float64(c.Conversions) / float64(c.Visitors), true
}
if t := s.siteConv(); t.Visitors > 0 {
return float64(t.Conversions) / float64(t.Visitors), false
}
return 0, false
}
// ctrAt is the share of searchers who click a result at a position, on
// page one: the usual curve, rounded. Past page one, 1%.
func ctrAt(pos float64) float64 {
curve := []float64{0.28, 0.15, 0.11, 0.08, 0.07, 0.05, 0.04, 0.03, 0.025, 0.02}
i := int(math.Round(pos)) - 1
switch {
case i < 0:
return curve[0]
case i < len(curve):
return curve[i]
}
return 0.01
}
// Expected is how many more sign-ups a page would bring in the period if
// it were clicked as often as a result at its position usually is: the
// clicks it misses, times its sign-up rate. 0 without conversion data.
func (s Scope) Expected(n Numbers, page string) float64 {
rate, _ := s.Rate(page)
if rate == 0 || n.Impressions == 0 {
return 0
}
missed := float64(n.Impressions)*ctrAt(n.Position) - float64(n.Clicks)
return math.Max(0, missed) * rate
}
// Flags marks the pages worth a look for what they convert: visited a lot
// with no sign-up, or converting well but hardly shown by Google (by
// impressions per path over the same period).
func (s Scope) Flags(impressions map[string]int) map[string]string {
out := map[string]string{}
var rates []float64
for _, c := range s.Conv {
if c.Visitors >= hiddenMinVisits && c.Conversions > 0 {
rates = append(rates, float64(c.Conversions)/float64(c.Visitors))
}
}
slices.Sort(rates)
top := math.Inf(1)
if len(rates) > 0 {
top = rates[len(rates)*3/4] // the top quarter starts here
}
for p, c := range s.Conv {
switch {
case c.Visitors >= noSignupsVisits && c.Conversions == 0:
out[p] = FlagNoSignups
case c.Visitors >= hiddenMinVisits && c.Conversions > 0 && float64(c.Conversions)/float64(c.Visitors) >= top && impressions[p] < hiddenMaxImpr:
out[p] = FlagHidden
}
}
return out
}
// Impressions sums a period's impressions by path (a page on www. and off
// it counts once).
func Impressions(rows []PageRow) map[string]int {
out := map[string]int{}
for _, r := range rows {
out[PathKey(r.Page)] += r.Impressions
}
return out
}
// expectedWhy says what a page is worth in sign-ups, and on what rate.
func expectedWhy(sc Scope, page string, expected float64) string {
rate, own := sc.Rate(page)
whose := "the site's"
if own {
whose = "its own"
}
if rate == 0 {
return "Nobody signed up from the site in this period, so its worth in sign-ups is unknown."
}
return fmt.Sprintf("Clicked as usual for its position, it would bring %s in 90 days (at %s rate of %.1f%% of visits).",
moreSignups(expected), whose, 100*rate)
}
// moreSignups rounds an estimate for reading: "less than one more
// sign-up", "about 1 more sign-up", "about 12 more sign-ups".
func moreSignups(x float64) string {
if x < 0.5 {
return "less than one more sign-up"
}
n := int(math.Round(x))
return fmt.Sprintf("about %d more %s", n, plural(n, "sign-up", "sign-ups"))
}