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:
+27
-4
@@ -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
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"))
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user