Metrics: every cohort over every month, percentages and dollars aligned
Both cohort tables (MRR retention on Metrics, revenue per customer on CLV) and their CSVs now show every cohort, each followed to the latest month, instead of the last 12 or 18 for 12 or 24 months. Each MRR cohort is now two rows, the share of starting MRR and the dollars under it, so the numbers line up across months; the month, customers and starting MRR span both rows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -61,14 +61,15 @@ func Export(w io.Writer, d *db.DB, name string, now time.Time) error {
|
|||||||
}
|
}
|
||||||
case "nrr-cohorts":
|
case "nrr-cohorts":
|
||||||
head := []string{"first_paid", "customers", "starting_mrr"}
|
head := []string{"first_paid", "customers", "starting_mrr"}
|
||||||
for k := 0; k <= 24; k++ {
|
span := max(len(model.Months)-1, 0) // every cohort, to the latest month
|
||||||
|
for k := 0; k <= span; k++ {
|
||||||
head = append(head, fmt.Sprintf("month_%d_pct", k))
|
head = append(head, fmt.Sprintf("month_%d_pct", k))
|
||||||
}
|
}
|
||||||
for k := 0; k <= 24; k++ {
|
for k := 0; k <= span; k++ {
|
||||||
head = append(head, fmt.Sprintf("month_%d_mrr", k))
|
head = append(head, fmt.Sprintf("month_%d_mrr", k))
|
||||||
}
|
}
|
||||||
write(head)
|
write(head)
|
||||||
for _, c := range model.Cohorts(1000, 24) {
|
for _, c := range model.Cohorts(len(model.Months), span) {
|
||||||
row := []string{c.Month, strconv.Itoa(c.Customers), dollars(c.Start)}
|
row := []string{c.Month, strconv.Itoa(c.Customers), dollars(c.Start)}
|
||||||
for _, r := range c.Retained {
|
for _, r := range c.Retained {
|
||||||
row = append(row, pct(r))
|
row = append(row, pct(r))
|
||||||
@@ -85,12 +86,13 @@ func Export(w io.Writer, d *db.DB, name string, now time.Time) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "cohort-revenue":
|
case "cohort-revenue":
|
||||||
cs, err := RevenueByCohort(d, model, 1000, 24, now)
|
span := max(len(model.Months)-1, 0) // every cohort, to the latest month
|
||||||
|
cs, err := RevenueByCohort(d, model, len(model.Months), span, now)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
head := []string{"first_paid", "customers"}
|
head := []string{"first_paid", "customers"}
|
||||||
for k := 0; k <= 24; k++ {
|
for k := 0; k <= span; k++ {
|
||||||
head = append(head, fmt.Sprintf("month_%d_revenue_per_customer", k))
|
head = append(head, fmt.Sprintf("month_%d_revenue_per_customer", k))
|
||||||
}
|
}
|
||||||
write(head)
|
write(head)
|
||||||
|
|||||||
@@ -54,8 +54,9 @@ func (s *Server) renderMetrics(w http.ResponseWriter, r *http.Request, errMsg st
|
|||||||
"Now": model.Last(),
|
"Now": model.Last(),
|
||||||
"Recent": model.Recent(13),
|
"Recent": model.Recent(13),
|
||||||
"Bars": bars(model, 24),
|
"Bars": bars(model, 24),
|
||||||
"Cohorts": model.Cohorts(12, 12),
|
// Every cohort, each followed to the latest month.
|
||||||
"Span": make([]int, 13),
|
"Cohorts": model.Cohorts(len(model.Months), max(len(model.Months)-1, 0)),
|
||||||
|
"Span": make([]int, len(model.Months)),
|
||||||
}})
|
}})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -429,13 +430,14 @@ func (s *Server) metricsCLV(w http.ResponseWriter, r *http.Request) {
|
|||||||
s.serverError(w, err)
|
s.serverError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cohorts, err := metrics.RevenueByCohort(s.DB, model, 18, 12, now)
|
span := max(len(model.Months)-1, 0) // every cohort, to the latest month
|
||||||
|
cohorts, err := metrics.RevenueByCohort(s.DB, model, len(model.Months), span, now)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.serverError(w, err)
|
s.serverError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.render(w, r, "metrics-clv", page{Title: "CLV and cohorts", Nav: "metrics/clv", Data: map[string]any{
|
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",
|
"CLV": clv, "Cohorts": cohorts, "Span": make([]int, span+1), "Profit": r.URL.Query().Get("view") == "profit",
|
||||||
"Currency": model.Currency,
|
"Currency": model.Currency,
|
||||||
}})
|
}})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -411,6 +411,12 @@ svg.chart rect { fill: hsl(var(--primary)); opacity: 0.85; }
|
|||||||
svg.chart rect:hover { opacity: 1; }
|
svg.chart rect:hover { opacity: 1; }
|
||||||
svg.chart text { font-size: 9px; fill: hsl(var(--muted-foreground)); }
|
svg.chart text { font-size: 9px; fill: hsl(var(--muted-foreground)); }
|
||||||
table.cohorts td, table.cohorts th { padding-left: 0.4rem; padding-right: 0.4rem; font-size: 0.85rem; }
|
table.cohorts td, table.cohorts th { padding-left: 0.4rem; padding-right: 0.4rem; font-size: 0.85rem; }
|
||||||
|
/* Each cohort is two rows: the share of starting MRR, then the dollars
|
||||||
|
under it; the month, customers and starting MRR span both. */
|
||||||
|
table.cohorts tbody.cohort tr.pct td { border-bottom: 0; padding-bottom: 0.1rem; }
|
||||||
|
table.cohorts tbody.cohort tr.pct td[rowspan] { vertical-align: middle; padding-bottom: 0.6rem; border-bottom: 1px solid hsl(var(--border)); }
|
||||||
|
table.cohorts tbody.cohort tr.usd td { padding-top: 0.1rem; color: hsl(var(--muted-foreground)); border-bottom: 1px solid hsl(var(--border)); }
|
||||||
|
table.cohorts tbody.cohort:last-child tr.usd td, table.cohorts tbody.cohort:last-child tr.pct td[rowspan] { border-bottom: 0; }
|
||||||
.table-wrap { overflow-x: auto; }
|
.table-wrap { overflow-x: auto; }
|
||||||
table.compact th, table.compact td { white-space: nowrap; padding-left: 0.5rem; padding-right: 0.5rem; font-size: 0.85rem; }
|
table.compact th, table.compact td { white-space: nowrap; padding-left: 0.5rem; padding-right: 0.5rem; font-size: 0.85rem; }
|
||||||
/* A button that opens a small form below it (Sites: variants). */
|
/* A button that opens a small form below it (Sites: variants). */
|
||||||
|
|||||||
@@ -33,6 +33,6 @@
|
|||||||
{{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}}
|
{{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>
|
</tr>{{end}}</tbody>
|
||||||
</table></div>
|
</table></div>
|
||||||
<p class="small"><a href="/metrics/export/cohort-revenue.csv">Download as CSV</a> (every cohort, 24 months)</p>
|
<p class="small"><a href="/metrics/export/cohort-revenue.csv">Download as CSV</a> (every cohort, every month)</p>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}{{end}}
|
{{end}}{{end}}
|
||||||
|
|||||||
@@ -65,9 +65,12 @@
|
|||||||
<p class="help">Customers by the month they first paid, and what those same customers pay each month after: the share of their starting MRR (above 100% means they grew), and below it the dollars.</p>
|
<p class="help">Customers by the month they first paid, and what those same customers pay each month after: the share of their starting MRR (above 100% means they grew), and below it the dollars.</p>
|
||||||
<div class="table-wrap"><table class="list compact cohorts">
|
<div class="table-wrap"><table class="list compact cohorts">
|
||||||
<thead><tr><th>First paid</th><th class="num">Customers</th><th class="num">Starting MRR</th>{{range $i, $_ := $d.Span}}<th class="num">{{$i}}</th>{{end}}</tr></thead>
|
<thead><tr><th>First paid</th><th class="num">Customers</th><th class="num">Starting MRR</th>{{range $i, $_ := $d.Span}}<th class="num">{{$i}}</th>{{end}}</tr></thead>
|
||||||
<tbody>{{range $d.Cohorts}}<tr><td>{{.Month}}</td><td class="num">{{.Customers}}</td><td class="num">{{usd .Start}}</td>{{$co := .}}{{range $k, $r := .Retained}}<td class="num">{{if ge $r 0.0}}{{pct $r}}<br><span class="muted small">{{usd (index $co.MRR $k)}}</span>{{end}}</td>{{end}}</tr>{{end}}</tbody>
|
{{range $d.Cohorts}}<tbody class="cohort">
|
||||||
|
<tr class="pct"><td rowspan="2">{{.Month}}</td><td class="num" rowspan="2">{{.Customers}}</td><td class="num" rowspan="2">{{usd .Start}}</td>{{range .Retained}}<td class="num">{{if ge . 0.0}}{{pct .}}{{end}}</td>{{end}}</tr>
|
||||||
|
<tr class="usd">{{range .MRR}}<td class="num">{{if ge . 0.0}}{{usd .}}{{end}}</td>{{end}}</tr>
|
||||||
|
</tbody>{{end}}
|
||||||
</table></div>
|
</table></div>
|
||||||
<p class="small"><a href="/metrics/export/nrr-cohorts.csv">Download as CSV</a> (every cohort, 24 months)</p>
|
<p class="small"><a href="/metrics/export/nrr-cohorts.csv">Download as CSV</a> (every cohort, every month)</p>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
<form method="post" action="/metrics/start" class="row small">
|
<form method="post" action="/metrics/start" class="row small">
|
||||||
|
|||||||
Reference in New Issue
Block a user