Repository navigation
feat(analytics): add cohort retention and churn HTTP endpoints - #1844
Merged
github-actions[bot] merged 2 commits intoOct 19, 2026
Merged
github-actions[bot] merged 2 commits into
github-actions[bot] merged 2 commits into
Conversation
Implements issue Smartdevs17#1755. The existing CohortService and AnalyticsDashboardApi already contained all cohort/churn/retention logic — this change exposes that logic over HTTP and adds a test suite for the routing layer. New files backend/analytics/cohortAnalyticsRouter.ts HTTP router mounted at /analytics/cohorts. Routes: GET /analytics/cohorts?merchantId=…&granularity=month|week Cohort table grouped by subscriber signup period. GET /analytics/cohorts/retention?merchantId=… Day 1/7/30/60/90 retention curve. GET /analytics/cohorts/churn?merchantId=…&from=<ms>&to=<ms> Revenue churn vs logo churn breakdown for a period. GET /analytics/cohorts/export?merchantId=…&granularity=…&format=csv|pdf Downloadable cohort report (CSV or PDF). GET /analytics/cohorts/mrr?merchantId=… MRR / ARR / ARPU / LTV summary. POST /analytics/cohorts/subscribers Upsert a subscriber record into the in-memory store. backend/analytics/__tests__/cohortAnalyticsRouter.test.ts 17 unit tests; all passing. Modified backend/server.ts — import + route block for /analytics/cohorts placed before the 404 fallback. Closes Smartdevs17#1755
|
@retkatmun Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1755
Summary
Churn was not measured and cohort retention views did not exist over HTTP. The underlying
CohortServiceandAnalyticsDashboardApialready contained the full cohort/churn/retention logic — this change wires it to the HTTP layer and adds a test suite.Changes
New files:
backend/analytics/cohortAnalyticsRouter.ts/analytics/cohorts. Six routes (see below).backend/analytics/__tests__/cohortAnalyticsRouter.test.tsModified:
backend/server.ts— import + route block for/analytics/cohorts, placed before the 404 fallback.Endpoints
GET/analytics/cohorts?merchantId=…&granularity=month|weekGET/analytics/cohorts/retention?merchantId=…GET/analytics/cohorts/churn?merchantId=…&from=<ms>&to=<ms>GET/analytics/cohorts/export?merchantId=…&granularity=…&format=csv|pdfGET/analytics/cohorts/mrr?merchantId=…POST/analytics/cohorts/subscribersDesign decisions
CohortService,AnalyticsDashboardApi,RetentionCalculator, andcohortReportExportalready existed with full cohort-by-signup, retention curve, churn breakdown, and export support. This PR is purely a wiring layer.cohortTableToCsv/cohortTableToPdfhelpers. The?format=query param selects between them; CSV is the default.month(default) andweekare both supported; weekly cohorts use ISO-8601 week keys.POST /analytics/cohorts/subscriberslets callers upsert records into the in-memorySubscriberRecordRepository, making the endpoint self-contained until a database-backed repository is wired in.Acceptance criteria (from issue)
/export?format=csv|pdfTesting
Covers: non-matching path fallthrough, missing
merchantId→ 400, wrong method → 405, cohort table (monthly + weekly), retention curve fields, churn breakdown, MRR/ARR/ARPU/LTV, CSV/PDF export headers and body, subscriber upsert and invalid JSON.