SEO: daily clicks chart, top searches, percentages, daily email

- The morning check draws clicks by day, this week over the week before.
- The morning check and the Monday report list the searches that gained
  and lost most clicks (any size; real moves stay on their own list).
- The week's clicks and impressions show their change in percent.
- Settings → Search engines can email the morning check, at most once a
  day, when something really moved. Both emails carry the new lists.
- With a domain property, a line says how many clicks went to its other
  hosts (a shop, a Gitea…) and for which search.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-24 06:55:54 -07:00
co-authored by Claude Opus 5.5
parent 1702fccbcc
commit aeba28b658
13 changed files with 598 additions and 20 deletions
+55
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"math"
"slices"
"strings"
"time"
"supermarket/internal/db"
@@ -16,6 +17,7 @@ type Settings struct {
MinPositions float64 `json:"min_positions"` // or of more than this many positions…
MinImpressions int `json:"min_impressions"` // …on at least this many impressions
EmailReport bool `json:"email_report"`
EmailCheck bool `json:"email_check"` // email the morning check when something really moved
}
// DefaultSettings: the post's thresholds, with impressions raised to 300 as
@@ -73,6 +75,10 @@ type Check struct {
Moves []Move
Settings Settings
Pages, Queries, Total int // how many pages and queries were compared
Days, PrevDays []Day // clicks by day, this week and the week before
Gains, Losses []QueryChange // the searches whose clicks changed most, any size
Outside []Outside // clicks the property sent to its other hosts
}
// Quiet reports that nothing real moved.
@@ -236,6 +242,24 @@ func MorningCheck(d *db.DB, sc Scope, set Settings) (*Check, error) {
c.Moves = append(c.Moves, m)
}
}
if c.Days, err = days(d, sc, from, to); err != nil {
return nil, err
}
if c.PrevDays, err = days(d, sc, pfrom, pto); err != nil {
return nil, err
}
qa, err := queriesIn(d, sc, from, to)
if err != nil {
return nil, err
}
qb, err := queriesIn(d, sc, pfrom, pto)
if err != nil {
return nil, err
}
c.Gains, c.Losses = topQueries(qb, qa, TopChanges)
if c.Outside, err = outside(d, sc, from, to); err != nil {
return nil, err
}
slices.SortStableFunc(c.Moves, func(x, y Move) int {
if dx, dy := abs(x.ClickDelta()), abs(y.ClickDelta()); dx != dy {
return dy - dx
@@ -362,3 +386,34 @@ func change(b, a Numbers) string {
return fmt.Sprintf("%s → %s clicks, %s → %s impressions, position %.1f → %.1f",
Thousands(b.Clicks), Thousands(a.Clicks), Thousands(b.Impressions), Thousands(a.Impressions), b.Position, a.Position)
}
// Text is the morning check as an email.
func (c *Check) Text(siteURL string) string {
var b strings.Builder
fmt.Fprintf(&b, "Morning check for %s: %s to %s, against %s to %s\n\n", siteURL, c.From, c.To, c.PrevFrom, c.PrevTo)
fmt.Fprintf(&b, "Clicks %s → %s%s\n", Thousands(c.Before.Clicks), Thousands(c.After.Clicks), inParens(Percent(c.Before.Clicks, c.After.Clicks)))
fmt.Fprintf(&b, "Impressions %s → %s%s\n", Thousands(c.Before.Impressions), Thousands(c.After.Impressions), inParens(Percent(c.Before.Impressions, c.After.Impressions)))
fmt.Fprintf(&b, "Position %.1f → %.1f\n", c.Before.Position, c.After.Position)
writeOutside(&b, c.Outside)
b.WriteString("\nWhat really moved\n")
if c.Quiet() {
b.WriteString(" Nothing.\n")
}
for _, m := range c.Moves {
what := m.Key
if m.Kind == "query" {
what = "search “" + m.Key + "”"
}
if m.NoData {
fmt.Fprintf(&b, " %s: no data this week (it had %d clicks)\n", what, m.Before.Clicks)
} else {
fmt.Fprintf(&b, " %s: %s\n", what, change(m.Before, m.After))
}
for _, w := range m.Why {
fmt.Fprintf(&b, " %s\n", w)
}
}
b.WriteString("\n")
writeChanges(&b, c.Gains, c.Losses)
return b.String()
}