diff --git a/internal/metrics/export.go b/internal/metrics/export.go index 6eca530..d48829c 100644 --- a/internal/metrics/export.go +++ b/internal/metrics/export.go @@ -61,14 +61,15 @@ func Export(w io.Writer, d *db.DB, name string, now time.Time) error { } case "nrr-cohorts": 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)) } - for k := 0; k <= 24; k++ { + for k := 0; k <= span; k++ { head = append(head, fmt.Sprintf("month_%d_mrr", k)) } 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)} for _, r := range c.Retained { 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": - 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 { return err } 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)) } write(head) diff --git a/internal/web/metrics.go b/internal/web/metrics.go index ff90eee..f4cee66 100644 --- a/internal/web/metrics.go +++ b/internal/web/metrics.go @@ -54,8 +54,9 @@ func (s *Server) renderMetrics(w http.ResponseWriter, r *http.Request, errMsg st "Now": model.Last(), "Recent": model.Recent(13), "Bars": bars(model, 24), - "Cohorts": model.Cohorts(12, 12), - "Span": make([]int, 13), + // Every cohort, each followed to the latest month. + "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) 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 { 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", + "CLV": clv, "Cohorts": cohorts, "Span": make([]int, span+1), "Profit": r.URL.Query().Get("view") == "profit", "Currency": model.Currency, }}) } diff --git a/internal/web/static/app.css b/internal/web/static/app.css index 6a20c9b..e10f6a7 100644 --- a/internal/web/static/app.css +++ b/internal/web/static/app.css @@ -411,6 +411,12 @@ svg.chart rect { fill: hsl(var(--primary)); opacity: 0.85; } svg.chart rect:hover { opacity: 1; } 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; } +/* 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.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). */ diff --git a/internal/web/templates/metrics-clv.html b/internal/web/templates/metrics-clv.html index dd015d9..6813764 100644 --- a/internal/web/templates/metrics-clv.html +++ b/internal/web/templates/metrics-clv.html @@ -33,6 +33,6 @@ {{if $d.Profit}}{{range .Margin}}
Download as CSV (every cohort, 24 months)
+Download as CSV (every cohort, every month)
{{end}} {{end}}{{end}} diff --git a/internal/web/templates/metrics.html b/internal/web/templates/metrics.html index f2ce922..646280d 100644 --- a/internal/web/templates/metrics.html +++ b/internal/web/templates/metrics.html @@ -65,9 +65,12 @@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.
| First paid | Customers | Starting MRR | {{range $i, $_ := $d.Span}}{{$i}} | {{end}}
|---|---|---|---|
| {{.Month}} | {{.Customers}} | {{usd .Start}} | {{$co := .}}{{range $k, $r := .Retained}}{{if ge $r 0.0}}{{pct $r}} {{usd (index $co.MRR $k)}}{{end}} | {{end}}
| {{.Month}} | {{.Customers}} | {{usd .Start}} | {{range .Retained}}{{if ge . 0.0}}{{pct .}}{{end}} | {{end}}
| {{if ge . 0.0}}{{usd .}}{{end}} | {{end}}
Download as CSV (every cohort, 24 months)
+Download as CSV (every cohort, every month)
{{end}}