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
+27 -4
View File
@@ -8,6 +8,7 @@ import (
"net/url"
"os"
"path/filepath"
"slices"
"strings"
"time"
@@ -218,13 +219,18 @@ type Candidate struct {
Title bool // its title should change
Desc bool // its description should change
Traffic Numbers
// Expected is how many more sign-ups the page would bring in 90 days
// if clicked as usual for its position (0 without conversion data).
Expected float64
}
// Candidates are the pages to propose changes for, best first: the pages to
// push (on page one, not clicked), then audit issues on pages with traffic,
// then audit issues on the rest. Pages with a change in the last 90 days
// are left alone.
func Candidates(d *db.DB, site, property string, now time.Time) ([]Candidate, error) {
func Candidates(d *db.DB, site, property string, conv map[string]PageConv, now time.Time) ([]Candidate, error) {
sc := NewScope(property, site)
sc.Conv = conv
recent := map[string]bool{}
rows, err := d.Query(`SELECT page FROM seo_changes WHERE site = ? AND (created_at >= ? OR status IN ('proposed', 'applying', 'pr', 'merged'))`,
site, now.AddDate(0, 0, -90).UTC().Format(time.RFC3339))
@@ -248,9 +254,9 @@ func Candidates(d *db.DB, site, property string, now time.Time) ([]Candidate, er
out = append(out, c)
}
if property != "" {
if r, err := WhatRanks(d, NewScope(property, site)); err == nil && r != nil {
if r, err := WhatRanks(d, sc); err == nil && r != nil {
for _, p := range r.Push {
add(Candidate{Page: p.Page, Why: p.Why, Title: true, Desc: true, Traffic: p.Numbers})
add(Candidate{Page: p.Page, Why: p.Why, Title: true, Desc: true, Traffic: p.Numbers, Expected: p.Expected})
}
}
}
@@ -276,11 +282,27 @@ func Candidates(d *db.DB, site, property string, now time.Time) ([]Candidate, er
c.Why = is.Title + ". " + is.Detail
if is.Traffic.Impressions > 0 {
c.Why += fmt.Sprintf(" (%s impressions, %s clicks in 90 days)", Thousands(is.Traffic.Impressions), Thousands(is.Traffic.Clicks))
if sc.HasConv() {
c.Expected = sc.Expected(is.Traffic, is.Page)
c.Why += " " + expectedWhy(sc, is.Page, c.Expected)
}
}
add(c)
}
}
}
// With conversion data, the change that would bring most sign-ups first.
if sc.HasConv() {
slices.SortStableFunc(out, func(a, b Candidate) int {
switch {
case a.Expected > b.Expected:
return -1
case a.Expected < b.Expected:
return 1
}
return 0
})
}
return out, nil
}
@@ -321,6 +343,7 @@ type Proposer struct {
AI ai.Client
Profile *profile.Profile
Fetcher *Fetcher
Conv map[string]PageConv // what the site's pages convert, to rank by it
}
var proposalSchema = map[string]any{
@@ -469,7 +492,7 @@ func (pr *Proposer) SuggestChanges(ctx context.Context, d *db.DB, site, property
if waiting >= MaxWaiting {
return 0, fmt.Errorf("%d changes already wait for your yes: decide on those first", waiting)
}
cands, err := Candidates(d, site, property, now)
cands, err := Candidates(d, site, property, pr.Conv, now)
if err != nil {
return 0, err
}
+39
View File
@@ -243,3 +243,42 @@ func TestDailyGainsAndOutside(t *testing.T) {
t.Error("Percent")
}
}
func TestRankedByWhatConverts(t *testing.T) {
d := openDB(t)
const site = "sc-domain:whey.example"
// Two pages on page one, shown a lot, hardly clicked: /big/ is shown
// more, /sells/ turns its visits into sign-ups.
week(t, d, site, "2026-11-13", row{}, []row{
{"https://whey.example/big/", "big", 2, 3000, 5},
{"https://whey.example/sells/", "sells", 1, 1500, 5},
})
d.PutJSON(throughKey(site), "2026-11-19")
sc := NewScope(site, "https://whey.example/")
r, _ := WhatRanks(d, sc)
if len(r.Push) != 2 || r.Push[0].Page != "https://whey.example/big/" {
t.Fatalf("without conversions, by impressions: %+v", r.Push)
}
sc.Conv = map[string]PageConv{
"/big/": {Visitors: 200, Conversions: 0},
"/sells/": {Visitors: 40, Conversions: 8},
"/quiet/": {Visitors: 20, Conversions: 4}, // converts, but Google hardly shows it
"/other/": {Visitors: 60, Conversions: 1},
}
r, _ = WhatRanks(d, sc)
if r.Push[0].Page != "https://whey.example/sells/" || r.Push[0].Expected < r.Push[1].Expected || r.Push[1].Expected != 0 {
t.Errorf("by sign-ups: %+v", r.Push)
}
if !strings.Contains(r.Push[0].Why, "at its own rate of 20.0% of visits") {
t.Errorf("why: %s", r.Push[0].Why)
}
if r.Flags["/big/"] != FlagNoSignups || r.Flags["/quiet/"] != FlagHidden || r.Flags["/other/"] != "" {
t.Errorf("flags: %+v", r.Flags)
}
if len(r.Flagged) != 2 || r.Flagged[0].Path != "/quiet/" {
t.Errorf("flagged: %+v", r.Flagged)
}
if PathKey("https://www.whey.example/Big") != "/big/" || PathKey("https://whey.example") != "/" {
t.Error("PathKey")
}
}
+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"))
}
+46
View File
@@ -53,6 +53,7 @@ type Pick struct {
MainShare float64 // that query's share of the page's impressions, in percent
MainPos float64 // the page's position for it
Why string
Expected float64 // more sign-ups in the period if clicked as usual for its position
}
// Ranks is job 1: what already ranks, over a period.
@@ -65,6 +66,18 @@ type Ranks struct {
Unclicked []QueryRow // shown a lot, almost never clicked
Protect []Pick
Push []Pick
// Flags mark pages by what they convert (by PathKey): FlagNoSignups or
// FlagHidden. Flagged lists them, worst first.
Flags map[string]string
Flagged []Flagged
}
// Flagged is a flagged page, with its numbers.
type Flagged struct {
Path string
Flag string
Conv PageConv
Impressions int
}
// RanksDays is the period job 1 looks at.
@@ -159,6 +172,19 @@ func WhatRanks(d *db.DB, sc Scope) (*Ranks, error) {
}
}
slices.SortStableFunc(cands, func(a, b PageRow) int { return b.Impressions - a.Impressions })
// With conversion data, the page that would bring most sign-ups first.
if sc.HasConv() {
slices.SortStableFunc(cands, func(a, b PageRow) int {
ea, eb := sc.Expected(a.Numbers, a.Page), sc.Expected(b.Numbers, b.Page)
switch {
case ea > eb:
return -1
case ea < eb:
return 1
}
return 0
})
}
for _, p := range cands {
if len(r.Push) == 3 {
break
@@ -171,8 +197,28 @@ func WhatRanks(d *db.DB, sc Scope) (*Ranks, error) {
if pick.MainQuery != "" {
pick.Why += fmt.Sprintf(" %.0f%% of its impressions come from “%s”, where it's at %.1f.", pick.MainShare, pick.MainQuery, pick.MainPos)
}
if sc.HasConv() {
pick.Expected = sc.Expected(p.Numbers, p.Page)
pick.Why += " " + expectedWhy(sc, p.Page, pick.Expected)
}
r.Push = append(r.Push, pick)
}
if sc.HasConv() {
impr := Impressions(pages)
r.Flags = sc.Flags(impr)
for p, f := range r.Flags {
r.Flagged = append(r.Flagged, Flagged{Path: p, Flag: f, Conv: sc.Conv[p], Impressions: impr[p]})
}
slices.SortFunc(r.Flagged, func(a, b Flagged) int {
if a.Flag != b.Flag {
return strings.Compare(a.Flag, b.Flag) // converts, hardly found first
}
if a.Conv.Visitors != b.Conv.Visitors {
return b.Conv.Visitors - a.Conv.Visitors
}
return strings.Compare(a.Path, b.Path)
})
}
return r, nil
}
+3
View File
@@ -12,6 +12,9 @@ import (
type Scope struct {
Property string
Hosts []string // lower case, without www.
// Conv is what the website's pages convert, by PathKey (from
// Plausible); nil when it isn't known.
Conv map[string]PageConv
}
// NewScope is the scope of the website at siteURL within property. Only a
+1
View File
@@ -139,6 +139,7 @@ func (s *Server) seoChangesSuggest(w http.ResponseWriter, r *http.Request) {
if err == nil {
ctx, cancel := context.WithTimeout(r.Context(), 5*time.Minute)
defer cancel()
pr.Conv = s.seoConv(cur.URL)
_, err = pr.SuggestChanges(ctx, s.DB, auditKey(*cur), cur.Property, time.Now())
}
if err != nil {
+24 -6
View File
@@ -90,8 +90,26 @@ type seoSite struct {
Last *seo.SyncResult
}
// scope narrows the site's Search Console property to the website's host.
func (st seoSite) scope() seo.Scope { return seo.NewScope(st.Property, st.URL) }
// scope narrows the site's Search Console property to the website's host,
// with what its pages convert (from Plausible) when that's been read.
func (s *Server) scope(st seoSite) seo.Scope {
sc := seo.NewScope(st.Property, st.URL)
sc.Conv = s.seoConv(st.URL)
return sc
}
// seoConv is a website's page conversions for SEO's ranking.
func (s *Server) seoConv(siteURL string) map[string]seo.PageConv {
pages := s.pageConv(siteURL)
if pages == nil {
return nil
}
out := make(map[string]seo.PageConv, len(pages))
for p, n := range pages {
out[p] = seo.PageConv{Visitors: n.Visitors, Conversions: n.Conversions()}
}
return out
}
func (s *Server) seoSites() []seoSite {
p, _ := profile.Load(s.DB)
@@ -296,7 +314,7 @@ func (s *Server) seoPage(w http.ResponseWriter, r *http.Request) {
data, cur := s.seoBase(r)
data["Path"], data["Days"] = "/seo", seo.RanksDays
if cur != nil {
ranks, err := seo.WhatRanks(s.DB, cur.scope())
ranks, err := seo.WhatRanks(s.DB, s.scope(*cur))
if err != nil {
s.serverError(w, err)
return
@@ -360,7 +378,7 @@ func (s *Server) seoCheckPage(w http.ResponseWriter, r *http.Request) {
data, cur := s.seoBase(r)
data["Path"] = "/seo/check"
if cur != nil {
c, err := seo.MorningCheck(s.DB, cur.scope(), seo.LoadSettings(s.DB))
c, err := seo.MorningCheck(s.DB, s.scope(*cur), seo.LoadSettings(s.DB))
if err != nil {
s.serverError(w, err)
return
@@ -429,7 +447,7 @@ func (s *Server) seoReportWrite(w http.ResponseWriter, r *http.Request) {
// writeReport builds and stores a site's report, and emails it if the
// settings say so (and email is set up).
func (s *Server) writeReport(ctx context.Context, site seoSite, email bool) (*seo.Report, error) {
rep, err := seo.Weekly(s.DB, site.scope(), time.Now())
rep, err := seo.Weekly(s.DB, s.scope(site), time.Now())
if err != nil || rep == nil {
return rep, err
}
@@ -485,7 +503,7 @@ func (s *Server) dailyChecks(ctx context.Context) {
if site.Property == "" {
continue
}
c, err := seo.MorningCheck(s.DB, site.scope(), set)
c, err := seo.MorningCheck(s.DB, s.scope(site), set)
if err != nil {
s.Log.Warn("seo: the morning check", "site", site.Property, "err", err)
continue
+1
View File
@@ -396,6 +396,7 @@ func (s *Server) loadTemplates() error {
"dec1": func(f float64) string { return strconv.FormatFloat(f, 'f', 1, 64) },
"pagePath": pagePath,
"change": seo.Percent,
"flagOf": func(m map[string]string, page string) string { return m[seo.PathKey(page)] },
"conv": func(m map[string]tracking.PageNumbers, page string) tracking.PageNumbers {
return m[tracking.PathOf(page)]
},
+17 -1
View File
@@ -36,11 +36,27 @@
</section>
</div>
{{with .Flagged}}
<section class="card">
<h2>By what they convert</h2>
<p class="help">From the visits that began on each page in the last 90 days and went on to sign up or send a form (what counts is under <a href="/settings/tracking#signups">Settings → Website &amp; sales</a>).</p>
<table class="list">
<thead><tr><th>Page</th><th></th><th class="num">Visits</th><th class="num">Sign-ups</th><th class="num">Impressions</th><th>What to do</th></tr></thead>
<tbody>{{range .}}<tr>
<td>{{.Path}}</td>
<td><span class="badge {{if eq .Flag "converts, hardly found"}}published{{else}}competitor{{end}}">{{.Flag}}</span></td>
<td class="num">{{num .Conv.Visitors}}</td><td class="num">{{num .Conv.Conversions}}</td><td class="num">{{num .Impressions}}</td>
<td class="small">{{if eq .Flag "converts, hardly found"}}It turns visits into sign-ups, but Google hardly shows it: link to it from pages that rank, and look for the searches it should rank for.{{else}}Visitors come, nobody signs up: check what the page asks them to do, and where its button leads.{{end}}</td>
</tr>{{end}}</tbody>
</table>
</section>
{{end}}
<h2>Best pages</h2>
{{if .Pages}}
<table class="list">
<thead><tr><th>Page</th><th class="num">Clicks</th><th class="num">Impressions</th><th class="num">Click rate</th><th class="num">Position</th>{{if $d.Conv}}<th class="num" title="Visits that began on the page, from Plausible">Visits</th><th class="num" title="Visits that began on the page and went on to sign up or send a form">Sign-ups</th>{{end}}</tr></thead>
<tbody>{{range .Pages}}<tr><td><a href="{{.Page}}" target="_blank" rel="noopener noreferrer">{{pagePath .Page}}</a></td><td class="num">{{num .Clicks}}</td><td class="num">{{num .Impressions}}</td><td class="num">{{dec1 .CTR}}%</td><td class="num">{{dec1 .Position}}</td>{{if $d.Conv}}{{with conv $d.Conv .Page}}<td class="num">{{num .Visitors}}</td><td class="num">{{if .Conversions}}<strong>{{num .Conversions}}</strong>{{else}}<span class="muted">0</span>{{end}}</td>{{end}}{{end}}</tr>{{end}}</tbody>
<tbody>{{range .Pages}}<tr><td><a href="{{.Page}}" target="_blank" rel="noopener noreferrer">{{pagePath .Page}}</a>{{with flagOf $d.Ranks.Flags .Page}} <span class="badge {{if eq . "converts, hardly found"}}published{{else}}competitor{{end}}">{{.}}</span>{{end}}</td><td class="num">{{num .Clicks}}</td><td class="num">{{num .Impressions}}</td><td class="num">{{dec1 .CTR}}%</td><td class="num">{{dec1 .Position}}</td>{{if $d.Conv}}{{with conv $d.Conv .Page}}<td class="num">{{num .Visitors}}</td><td class="num">{{if .Conversions}}<strong>{{num .Conversions}}</strong>{{else}}<span class="muted">0</span>{{end}}</td>{{end}}{{end}}</tr>{{end}}</tbody>
</table>
{{else}}<p class="help">No pages with data yet.</p>{{end}}