Phase 5 part 4: landing pages per buying signal
Each signal's page lists its landing pages with their Gitea status, live address and 30-day visitors from Plausible, and builds a new one. Pages can be duplicated as variants (B, C…, with their own utm_content), taken off the site through a pull request that deletes the file, or have their pull request closed. The scorecard counts live pages. Schema 23. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,8 @@ import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"supermarket/internal/sites"
|
||||
"supermarket/internal/tracking"
|
||||
"time"
|
||||
|
||||
"supermarket/internal/ai"
|
||||
@@ -64,7 +66,13 @@ func (s *Server) renderSignals(w http.ResponseWriter, r *http.Request, errMsg st
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
live, err := sites.LivePageCounts(s.DB)
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
s.render(w, r, "signals", page{Title: "Signals", Nav: "prospects/signals", Error: errMsg, Data: map[string]any{
|
||||
"LivePages": live,
|
||||
"Rows": rows,
|
||||
"Signals": list,
|
||||
"Stages": signals.Stages,
|
||||
@@ -92,6 +100,10 @@ type signalData struct {
|
||||
Posts []content.Draft // written for it
|
||||
Links []string // the websites, tagged with its campaign
|
||||
|
||||
Pages []signalPage // its landing pages and their variants
|
||||
PageSites []siteRepo // websites a landing page can go on
|
||||
VisitorsErr string // why page visitors couldn't be read
|
||||
|
||||
Runs []discovery.Run
|
||||
Running bool
|
||||
Research string // why Claude can't search, or ""
|
||||
@@ -101,6 +113,13 @@ type signalData struct {
|
||||
MaxResults int
|
||||
}
|
||||
|
||||
// signalPage is a landing page on a signal's page.
|
||||
type signalPage struct {
|
||||
sites.SitePage
|
||||
Address string // on the live site
|
||||
Visitors int // last 30 days; -1 when unknown
|
||||
}
|
||||
|
||||
type channelRow struct {
|
||||
Channel string
|
||||
Row signals.Row
|
||||
@@ -171,6 +190,10 @@ func (s *Server) renderSignal(w http.ResponseWriter, r *http.Request, sig *signa
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
if err := s.signalPages(r.Context(), sig, &d); err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
cs, ps, err := prospects.Review(s.DB, prospects.StatusNew, sig.ID, 1000)
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
@@ -667,3 +690,61 @@ func tagLink(site, slug string) string {
|
||||
u.RawQuery = q.Encode()
|
||||
return u.String()
|
||||
}
|
||||
|
||||
// signalPages fills in a signal's landing pages: their state on Gitea
|
||||
// (merged, closed), and each live one's visitors over 30 days.
|
||||
func (s *Server) signalPages(ctx context.Context, sig *signals.Signal, d *signalData) error {
|
||||
ps, err := sites.SignalPages(s.DB, sig.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, sr := range s.siteRepos() {
|
||||
if sr.Repo != "" {
|
||||
d.PageSites = append(d.PageSites, sr)
|
||||
}
|
||||
}
|
||||
if s.gitea() != nil {
|
||||
gctx, cancel := context.WithTimeout(ctx, 15*time.Second)
|
||||
for i := range ps {
|
||||
if ps[i].Status == sites.PagePR || ps[i].Status == sites.PageRemoving {
|
||||
s.refreshPagePR(gctx, &ps[i])
|
||||
}
|
||||
}
|
||||
cancel()
|
||||
}
|
||||
prof, _ := profile.Load(s.DB)
|
||||
bySite := map[string][]string{}
|
||||
for _, p := range ps {
|
||||
if p.Live() {
|
||||
bySite[p.Site] = append(bySite[p.Site], p.Path)
|
||||
}
|
||||
}
|
||||
visitors := map[string]map[string]int{}
|
||||
if pl := s.plausible(); pl != nil && prof != nil && len(bySite) > 0 {
|
||||
pctx, cancel := context.WithTimeout(ctx, 15*time.Second)
|
||||
for _, w := range prof.Websites {
|
||||
paths := bySite[w.URL]
|
||||
if len(paths) == 0 {
|
||||
continue
|
||||
}
|
||||
v, err := tracking.PageVisitors(pctx, pl, tracking.SiteID(w), paths)
|
||||
if err != nil {
|
||||
d.VisitorsErr = err.Error()
|
||||
continue
|
||||
}
|
||||
visitors[w.URL] = v
|
||||
}
|
||||
cancel()
|
||||
}
|
||||
for _, p := range ps {
|
||||
sp := signalPage{SitePage: p, Visitors: -1}
|
||||
if p.Live() {
|
||||
sp.Address = strings.TrimRight(p.Site, "/") + p.Path
|
||||
if v, ok := visitors[p.Site]; ok {
|
||||
sp.Visitors = v[p.Path]
|
||||
}
|
||||
}
|
||||
d.Pages = append(d.Pages, sp)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user