Phase 7 part 1: sign-ups by page
Settings → Website & sales says which clicked links count as a sign-up: Supermarket suggests the sign-up, trial and checkout links visitors clicked, and the user ticks, unticks or adds their own. The Plausible import reads, per page a visit began on, the visitors, sign-ups and form leads (a new page_days table); What ranks, the audit and Sites show visits and sign-ups next to each page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -302,6 +302,7 @@ func (s *Server) seoPage(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
data["Ranks"] = ranks
|
||||
data["Conv"] = s.pageConv(cur.URL)
|
||||
}
|
||||
s.render(w, r, "seo", page{Title: "SEO", Nav: "seo/ranks", Data: data})
|
||||
}
|
||||
@@ -552,6 +553,7 @@ func (s *Server) seoAuditPage(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
data["Audit"] = a
|
||||
data["Conv"] = s.pageConv(cur.URL)
|
||||
if a != nil && a.Status == "done" {
|
||||
sev := r.URL.Query().Get("severity")
|
||||
var shown []seo.Issue
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"supermarket/internal/seo"
|
||||
"supermarket/internal/signals"
|
||||
"supermarket/internal/sites"
|
||||
"supermarket/internal/tracking"
|
||||
)
|
||||
|
||||
//go:embed templates/*.html
|
||||
@@ -228,6 +229,7 @@ func (s *Server) Handler() (http.Handler, error) {
|
||||
mux.HandleFunc("GET /settings/tracking", s.trackingPage)
|
||||
mux.HandleFunc("POST /settings/tracking", s.trackingSave)
|
||||
mux.HandleFunc("POST /settings/tracking/test/{source}", s.trackingTest)
|
||||
mux.HandleFunc("POST /settings/tracking/signups", s.trackingSignups)
|
||||
mux.HandleFunc("POST /settings/tracking/run/{source}", s.trackingRun)
|
||||
mux.HandleFunc("GET /outreach", s.outreachPage)
|
||||
mux.HandleFunc("POST /outreach/draft", s.outreachDraft)
|
||||
@@ -394,8 +396,11 @@ func (s *Server) loadTemplates() error {
|
||||
"dec1": func(f float64) string { return strconv.FormatFloat(f, 'f', 1, 64) },
|
||||
"pagePath": pagePath,
|
||||
"change": seo.Percent,
|
||||
"stage": signals.StageLabel,
|
||||
"channel": signals.ChannelLabel,
|
||||
"conv": func(m map[string]tracking.PageNumbers, page string) tracking.PageNumbers {
|
||||
return m[tracking.PathOf(page)]
|
||||
},
|
||||
"stage": signals.StageLabel,
|
||||
"channel": signals.ChannelLabel,
|
||||
"truncate": func(n int, s string) string {
|
||||
r := []rune(s)
|
||||
if len(r) <= n {
|
||||
@@ -532,6 +537,7 @@ var flashes = map[string]string{
|
||||
"keyword-picked": "Picked. Write its brief when you're ready.",
|
||||
"keyword-dismissed": "Dismissed: it's under Dismissed if you change your mind.",
|
||||
"keyword-back": "Back among the candidates.",
|
||||
"signups-saved": "Saved. The pages' sign-ups were read again with it.",
|
||||
"audited": "The audit is done.",
|
||||
"auditing": "Auditing. It reads up to 300 pages politely, so it takes a few minutes; this page updates when it's done.",
|
||||
"no-data": "There isn't two weeks of Search Console data yet.",
|
||||
|
||||
@@ -87,6 +87,9 @@ func (s *Server) sitesPage(w http.ResponseWriter, r *http.Request) {
|
||||
func (s *Server) renderSites(w http.ResponseWriter, r *http.Request, errMsg string) {
|
||||
all, cur := s.currentSite(r)
|
||||
data := map[string]any{"Sites": all, "Current": cur, "Gitea": s.gitea() != nil, "Synced": siteSynced{}}
|
||||
if cur != nil {
|
||||
data["Conv"] = s.pageConv(cur.URL)
|
||||
}
|
||||
if cur != nil && cur.Repo != "" {
|
||||
var synced siteSynced
|
||||
if ok, _ := s.DB.GetJSON(siteSyncKey(cur.Repo), &synced); ok {
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
<h2>Issues{{with $d.Severity}}: {{.}}s{{end}}</h2>
|
||||
{{if $d.Shown}}
|
||||
<table class="list">
|
||||
<thead><tr><th></th><th>Issue</th><th>Page</th><th class="num">Clicks</th><th class="num">Impressions</th></tr></thead>
|
||||
<thead><tr><th></th><th>Issue</th><th>Page</th><th class="num">Clicks</th><th class="num">Impressions</th>{{if $d.Conv}}<th class="num" title="Visits that began on the page and went on to sign up or send a form, in 90 days">Sign-ups</th>{{end}}</tr></thead>
|
||||
<tbody>{{range $d.Shown}}<tr>
|
||||
<td><span class="badge {{if eq .Severity "error"}}failed{{else if eq .Severity "warning"}}scheduled{{end}}">{{.Severity}}</span></td>
|
||||
<td><strong>{{.Title}}</strong>{{with .Detail}}<br><span class="small">{{truncate 400 .}}</span>{{end}}
|
||||
@@ -70,7 +70,7 @@
|
||||
<td class="small"><a href="{{.Page}}" target="_blank" rel="noopener noreferrer">{{pagePath .Page}}</a></td>
|
||||
<td class="num">{{if .Traffic.Impressions}}{{num .Traffic.Clicks}}{{else}}<span class="muted">·</span>{{end}}</td>
|
||||
<td class="num">{{if .Traffic.Impressions}}{{num .Traffic.Impressions}}{{else}}<span class="muted">·</span>{{end}}</td>
|
||||
</tr>{{end}}</tbody>
|
||||
{{if $d.Conv}}{{with conv $d.Conv .Page}}<td class="num">{{if .Conversions}}<strong>{{num .Conversions}}</strong>{{else if .Visitors}}<span class="muted">0</span>{{else}}<span class="muted">·</span>{{end}}</td>{{end}}{{end}}</tr>{{end}}</tbody>
|
||||
</table>
|
||||
{{with $d.More}}<p class="help">And {{.}} more.</p>{{end}}
|
||||
{{else}}<p class="help">No issues{{with $d.Severity}} of this kind{{end}}.</p>{{end}}
|
||||
|
||||
@@ -25,12 +25,12 @@
|
||||
<section class="card">
|
||||
<h2>Protect</h2>
|
||||
<p class="help">They carry the clicks: don't rewrite them for fun, don't change their address, look at them first.</p>
|
||||
{{range .Protect}}<p><a href="{{.Page}}" target="_blank" rel="noopener noreferrer">{{pagePath .Page}}</a><br><span class="small">{{.Why}}</span></p>{{else}}<p class="help">No page has clicks yet.</p>{{end}}
|
||||
{{range .Protect}}<p><a href="{{.Page}}" target="_blank" rel="noopener noreferrer">{{pagePath .Page}}</a><br><span class="small">{{.Why}}{{if $d.Conv}}{{with conv $d.Conv .Page}} {{num .Visitors}} visits and {{num .Conversions}} sign-ups in 90 days.{{end}}{{end}}</span></p>{{else}}<p class="help">No page has clicks yet.</p>{{end}}
|
||||
</section>
|
||||
<section class="card">
|
||||
<h2>Push</h2>
|
||||
<p class="help">On page one, shown a lot, hardly clicked: Google did the hard part, and the page loses at the click. Compare its main query with its title first.</p>
|
||||
{{range .Push}}<p><a href="{{.Page}}" target="_blank" rel="noopener noreferrer">{{pagePath .Page}}</a><br><span class="small">{{.Why}}</span>
|
||||
{{range .Push}}<p><a href="{{.Page}}" target="_blank" rel="noopener noreferrer">{{pagePath .Page}}</a><br><span class="small">{{.Why}}{{if $d.Conv}}{{with conv $d.Conv .Page}} {{num .Visitors}} visits and {{num .Conversions}} sign-ups in 90 days.{{end}}{{end}}</span>
|
||||
<form method="post" action="/seo/changes/page?site={{$d.Current.Index}}" class="inline" data-busy="Writing…"><input type="hidden" name="page" value="{{.Page}}"><input type="hidden" name="why" value="{{.Why}}"><button type="submit" class="link small">Propose a new title and description</button></form>
|
||||
· <form method="post" action="/seo/briefs?site={{$d.Current.Index}}" class="inline" data-busy="Writing the brief…"><input type="hidden" name="page" value="{{.Page}}"><button type="submit" class="link small">Write a brief to rewrite it</button></form></p>{{else}}<p class="help">No page sits on page one with few clicks. Good, or too little data.</p>{{end}}
|
||||
</section>
|
||||
@@ -39,8 +39,8 @@
|
||||
<h2>Best pages</h2>
|
||||
{{if .Pages}}
|
||||
<table class="list">
|
||||
<thead><tr><th>Page</th><th class="num">Clicks</th><th class="num">Impressions</th><th class="num">Click rate</th><th class="num">Position</th></tr></thead>
|
||||
<tbody>{{range .Pages}}<tr><td><a href="{{.Page}}" target="_blank" rel="noopener noreferrer">{{pagePath .Page}}</a></td><td class="num">{{num .Clicks}}</td><td class="num">{{num .Impressions}}</td><td class="num">{{dec1 .CTR}}%</td><td class="num">{{dec1 .Position}}</td></tr>{{end}}</tbody>
|
||||
<thead><tr><th>Page</th><th class="num">Clicks</th><th class="num">Impressions</th><th class="num">Click rate</th><th class="num">Position</th>{{if $d.Conv}}<th class="num" title="Visits that began on the page, from Plausible">Visits</th><th class="num" title="Visits that began on the page and went on to sign up or send a form">Sign-ups</th>{{end}}</tr></thead>
|
||||
<tbody>{{range .Pages}}<tr><td><a href="{{.Page}}" target="_blank" rel="noopener noreferrer">{{pagePath .Page}}</a></td><td class="num">{{num .Clicks}}</td><td class="num">{{num .Impressions}}</td><td class="num">{{dec1 .CTR}}%</td><td class="num">{{dec1 .Position}}</td>{{if $d.Conv}}{{with conv $d.Conv .Page}}<td class="num">{{num .Visitors}}</td><td class="num">{{if .Conversions}}<strong>{{num .Conversions}}</strong>{{else}}<span class="muted">0</span>{{end}}</td>{{end}}{{end}}</tr>{{end}}</tbody>
|
||||
</table>
|
||||
{{else}}<p class="help">No pages with data yet.</p>{{end}}
|
||||
|
||||
|
||||
@@ -79,16 +79,16 @@
|
||||
<h2>Pages</h2>
|
||||
{{with $d.SectionPages}}
|
||||
<div class="table-wrap"><table class="compact">
|
||||
<thead><tr><th>Address</th><th>Title</th><th>Sections</th></tr></thead>
|
||||
<tbody>{{range .}}<tr><td><a href="{{$d.Current.Base}}{{.Path}}" target="_blank" rel="noopener noreferrer">{{.Path}}</a>{{if .Draft}} <span class="badge draft">draft</span>{{end}}</td><td>{{.Title}}</td><td class="small">{{join .Types " · "}}</td></tr>{{end}}</tbody>
|
||||
<thead><tr><th>Address</th><th>Title</th><th>Sections</th>{{if $d.Conv}}<th class="num" title="Visits that began on the page, in 90 days (Plausible)">Visits</th><th class="num" title="Of those, the ones that went on to sign up or send a form">Sign-ups</th>{{end}}</tr></thead>
|
||||
<tbody>{{range .}}<tr><td><a href="{{$d.Current.Base}}{{.Path}}" target="_blank" rel="noopener noreferrer">{{.Path}}</a>{{if .Draft}} <span class="badge draft">draft</span>{{end}}</td><td>{{.Title}}</td><td class="small">{{join .Types " · "}}</td>{{if $d.Conv}}{{with conv $d.Conv .Path}}<td class="num">{{num .Visitors}}</td><td class="num">{{if .Conversions}}<strong>{{num .Conversions}}</strong>{{else}}<span class="muted">0</span>{{end}}</td>{{end}}{{end}}</tr>{{end}}</tbody>
|
||||
</table></div>
|
||||
{{else}}<p class="help">No page is built from sections yet.</p>{{end}}
|
||||
{{with $d.OtherPages}}
|
||||
<details class="card">
|
||||
<summary>{{len .}} other pages, written in Markdown</summary>
|
||||
<div class="table-wrap"><table class="compact">
|
||||
<thead><tr><th>Address</th><th>Title</th></tr></thead>
|
||||
<tbody>{{range .}}<tr><td>{{.Path}}{{if .Draft}} <span class="badge draft">draft</span>{{end}}</td><td>{{.Title}}</td></tr>{{end}}</tbody>
|
||||
<thead><tr><th>Address</th><th>Title</th>{{if $d.Conv}}<th class="num">Visits</th><th class="num">Sign-ups</th>{{end}}</tr></thead>
|
||||
<tbody>{{range .}}<tr><td>{{.Path}}{{if .Draft}} <span class="badge draft">draft</span>{{end}}</td><td>{{.Title}}</td>{{if $d.Conv}}{{with conv $d.Conv .Path}}<td class="num">{{num .Visitors}}</td><td class="num">{{if .Conversions}}<strong>{{num .Conversions}}</strong>{{else}}<span class="muted">0</span>{{end}}</td>{{end}}{{end}}</tr>{{end}}</tbody>
|
||||
</table></div>
|
||||
</details>
|
||||
{{end}}
|
||||
|
||||
@@ -61,6 +61,31 @@ metadata[utm_content] = optional: which message or post</pre>
|
||||
|
||||
<div class="actions"><button type="submit">Save</button></div>
|
||||
</form>
|
||||
|
||||
{{if .PlausibleSet}}
|
||||
<form method="post" action="/settings/tracking/signups" data-busy="Saving and reading the pages…">
|
||||
<section class="card" id="signups">
|
||||
<h3>What counts as a sign-up</h3>
|
||||
<p class="small">Each page of your site is measured by what its visitors go on to do: click through to sign up, or send a form. Plausible records clicks on links to other sites (its <em>Outbound Link: Click</em> goal), and ties each to the page the visit began on. Say which of those links start a sign-up.{{if not .Signups.Saved}} <strong>Supermarket's suggestion is ticked</strong>: the links that look like a sign-up, a trial or a checkout. Change it and save to make it yours.{{end}}</p>
|
||||
{{with .Links}}
|
||||
<table class="list">
|
||||
<thead><tr><th>A sign-up?</th><th>Link clicked, last 30 days</th><th class="num">Visitors</th></tr></thead>
|
||||
<tbody>{{range .}}<tr>
|
||||
<td><input type="checkbox" name="link" value="{{.URL}}" aria-label="{{.URL}} is a sign-up" {{if .Signup}}checked{{end}}></td>
|
||||
<td class="small"><code>{{.URL}}</code></td><td class="num">{{num .Visitors}}</td>
|
||||
</tr>{{end}}</tbody>
|
||||
</table>
|
||||
{{else}}<p class="help">No clicks on outbound links in the last 30 days, or Plausible couldn't be read.</p>{{end}}
|
||||
<label>Other links that count (optional)
|
||||
<textarea name="patterns" rows="3" placeholder="cloud.federated.computer/signup">{{.OwnPatterns}}</textarea>
|
||||
<span class="help">One per line. A link counts if it contains the text, in any case: <code>/signup</code> counts every sign-up page on every site.</span>
|
||||
</label>
|
||||
<p class="small">Form leads count too, once your forms send Plausible's <code>Lead</code> goal (Sites → Lead forms).</p>
|
||||
<div class="actions"><button type="submit">Save what counts</button></div>
|
||||
{{template "last-run" .LastPages}}
|
||||
</section>
|
||||
</form>
|
||||
{{end}}
|
||||
{{end}}{{template "settings-end"}}{{end}}
|
||||
|
||||
{{define "last-run"}}{{with .}}
|
||||
|
||||
@@ -3,7 +3,9 @@ package web
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -78,6 +80,39 @@ func (s *Server) renderTracking(w http.ResponseWriter, r *http.Request, errMsg s
|
||||
lastS, _ := tracking.Last(s.DB, tracking.SourceStripe)
|
||||
customers, _ := tracking.Customers(s.DB, 20)
|
||||
set, _ := s.outreachSettings()
|
||||
// The links visitors clicked, to say which are sign-ups.
|
||||
var links []tracking.OutboundLink
|
||||
if c := s.plausible(); c != nil {
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 15*time.Second)
|
||||
for _, site := range s.sites() {
|
||||
l, err := tracking.OutboundLinks(ctx, c, site)
|
||||
if err == nil {
|
||||
links = append(links, l...)
|
||||
}
|
||||
}
|
||||
cancel()
|
||||
}
|
||||
var urls []string
|
||||
for _, l := range links {
|
||||
urls = append(urls, l.URL)
|
||||
}
|
||||
signups := tracking.LoadSignups(s.DB, urls)
|
||||
var own []string // patterns that aren't one of the links, to edit as text
|
||||
for i := range links {
|
||||
links[i].Signup = signups.Matches(links[i].URL)
|
||||
}
|
||||
for _, p := range signups.Patterns {
|
||||
listed := false
|
||||
for _, l := range links {
|
||||
if strings.EqualFold(patternOf(l.URL), p) {
|
||||
listed = true
|
||||
}
|
||||
}
|
||||
if !listed {
|
||||
own = append(own, p)
|
||||
}
|
||||
}
|
||||
lastPages, _ := tracking.Last(s.DB, "pages")
|
||||
s.render(w, r, "tracking", page{Title: "Website & sales", Nav: "settings/tracking", Error: errMsg, Data: map[string]any{
|
||||
"PlausibleURL": s.plausibleURL(),
|
||||
"PlausibleKey": plausibleKey,
|
||||
@@ -89,6 +124,10 @@ func (s *Server) renderTracking(w http.ResponseWriter, r *http.Request, errMsg s
|
||||
"LastStripe": lastS,
|
||||
"Customers": customers,
|
||||
"BookingFrom": set.BookingFrom,
|
||||
"Links": links,
|
||||
"Signups": signups,
|
||||
"OwnPatterns": strings.Join(own, "\n"),
|
||||
"LastPages": lastPages,
|
||||
}})
|
||||
}
|
||||
|
||||
@@ -188,6 +227,9 @@ func (s *Server) runTracking(ctx context.Context, source string) error {
|
||||
return errors.New("save the Plausible key first")
|
||||
}
|
||||
_, err := tracking.ImportPlausible(ctx, s.DB, c, s.sites(), now)
|
||||
if _, perr := tracking.ImportPages(ctx, s.DB, c, s.sites(), now); perr != nil && err == nil {
|
||||
err = fmt.Errorf("pages: %w", perr)
|
||||
}
|
||||
return err
|
||||
case tracking.SourceStripe:
|
||||
c := s.stripe()
|
||||
@@ -235,3 +277,67 @@ func (s *Server) RunTracking(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// patternOf is the pattern a ticked link saves as: its host and path.
|
||||
func patternOf(link string) string {
|
||||
if p := tracking.SuggestSignups([]string{link}); len(p) > 0 {
|
||||
return p[0]
|
||||
}
|
||||
if u, err := url.Parse(link); err == nil && u.Host != "" {
|
||||
return strings.ToLower(u.Host + strings.TrimRight(u.Path, "/"))
|
||||
}
|
||||
return strings.ToLower(link)
|
||||
}
|
||||
|
||||
// trackingSignups saves what counts as a sign-up, and reads the pages
|
||||
// again with it.
|
||||
func (s *Server) trackingSignups(w http.ResponseWriter, r *http.Request) {
|
||||
if err := r.ParseForm(); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
var pats []string
|
||||
for _, l := range r.PostForm["link"] {
|
||||
pats = append(pats, patternOf(l))
|
||||
}
|
||||
pats = append(pats, strings.Split(r.PostFormValue("patterns"), "\n")...)
|
||||
if err := tracking.SaveSignups(s.DB, pats); err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
if c := s.plausible(); c != nil {
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 3*time.Minute)
|
||||
_, err := tracking.ImportPages(ctx, s.DB, c, s.sites(), time.Now())
|
||||
cancel()
|
||||
if err != nil {
|
||||
s.renderTracking(w, r, "Saved, but reading the pages again failed: "+err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
redirect(w, r, "/settings/tracking#signups", "signups-saved")
|
||||
}
|
||||
|
||||
// convDays is the period the page tables show visits and sign-ups for, as
|
||||
// What ranks shows Search Console's.
|
||||
const convDays = 90
|
||||
|
||||
// pageConv is a website's visits, sign-ups and leads by page over the last
|
||||
// convDays, or nil before Plausible's pages were read.
|
||||
func (s *Server) pageConv(siteURL string) map[string]tracking.PageNumbers {
|
||||
p, _ := profile.Load(s.DB)
|
||||
if p == nil {
|
||||
return nil
|
||||
}
|
||||
want := strings.TrimRight(strings.ToLower(strings.TrimSpace(siteURL)), "/")
|
||||
for _, w := range p.Websites {
|
||||
if strings.TrimRight(strings.ToLower(strings.TrimSpace(w.URL)), "/") != want {
|
||||
continue
|
||||
}
|
||||
pages, ok, err := tracking.Pages(s.DB, tracking.SiteID(w), convDays)
|
||||
if err != nil || !ok {
|
||||
return nil
|
||||
}
|
||||
return pages
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user