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
+52 -1
View File
@@ -3,6 +3,7 @@ package web
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"sort"
@@ -177,7 +178,8 @@ func (s *Server) searchSettingsSave(w http.ResponseWriter, r *http.Request) {
clicks, _ := strconv.Atoi(f("min_clicks"))
impr, _ := strconv.Atoi(f("min_impressions"))
pos, _ := strconv.ParseFloat(f("min_positions"), 64)
if err := seo.SaveSettings(s.DB, seo.Settings{MinClicks: clicks, MinPositions: pos, MinImpressions: impr, EmailReport: f("email_report") == "on"}); err != nil {
if err := seo.SaveSettings(s.DB, seo.Settings{MinClicks: clicks, MinPositions: pos, MinImpressions: impr,
EmailReport: f("email_report") == "on", EmailCheck: f("email_check") == "on"}); err != nil {
s.renderSearchSettings(w, r, err.Error())
return
}
@@ -274,6 +276,7 @@ func (s *Server) RunSEO(ctx context.Context) {
cancel()
}
s.weeklyReports(ctx, time.Now())
s.dailyChecks(ctx)
}
s.refreshChanges(ctx)
s.refreshBriefs(ctx)
@@ -362,6 +365,9 @@ func (s *Server) seoCheckPage(w http.ResponseWriter, r *http.Request) {
return
}
data["Check"] = c
if c != nil {
data["Chart"] = newClickChart(c.Days, c.PrevDays)
}
if c != nil && len(c.Moves) > 25 {
data["More"] = len(c.Moves) - 25
c.Moves = c.Moves[:25]
@@ -465,6 +471,51 @@ func (s *Server) weeklyReports(ctx context.Context, now time.Time) {
}
}
func checkEmailedKey(property string) string { return "seo:check-emailed:" + property }
// dailyChecks emails each site's morning check, once for each new day of
// final data, when something really moved and the settings ask for it.
func (s *Server) dailyChecks(ctx context.Context) {
set := seo.LoadSettings(s.DB)
if !set.EmailCheck {
return
}
for _, site := range s.seoSites() {
if site.Property == "" {
continue
}
c, err := seo.MorningCheck(s.DB, site.scope(), set)
if err != nil {
s.Log.Warn("seo: the morning check", "site", site.Property, "err", err)
continue
}
if c == nil {
continue
}
var sent string
_, _ = s.DB.GetJSON(checkEmailedKey(site.Property), &sent)
if sent == c.To {
continue
}
if !c.Quiet() {
mailSet, mb, err := s.mailbox()
if err != nil {
return // email isn't set up: nothing to send with
}
ectx, cancel := context.WithTimeout(ctx, 2*time.Minute)
err = outreach.SendToSelf(ectx, mailSet, mb, fmt.Sprintf("SEO morning check: %s, %d moved", site.URL, len(c.Moves)), c.Text(site.URL), time.Now())
cancel()
if err != nil {
s.Log.Warn("seo: emailing the morning check", "err", err)
continue
}
}
if err := s.DB.PutJSON(checkEmailedKey(site.Property), c.To); err != nil {
s.Log.Warn("seo: noting the morning check was sent", "err", err)
}
}
}
// --- The audit ---
var pageSpeedKey = secretField{"pagespeed", secrets.PageSpeedAPIKey, "PageSpeed Insights API key (optional)",