Fixes from the first round of TEST.md
SEO: a domain property (sc-domain:) covers every subdomain, so the shop, Gitea and forum were counted as the website. What ranks, the morning check, the Monday report, keywords, change candidates and the audit's traffic now read only the website's own host (with or without www). The report keeps pages worth a proposal apart from "Waiting for your yes", explains only moves past the thresholds, and says "places up/down". Also: - Feed summaries drop the posts' scripts and styles. - Spend you log can't be negative. - Test and check buttons can't be clicked twice while they run. - Previews show the site's web fonts and icon sprites. - Backups are read without leaving -wal/-shm files; deleting one removes them, and leftovers are swept at start. - The Overview's setup flags a CRM that Hermes can't reach. - Import now says what came in; adding a prospect that exists says so; prospects can be deleted. - Signal tags and brief addresses keep accented letters (Ü → u). - Page errors start with a capital; clearer messages for bad uploads, CRM retry and cancel, keywords, and the finished audit. - The module you're in stays unfolded in the sidebar. - A picked keyword can be unpicked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+46
-23
@@ -88,11 +88,20 @@ func weeks(d *db.DB, site string) (from, to, prevFrom, prevTo string, ok bool) {
|
||||
return t.AddDate(0, 0, -6).Format(dayFormat), to, t.AddDate(0, 0, -13).Format(dayFormat), t.AddDate(0, 0, -7).Format(dayFormat), true
|
||||
}
|
||||
|
||||
func siteNumbers(d *db.DB, site, from, to string) (Numbers, error) {
|
||||
// siteNumbers are the scope's totals. A whole property has its own daily
|
||||
// totals; a website within one is the sum of its pages.
|
||||
func siteNumbers(d *db.DB, sc Scope, from, to string) (Numbers, error) {
|
||||
var n Numbers
|
||||
var ps float64
|
||||
err := d.QueryRow(`SELECT coalesce(sum(clicks), 0), coalesce(sum(impressions), 0), coalesce(sum(pos_sum), 0)
|
||||
FROM gsc_site_days WHERE site = ? AND date BETWEEN ? AND ?`, site, from, to).Scan(&n.Clicks, &n.Impressions, &ps)
|
||||
var err error
|
||||
if len(sc.Hosts) == 0 {
|
||||
err = d.QueryRow(`SELECT coalesce(sum(clicks), 0), coalesce(sum(impressions), 0), coalesce(sum(pos_sum), 0)
|
||||
FROM gsc_site_days WHERE site = ? AND date BETWEEN ? AND ?`, sc.Property, from, to).Scan(&n.Clicks, &n.Impressions, &ps)
|
||||
} else {
|
||||
cond, args := sc.where()
|
||||
err = d.QueryRow(`SELECT coalesce(sum(clicks), 0), coalesce(sum(impressions), 0), coalesce(sum(pos_sum), 0)
|
||||
FROM gsc_page_days WHERE `+cond+` AND date BETWEEN ? AND ?`, append(args, from, to)...).Scan(&n.Clicks, &n.Impressions, &ps)
|
||||
}
|
||||
n.Position = position(ps, n.Impressions)
|
||||
return n, err
|
||||
}
|
||||
@@ -118,22 +127,23 @@ func grouped(d *db.DB, query string, args ...any) (map[string]Numbers, error) {
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
func pagesIn(d *db.DB, site, from, to string) (map[string]Numbers, error) {
|
||||
func pagesIn(d *db.DB, sc Scope, from, to string) (map[string]Numbers, error) {
|
||||
cond, args := sc.where()
|
||||
return grouped(d, `SELECT page, sum(clicks), sum(impressions), sum(pos_sum) FROM gsc_page_days
|
||||
WHERE site = ? AND date BETWEEN ? AND ? GROUP BY page`, site, from, to)
|
||||
WHERE `+cond+` AND date BETWEEN ? AND ? GROUP BY page`, append(args, from, to)...)
|
||||
}
|
||||
|
||||
func queriesIn(d *db.DB, site, from, to string) (map[string]Numbers, error) {
|
||||
func queriesIn(d *db.DB, sc Scope, from, to string) (map[string]Numbers, error) {
|
||||
cond, args := sc.where()
|
||||
return grouped(d, `SELECT query, sum(clicks), sum(impressions), sum(pos_sum) FROM gsc_query_days
|
||||
WHERE site = ? AND date BETWEEN ? AND ? GROUP BY query`, site, from, to)
|
||||
WHERE `+cond+` AND date BETWEEN ? AND ? GROUP BY query`, append(args, from, to)...)
|
||||
}
|
||||
|
||||
func pageQueriesIn(d *db.DB, site, page, from, to string) (map[string]Numbers, error) {
|
||||
func pageQueriesIn(d *db.DB, sc Scope, page, from, to string) (map[string]Numbers, error) {
|
||||
return grouped(d, `SELECT query, sum(clicks), sum(impressions), sum(pos_sum) FROM gsc_query_days
|
||||
WHERE site = ? AND page = ? AND date BETWEEN ? AND ? GROUP BY query`, site, page, from, to)
|
||||
WHERE site = ? AND page = ? AND date BETWEEN ? AND ? GROUP BY query`, sc.Property, page, from, to)
|
||||
}
|
||||
|
||||
// real decides whether a change passes the thresholds.
|
||||
func (s Settings) real(before, after Numbers) bool {
|
||||
if abs(after.Clicks-before.Clicks) > s.MinClicks {
|
||||
return true
|
||||
@@ -165,17 +175,17 @@ func abs(n int) int {
|
||||
// MorningCheck compares the last 7 days of final data with the 7 before,
|
||||
// by page and by query, and keeps only real moves. It returns nil if there
|
||||
// isn't two weeks of data yet.
|
||||
func MorningCheck(d *db.DB, site string, set Settings) (*Check, error) {
|
||||
from, to, pfrom, pto, ok := weeks(d, site)
|
||||
func MorningCheck(d *db.DB, sc Scope, set Settings) (*Check, error) {
|
||||
from, to, pfrom, pto, ok := weeks(d, sc.Property)
|
||||
if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
c := &Check{Site: site, From: from, To: to, PrevFrom: pfrom, PrevTo: pto, Settings: set}
|
||||
c := &Check{Site: sc.Property, From: from, To: to, PrevFrom: pfrom, PrevTo: pto, Settings: set}
|
||||
var err error
|
||||
if c.After, err = siteNumbers(d, site, from, to); err != nil {
|
||||
if c.After, err = siteNumbers(d, sc, from, to); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if c.Before, err = siteNumbers(d, site, pfrom, pto); err != nil {
|
||||
if c.Before, err = siteNumbers(d, sc, pfrom, pto); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, kind := range []string{"page", "query"} {
|
||||
@@ -183,11 +193,11 @@ func MorningCheck(d *db.DB, site string, set Settings) (*Check, error) {
|
||||
if kind == "query" {
|
||||
load = queriesIn
|
||||
}
|
||||
after, err := load(d, site, from, to)
|
||||
after, err := load(d, sc, from, to)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
before, err := load(d, site, pfrom, pto)
|
||||
before, err := load(d, sc, pfrom, pto)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -219,7 +229,7 @@ func MorningCheck(d *db.DB, site string, set Settings) (*Check, error) {
|
||||
m.Why = append(m.Why, "No row the week before: new in Search Console this week.")
|
||||
}
|
||||
if kind == "page" && hasA && hasB {
|
||||
if err := explainPage(d, site, &m, from, to, pfrom, pto, set); err != nil {
|
||||
if err := explainPage(d, sc, &m, from, to, pfrom, pto, set); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@@ -255,12 +265,12 @@ func MorningCheck(d *db.DB, site string, set Settings) (*Check, error) {
|
||||
// explainPage says what the page's queries show about its move: which
|
||||
// query's clicks changed most, and whether a position change is real or
|
||||
// comes from Google showing it for a different mix of searches.
|
||||
func explainPage(d *db.DB, site string, m *Move, from, to, pfrom, pto string, set Settings) error {
|
||||
after, err := pageQueriesIn(d, site, m.Key, from, to)
|
||||
func explainPage(d *db.DB, sc Scope, m *Move, from, to, pfrom, pto string, set Settings) error {
|
||||
after, err := pageQueriesIn(d, sc, m.Key, from, to)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
before, err := pageQueriesIn(d, site, m.Key, pfrom, pto)
|
||||
before, err := pageQueriesIn(d, sc, m.Key, pfrom, pto)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -302,13 +312,13 @@ func explainPage(d *db.DB, site string, m *Move, from, to, pfrom, pto string, se
|
||||
if w > 0 {
|
||||
like := moved / w
|
||||
if math.Abs(like) < math.Abs(m.PosDelta())/2 {
|
||||
m.Why = append(m.Why, fmt.Sprintf("Like for like it moved %+.1f positions, on the searches it had both weeks. The average moved because Google showed it for a different mix of searches.", like))
|
||||
m.Why = append(m.Why, fmt.Sprintf("Like for like it moved %s, on the searches it had both weeks. The average moved because Google showed it for a different mix of searches.", places(like)))
|
||||
if shift != "" {
|
||||
m.Why = append(m.Why, fmt.Sprintf("Biggest change: “%s”, %s.", shift, change(before[shift], after[shift])))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
m.Why = append(m.Why, fmt.Sprintf("On the searches it had both weeks it moved %+.1f positions: a real move.", like))
|
||||
m.Why = append(m.Why, fmt.Sprintf("On the searches it had both weeks it moved %s: its rankings changed, not just the mix of searches.", places(like)))
|
||||
return nil
|
||||
}
|
||||
if shift != "" {
|
||||
@@ -317,6 +327,19 @@ func explainPage(d *db.DB, site string, m *Move, from, to, pfrom, pto string, se
|
||||
return nil
|
||||
}
|
||||
|
||||
// places says a change in average position in words: a lower position
|
||||
// number is higher up the results.
|
||||
func places(delta float64) string {
|
||||
switch {
|
||||
case math.Abs(delta) < 0.05:
|
||||
return "less than 0.1 places"
|
||||
case delta < 0:
|
||||
return fmt.Sprintf("%.1f places up", -delta)
|
||||
default:
|
||||
return fmt.Sprintf("%.1f places down", delta)
|
||||
}
|
||||
}
|
||||
|
||||
func union(a, b map[string]Numbers) map[string]bool {
|
||||
out := map[string]bool{}
|
||||
for k := range a {
|
||||
|
||||
Reference in New Issue
Block a user