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
+42
View File
@@ -201,3 +201,45 @@ func TestPlaces(t *testing.T) {
}
}
}
func TestDailyGainsAndOutside(t *testing.T) {
d := openDB(t)
const site = "sc-domain:whey.example"
week(t, d, site, "2026-11-06", row{}, []row{
{"https://whey.example/best/", "best whey", 10, 200, 6},
{"https://whey.example/best/", "whey deals", 4, 100, 9},
{"https://gitea.whey.example/x.sql", "filetype:sql intext:password", 0, 5, 3},
})
week(t, d, site, "2026-11-13", row{}, []row{
{"https://whey.example/best/", "best whey", 15, 300, 5},
{"https://whey.example/best/", "whey price", 2, 40, 12},
{"https://gitea.whey.example/x.sql", "filetype:sql intext:password", 3, 9, 2},
{"https://shop.whey.example/", "whey shop", 1, 9, 2},
})
d.PutJSON(throughKey(site), "2026-11-19")
c, err := MorningCheck(d, NewScope(site, "https://whey.example/"), DefaultSettings)
if err != nil || c == nil {
t.Fatal(c, err)
}
if len(c.Days) != 7 || c.Days[0].Date != "2026-11-13" || c.Days[0].Clicks != 17 || c.Days[6].Clicks != 0 || c.PrevDays[0].Clicks != 14 {
t.Errorf("days: %+v %+v", c.Days, c.PrevDays)
}
if len(c.Gains) != 2 || c.Gains[0].Query != "best whey" || c.Gains[1].Query != "whey price" || !c.Gains[1].New {
t.Errorf("gains: %+v", c.Gains)
}
if len(c.Losses) != 1 || c.Losses[0].Query != "whey deals" || !c.Losses[0].NoData {
t.Errorf("losses: %+v", c.Losses)
}
if len(c.Outside) != 2 || c.Outside[0].Host != "gitea.whey.example" || c.Outside[0].Clicks != 3 || c.Outside[0].Query != "filetype:sql intext:password" {
t.Errorf("outside: %+v", c.Outside)
}
text := c.Text("https://whey.example/")
for _, want := range []string{"Clicks 14 → 17 (+21.4%)", "Not counted: 3 clicks went to gitea.whey.example, most for “filetype:sql intext:password”.", "Searches that lost most clicks", "whey deals"} {
if !strings.Contains(text, want) {
t.Errorf("text lacks %q:\n%s", want, text)
}
}
if Percent(37, 30) != "−18.9%" || Percent(5171, 7876) != "+52.3%" || Percent(0, 5) != "" {
t.Error("Percent")
}
}