When analyzing SaaS growth metrics—such as Monthly Recurring Revenue (MRR) movement, retention decay curves, and customer churn—founders and engineers usually rely on third-party analytical platforms. However, sending unencrypted billing ledgers, customer IDs, and transaction amounts to external cloud servers introduces significant privacy and compliance liabilities.
In this article, we examine how to perform SaaS cohort retention calculations and MRR waterfall breakdowns 100% inside the browser memory using client-side JavaScript.
The Architecture of In-Browser Cohort Analysis
To construct an investor-ready retention matrix locally, your application must process raw subscription logs without backend compute.
1. Normalizing Transaction Records
Raw CSV billing dumps typically contain data formatted like this:
[ { "customer_id": "usr_101", "timestamp": "2024-01-15", "mrr": 49.00 }, { "customer_id": "usr_101", "timestamp": "2024-02-15", "mrr": 49.00 }, { "customer_id": "usr_102", "timestamp": "2024-01-20", "mrr": 99.00 }, { "customer_id": "usr_102", "timestamp": "2024-02-20", "mrr": 149.00 } ] 2. Grouping into Time Cohorts
First, establish each user's signup month ($C_0$). Then track their subscription presence across subsequent periods ($M_n$).
function generateCohorts(transactions) { const customerFirstSeen = {}; const cohorts = {}; // Step 1: Identify Cohort Assignment (C0) transactions.forEach(tx => { const period = tx.timestamp.slice(0, 7); // YYYY-MM if (!customerFirstSeen[tx.customer_id] || period < customerFirstSeen[tx.customer_id]) { customerFirstSeen[tx.customer_id] = period; } }); // Step 2: Aggregate active subscriptions per period transactions.forEach(tx => { const cohort = customerFirstSeen[tx.customer_id]; const period = tx.timestamp.slice(0, 7); if (!cohorts[cohort]) cohorts[cohort] = {}; if (!cohorts[cohort][period]) cohorts[cohort][period] = { logos: new Set(), mrr: 0 }; cohorts[cohort][period].logos.add(tx.customer_id); cohorts[cohort][period].mrr += tx.mrr; }); return cohorts; } Computing MRR Movements (The Waterfall Model)
Retention isn't just about logo retention percentages; revenue dynamics govern SaaS survival. An offline engine needs to isolate 4 core financial vectors per period:
- New MRR: Revenue from first-time subscribers.
- Expansion MRR: Existing users upgrading their tier.
- Contraction MRR: Existing users downgrading.
- Churned MRR: Users dropping to zero active subscription value.
function calculateMRRWaterfall(currentPeriodData, previousPeriodData) { let newMRR = 0; let expansionMRR = 0; let contractionMRR = 0; let churnedMRR = 0; for (const [userId, currentVal] of Object.entries(currentPeriodData)) { const prevVal = previousPeriodData[userId] || 0; if (prevVal === 0) { newMRR += currentVal; } else if (currentVal > prevVal) { expansionMRR += (currentVal - prevVal); } else if (currentVal < prevVal) { contractionMRR += (prevVal - currentVal); } } for (const [userId, prevVal] of Object.entries(previousPeriodData)) { if (!currentPeriodData[userId]) { churnedMRR += prevVal; } } return { newMRR, expansionMRR, contractionMRR, churnedMRR }; } Zero-Cloud Privacy Advantages
Executing this math entirely within the client-side DOM runtime provides several structural advantages:
- Data Sovereignty: Financial ledgers and customer PII never touch external infrastructure.
- Instant Re-rendering: Toggling between Retention %, Logo Counts, and Revenue ($) updates instantaneously.
- Offline Execution: Operates smoothly in isolated enterprise networks or offline environments.
Try the Interactive Tooling
If you need an out-of-the-box solution that transforms raw billing dumps into visual heatmaps and audit reports, check out:
- 🌐 Live Web Demo: Try CohortLens Free App
- 📦 Production Build: Get CohortLens Pro on Gumroad
Processing SaaS financial metrics locally keeps your business data completely secure while giving you immediate clarity on your retention dynamics.