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,
}})
}