Phase 4 part 5: CLV and revenue by cohort

CLV = ARPA × revenue-weighted gross margin ÷ customer churn averaged over
up to 12 complete months, with lifetime and CLV:CAC (CAC over its own
12-month window). Revenue by cohort from money that came in: paid
invoices less refunds and post-payment credits not refunded, cumulative
per customer, with a gross profit view; months not reached are told
apart from negative amounts. Metrics → CLV and cohorts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 13:16:33 -07:00
co-authored by Claude Opus 5.5
parent a9a1cb97ac
commit 23f765159f
10 changed files with 447 additions and 1 deletions
+25
View File
@@ -400,3 +400,28 @@ func (s *Server) metricsSpendDelete(w http.ResponseWriter, r *http.Request) {
}
redirect(w, r, "/metrics/spend", "deleted")
}
// --- CLV and cohorts ---
func (s *Server) metricsCLV(w http.ResponseWriter, r *http.Request) {
now := time.Now()
model, err := metrics.Build(s.DB, now)
if err != nil {
s.serverError(w, err)
return
}
clv, err := metrics.BuildCLV(s.DB, model, now)
if err != nil {
s.serverError(w, err)
return
}
cohorts, err := metrics.RevenueByCohort(s.DB, model, 18, 12, now)
if err != nil {
s.serverError(w, err)
return
}
s.render(w, r, "metrics-clv", page{Title: "CLV and cohorts", Nav: "metrics/clv", Data: map[string]any{
"CLV": clv, "Cohorts": cohorts, "Span": make([]int, 13), "Profit": r.URL.Query().Get("view") == "profit",
"Currency": model.Currency,
}})
}
+2
View File
@@ -168,6 +168,7 @@ func (s *Server) Handler() (http.Handler, error) {
mux.HandleFunc("GET /metrics/month/{month}", s.metricsMonth)
mux.HandleFunc("GET /metrics/customers", s.metricsCustomers)
mux.HandleFunc("GET /metrics/spend", s.metricsSpend)
mux.HandleFunc("GET /metrics/clv", s.metricsCLV)
mux.HandleFunc("POST /metrics/spend", s.metricsSpendAdd)
mux.HandleFunc("POST /metrics/spend/{id}/delete", s.metricsSpendDelete)
mux.HandleFunc("POST /metrics/customers/{id}", s.metricsCustomerMatch)
@@ -326,6 +327,7 @@ func (s *Server) loadTemplates() error {
return strconv.FormatFloat(f, 'f', 0, 64) + "%"
},
"spendChannel": metrics.ChannelName,
"dec1f": func(f float64) string { return strconv.FormatFloat(f, 'f', 1, 64) },
"cents": func(f float64) string {
if f < 0 {
return "·"
+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/audit", "/seo/changes", "/seo/keywords", "/seo/briefs", "/seo/engines", "/metrics", "/metrics/customers", "/metrics/customers?show=all", "/metrics/spend",
"/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/audit", "/seo/changes", "/seo/keywords", "/seo/briefs", "/seo/engines", "/metrics", "/metrics/customers", "/metrics/customers?show=all", "/metrics/spend", "/metrics/clv", "/metrics/clv?view=profit",
"/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
@@ -54,6 +54,7 @@
<div class="subnav">
<a href="/metrics" {{if eq $nav "metrics/overview"}}aria-current="page"{{end}}>MRR and NRR</a>
<a href="/metrics/spend" {{if eq $nav "metrics/spend"}}aria-current="page"{{end}}>Spend and CAC</a>
<a href="/metrics/clv" {{if eq $nav "metrics/clv"}}aria-current="page"{{end}}>CLV and cohorts</a>
<a href="/metrics/customers" {{if eq $nav "metrics/customers"}}aria-current="page"{{end}}>Customers and the CRM</a>
</div>
{{end}}
+37
View File
@@ -0,0 +1,37 @@
{{define "content"}}{{with .Data}}{{$d := .}}
<div class="heading"><h1>CLV and cohorts</h1></div>
<p class="lede">What a customer is worth over their life with you, and what each signup cohort has actually paid. CLV is a projection from today's numbers; the cohort table is money that came in, net of refunds and credits.</p>
{{with .CLV}}
<section class="card">
<h2>Customer lifetime value <span class="muted small">measured on {{.Month}}</span></h2>
<div class="funnel">
<div class="step"><span class="label">CLV</span><strong>{{cents .Value}}</strong><span class="rate">gross profit per customer</span></div>
<div class="step"><span class="label">CAC, 12 months</span><strong>{{cents .CAC}}</strong></div>
<div class="step"><span class="label">CLV : CAC</span><strong>{{if ge .Ratio 0.0}}{{dec1f .Ratio}} : 1{{else}}·{{end}}</strong><span class="rate">3 : 1 or more is healthy</span></div>
<div class="step"><span class="label">Average per customer</span><strong>{{usd .ARPA}}</strong><span class="rate">a month</span></div>
<div class="step"><span class="label">Gross margin</span><strong>{{dec1f .Margin}}%</strong><span class="rate">weighted by product</span></div>
<div class="step"><span class="label">Churn</span><strong>{{dec1f .Churn}}%</strong><span class="rate">of customers a month, {{.ChurnMonths}}-month average</span></div>
<div class="step"><span class="label">Lifetime</span><strong>{{if .Lifetime}}{{dec1f .Lifetime}}{{else}}·{{end}}</strong><span class="rate">months, on average</span></div>
</div>
<p class="small muted">CLV = average MRR per customer × gross margin ÷ monthly churn. The margin weighs each product's margin (set on <a href="/metrics#margins">MRR and NRR</a>) by what it billed over 12 months. CAC is the spend logged over the same 12 months ÷ the new customers in them{{if lt .CAC 0.0}}: <a href="/metrics/spend">log your spend</a> to see it{{end}}.</p>
</section>
{{else}}
<section class="card empty"><p>CLV needs at least two complete months of billing from Stripe.</p></section>
{{end}}
{{if .Cohorts}}
<h2>Revenue by cohort</h2>
<p class="help">Customers by the month they first paid, and what they've paid since, per customer, cumulative: invoices paid, less refunds and credits. Month 0 is the month they first paid.</p>
<nav class="tabs">
<a href="/metrics/clv" {{if not .Profit}}aria-current="page"{{end}}>Revenue</a>
<a href="/metrics/clv?view=profit" {{if .Profit}}aria-current="page"{{end}}>Gross profit</a>
</nav>
<div class="table-wrap"><table class="list compact cohorts">
<thead><tr><th>First paid</th><th class="num">Customers</th>{{range $i, $_ := .Span}}<th class="num">{{$i}}</th>{{end}}</tr></thead>
<tbody>{{range .Cohorts}}<tr><td>{{.Month}}</td><td class="num">{{.Customers}}</td>
{{if $d.Profit}}{{range .Margin}}<td class="num">{{if .Known}}{{usd .V}}{{end}}</td>{{end}}{{else}}{{range .PerCustomer}}<td class="num">{{if .Known}}{{usd .V}}{{end}}</td>{{end}}{{end}}
</tr>{{end}}</tbody>
</table></div>
{{end}}
{{end}}{{end}}