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:
+49
-12
@@ -15,15 +15,18 @@ import (
|
||||
|
||||
// Report is the Monday report: one page, the same every week.
|
||||
type Report struct {
|
||||
Site string `json:"site"`
|
||||
WeekFrom string `json:"week_from"`
|
||||
WeekTo string `json:"week_to"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Before Numbers `json:"before"`
|
||||
After Numbers `json:"after"`
|
||||
Where string `json:"where"` // where the change came from, in a sentence
|
||||
Pages []Move `json:"pages"` // the 3 pages that moved most
|
||||
Waiting []Pick `json:"waiting"`
|
||||
Site string `json:"site"`
|
||||
WeekFrom string `json:"week_from"`
|
||||
WeekTo string `json:"week_to"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Before Numbers `json:"before"`
|
||||
After Numbers `json:"after"`
|
||||
Where string `json:"where"` // where the change came from, in a sentence
|
||||
Pages []Move `json:"pages"` // the 3 pages that moved most
|
||||
Waiting []Pick `json:"waiting"`
|
||||
Gains []QueryChange `json:"gains,omitempty"` // searches whose clicks rose most
|
||||
Losses []QueryChange `json:"losses,omitempty"` // and fell most
|
||||
Outside []Outside `json:"outside,omitempty"` // clicks on the property's other hosts
|
||||
// Candidates are the pages worth a proposal, when none is waiting.
|
||||
Candidates []Pick `json:"candidates,omitempty"`
|
||||
}
|
||||
@@ -37,6 +40,7 @@ func Weekly(d *db.DB, sc Scope, now time.Time) (*Report, error) {
|
||||
}
|
||||
r := &Report{Site: sc.Property, WeekFrom: c.From, WeekTo: c.To, CreatedAt: now, Before: c.Before, After: c.After}
|
||||
r.Where = where(c.Before, c.After)
|
||||
r.Gains, r.Losses, r.Outside = c.Gains, c.Losses, c.Outside
|
||||
var pages []Move
|
||||
for _, m := range c.Moves {
|
||||
if m.Kind == "page" && !m.NoData && (m.ClickDelta() != 0 || m.PosDelta() != 0) {
|
||||
@@ -201,10 +205,13 @@ func (r *Report) Text() string {
|
||||
var b strings.Builder
|
||||
fmt.Fprintf(&b, "SEO report for %s, %s to %s (against the week before)\n\n", r.Site, r.WeekFrom, r.WeekTo)
|
||||
b.WriteString("1. The week\n")
|
||||
fmt.Fprintf(&b, " Clicks %s → %s\n", Thousands(r.Before.Clicks), Thousands(r.After.Clicks))
|
||||
fmt.Fprintf(&b, " Impressions %s → %s\n", Thousands(r.Before.Impressions), Thousands(r.After.Impressions))
|
||||
fmt.Fprintf(&b, " Clicks %s → %s%s\n", Thousands(r.Before.Clicks), Thousands(r.After.Clicks), inParens(Percent(r.Before.Clicks, r.After.Clicks)))
|
||||
fmt.Fprintf(&b, " Impressions %s → %s%s\n", Thousands(r.Before.Impressions), Thousands(r.After.Impressions), inParens(Percent(r.Before.Impressions, r.After.Impressions)))
|
||||
fmt.Fprintf(&b, " Position %.1f → %.1f\n", r.Before.Position, r.After.Position)
|
||||
fmt.Fprintf(&b, " %s\n\n", r.Where)
|
||||
fmt.Fprintf(&b, " %s\n", r.Where)
|
||||
writeOutside(&b, r.Outside)
|
||||
b.WriteString("\n")
|
||||
writeChanges(&b, r.Gains, r.Losses)
|
||||
b.WriteString("2. The pages that moved most\n")
|
||||
if len(r.Pages) == 0 {
|
||||
b.WriteString(" None.\n")
|
||||
@@ -230,3 +237,33 @@ func (r *Report) Text() string {
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func inParens(s string) string {
|
||||
if s == "" {
|
||||
return ""
|
||||
}
|
||||
return " (" + s + ")"
|
||||
}
|
||||
|
||||
// writeChanges writes the searches that gained and lost most, for email.
|
||||
func writeChanges(b *strings.Builder, gains, losses []QueryChange) {
|
||||
for _, list := range []struct {
|
||||
title string
|
||||
qs []QueryChange
|
||||
}{{"Searches that gained most clicks", gains}, {"Searches that lost most clicks", losses}} {
|
||||
if len(list.qs) == 0 {
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(b, "%s\n", list.title)
|
||||
for _, q := range list.qs {
|
||||
fmt.Fprintf(b, " %-40s %s\n", q.Query, q.Summary())
|
||||
}
|
||||
b.WriteString("\n")
|
||||
}
|
||||
}
|
||||
|
||||
func writeOutside(b *strings.Builder, out []Outside) {
|
||||
for _, o := range out {
|
||||
fmt.Fprintf(b, " %s\n", o.Sentence())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user