Phase 8 part 1: links that bring visitors

The daily Plausible import also reads the visitors by referring site,
linking page and entry page, with their sign-ups and leads (a new
referrer_days table). Search engines, social networks, AI assistants,
email and mail filters, work apps, the company's own sites and tagged
links are told apart from links on other sites. SEO → Links lists the
sites that sent visitors in 90 days, the pages they landed on and the
sign-ups they brought, new ones first. A linking page Plausible names
in full is kept as a known backlink (a new backlinks table, for parts 2
and 3); browsers mostly send only the site, so most aren't.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-24 08:23:47 -07:00
co-authored by Claude Opus 5.5
parent db0d079ee5
commit 392980aff6
10 changed files with 535 additions and 18 deletions
+50
View File
@@ -0,0 +1,50 @@
package web
import (
"net/http"
"supermarket/internal/profile"
"supermarket/internal/tracking"
)
// SEO → Links: links from other sites to yours.
// linkDays is the period the Links page covers, as What ranks does.
const linkDays = 90
func (s *Server) seoLinksPage(w http.ResponseWriter, r *http.Request) {
data, cur := s.seoBase(r)
data["Path"] = "/seo/links"
data["Plausible"] = s.plausible() != nil
if cur != nil {
if p, _ := profile.Load(s.DB); p != nil {
for _, web := range p.Websites {
if web.URL != cur.URL {
continue
}
list, ok, err := tracking.Referrers(s.DB, web, linkDays)
if err != nil {
s.serverError(w, err)
return
}
data["Read"] = ok
var links []tracking.Referrer
others := map[string]int{}
for _, ref := range list {
if ref.Kind == tracking.RefLink {
links = append(links, ref)
} else {
others[ref.Kind] += ref.Visitors
}
}
data["Links"], data["Others"] = links, others
}
}
var known int
_ = s.DB.QueryRow(`SELECT count(*) FROM backlinks WHERE site = ?`, cur.URL).Scan(&known)
data["Known"] = known
}
last, _ := tracking.Last(s.DB, "referrers")
data["Last"] = last
s.render(w, r, "seo-links", page{Title: "Links", Nav: "seo/links", Data: data})
}
+1
View File
@@ -223,6 +223,7 @@ func (s *Server) Handler() (http.Handler, error) {
mux.HandleFunc("GET /seo/audit/status", s.seoAuditStatus)
mux.HandleFunc("GET /seo/report", s.seoReportPage)
mux.HandleFunc("GET /seo/next", s.seoNextPage)
mux.HandleFunc("GET /seo/links", s.seoLinksPage)
mux.HandleFunc("GET /sites/pages/add", s.sitesAddPage)
mux.HandleFunc("POST /sites/pages/add", s.sitesAdd)
mux.HandleFunc("POST /seo/next/dismiss", s.seoNextDismiss)
+1 -1
View File
@@ -100,7 +100,7 @@ func TestEveryPageRenders(t *testing.T) {
"/settings/ai", "/settings/accounts", "/settings/core", "/static/app.css", "/favicon.ico", "/static/favicon.png", "/static/logo.png", "/static/apple-touch-icon.png", "/search", "/crm", "/search?q=rival", "/search?q=nothing+here", "/static/htmx.min.js", "/healthz",
"/content", "/content/1", "/content/1?dismissed=1", "/posts", "/posts?msg=drafted",
"/content/scheduled", "/content/published",
"/prospects", "/prospects?status=accepted", "/prospects?status=rejected", "/prospects/new", "/prospects/suppressed", "/outreach", "/outreach?tab=queued", "/outreach?tab=sent", "/outreach?tab=replied", "/outreach?tab=failed", "/settings/email", "/settings/tracking", "/settings/search", "/seo", "/seo/check", "/seo/report", "/seo/next", "/seo/audit", "/seo/changes", "/seo/keywords", "/seo/briefs", "/seo/engines", "/metrics", "/metrics/customers", "/metrics/customers?show=all", "/metrics/spend", "/metrics/clv", "/metrics/clv?view=profit", "/metrics/publish", "/sites", "/sites?site=0", "/sites/previews", "/sites/pages", "/sites/publishing", "/sites/forms", "/sites/new", "/settings/backups",
"/prospects", "/prospects?status=accepted", "/prospects?status=rejected", "/prospects/new", "/prospects/suppressed", "/outreach", "/outreach?tab=queued", "/outreach?tab=sent", "/outreach?tab=replied", "/outreach?tab=failed", "/settings/email", "/settings/tracking", "/settings/search", "/seo", "/seo/check", "/seo/report", "/seo/next", "/seo/links", "/seo/audit", "/seo/changes", "/seo/keywords", "/seo/briefs", "/seo/engines", "/metrics", "/metrics/customers", "/metrics/customers?show=all", "/metrics/spend", "/metrics/clv", "/metrics/clv?view=profit", "/metrics/publish", "/sites", "/sites?site=0", "/sites/previews", "/sites/pages", "/sites/publishing", "/sites/forms", "/sites/new", "/settings/backups",
"/signals", "/signals?period=30d&channel=email", "/signals/new", "/settings/sources"} {
rec := do(h, http.MethodGet, path, nil, nil)
if rec.Code != http.StatusOK {
+1
View File
@@ -47,6 +47,7 @@
<a href="/seo/report" {{if eq $nav "seo/report"}}aria-current="page"{{end}}>Monday report</a>
<a href="/seo/next" {{if eq $nav "seo/next"}}aria-current="page"{{end}}>What to write next</a>
<a href="/seo" {{if eq $nav "seo/ranks"}}aria-current="page"{{end}}>What ranks</a>
<a href="/seo/links" {{if eq $nav "seo/links"}}aria-current="page"{{end}}>Links</a>
<a href="/seo/changes" {{if eq $nav "seo/changes"}}aria-current="page"{{end}}>Changes</a>
<a href="/seo/keywords" {{if eq $nav "seo/keywords"}}aria-current="page"{{end}}>Next keywords</a>
<a href="/seo/briefs" {{if eq $nav "seo/briefs"}}aria-current="page"{{end}}>Briefs and pages</a>
+33
View File
@@ -0,0 +1,33 @@
{{define "content"}}{{with .Data}}{{$d := .}}
<div class="heading"><h1>Links</h1></div>
<p class="lede">Links from other sites to yours: the ones that bring visitors and sign-ups, the ones search engines have found, and whether each is still there. A link that brings people who sign up is worth more than any number of links nobody clicks.</p>
{{template "seo-sites" .}}
{{if .Current}}
<section class="card">
<h2>Links that bring visitors</h2>
<p class="small">From Plausible, the last 90 days: other sites whose links people followed to yours, the pages they landed on, and how many of them signed up or sent a form. Search engines, social networks, email and AI assistants are counted apart, below.</p>
{{if not $d.Plausible}}<p class="warn-text small">Save a Plausible key under <a href="/settings/tracking">Settings → Website &amp; sales</a> to see them.</p>
{{else if not $d.Read}}<p class="help">Not read yet: it's read with the daily Plausible import, or now with <em>Import now</em> under <a href="/settings/tracking">Settings → Website &amp; sales</a>.</p>
{{else}}
{{with $d.Links}}
<table class="list">
<thead><tr><th>Site</th><th class="num">Visitors</th><th class="num">Sign-ups</th><th>Landed on</th><th>The linking page</th></tr></thead>
<tbody>{{range .}}<tr>
<td><strong>{{.Source}}</strong>{{if .New}} <span class="badge published">new</span>{{end}}<br><span class="small muted">since {{.FirstSeen}}</span></td>
<td class="num">{{num .Visitors}}</td>
<td class="num">{{if .Signups}}<strong>{{num .Signups}}</strong>{{else}}<span class="muted">0</span>{{end}}</td>
<td class="small">{{range $i, $p := .Pages}}{{if lt $i 3}}{{if $i}}, {{end}}{{$p}}{{end}}{{end}}</td>
<td class="small">{{range .Linking}}<a href="{{.}}" target="_blank" rel="noopener noreferrer">{{truncate 60 .}}</a><br>{{else}}<span class="muted">not given</span>{{end}}</td>
</tr>{{end}}</tbody>
</table>
{{else}}<p class="help">No other site sent visitors in the last 90 days.</p>{{end}}
{{with $d.Others}}<p class="small muted">Also, in visitors: {{with index . "search"}}search engines {{num .}} · {{end}}{{with index . "social"}}social networks {{num .}} · {{end}}{{with index . "ai"}}AI assistants {{num .}} · {{end}}{{with index . "email"}}email {{num .}} · {{end}}{{with index . "app"}}work apps (CRMs, chat, documents) {{num .}} · {{end}}{{with index . "own"}}your other sites {{num .}} · {{end}}{{with index . "tagged"}}tagged links {{num .}}{{end}}</p>{{end}}
<p class="small muted">Browsers usually tell a site only which site a visitor came from, not the page: where the page isn't given, find the link on that site, or add it by hand once that's possible. Visits with no referrer at all (typed in, bookmarks, apps that hide it) aren't counted here. {{with $d.Known}}{{.}} linking {{if eq . 1}}page is{{else}}pages are{{end}} known.{{end}}</p>
{{end}}
{{template "last-read" $d.Last}}
</section>
{{end}}
{{end}}{{end}}
{{define "last-read"}}{{with .}}<p class="small {{if .Error}}error-text{{else}}muted{{end}}">Last read {{ago .At}}: {{if .Error}}{{.Error}}{{else}}{{.Detail}}{{end}}</p>{{end}}{{end}}
+5
View File
@@ -230,6 +230,11 @@ func (s *Server) runTracking(ctx context.Context, source string) error {
if _, perr := tracking.ImportPages(ctx, s.DB, c, s.sites(), now); perr != nil && err == nil {
err = fmt.Errorf("pages: %w", perr)
}
if p, _ := profile.Load(s.DB); p != nil {
if _, rerr := tracking.ImportReferrers(ctx, s.DB, c, p.Websites, now); rerr != nil && err == nil {
err = fmt.Errorf("referring sites: %w", rerr)
}
}
return err
case tracking.SourceStripe:
c := s.stripe()