In the fast-paced world of SaaS, data isn't just important—it's everything. Your ability to measure, understand, and react to key business metrics determines your growth trajectory. Yet, for many companies, tracking Key Performance Indicators (KPIs) is a messy, manual process stuck in spreadsheets, updated weekly, and prone to human error.
What if you could treat your business metrics with the same rigor and automation as your application code?
This is the core idea behind KPIs as Code: defining your most critical business logic in version-controlled files and using an API to automate tracking and analysis. This transforms static reports into dynamic, data-driven services that provide real-time insight and trigger immediate action.
Let's explore the five most critical KPIs every SaaS business should stop calculating by hand and start automating as code.
MRR is the lifeblood of any subscription business. It represents the predictable revenue you can expect to receive every month, providing a clear measure of your company's financial health and growth momentum.
The Old Way: Manually exporting data from Stripe or your billing system, combining it with new sales from your CRM, cleaning it up in a spreadsheet, and hoping the final number is correct. This process is slow and often a week out of date.
The "KPIs as Code" Way: Define your MRR calculation once and let automation do the work. Your KPI definition can connect directly to your production database or billing API, run a SUM() query on active subscriptions on a schedule (e.g., every hour), and log the result.
You can also track changes or new contributions to MRR with a simple API call when a customer subscribes or upgrades.
import { kpis } from 'kpis.do';
// A new customer signs up for the Pro plan
await kpis.track({
name: 'monthly-recurring-revenue',
value: 99.00, // The value of the new subscription
// Use dimensions to slice & dice your data
dimensions: {
changeType: 'new-business',
plan: 'Pro',
region: 'EMEA'
}
});
While MRR measures growth, churn measures leakage. Your churn rate—the percentage of customers who cancel their subscriptions in a given period—is a critical indicator of customer satisfaction and product-market fit. High churn can silently sink an otherwise growing business.
The Old Way: At the end of the month, count the number of customers who canceled. Divide that by the number of customers you had at the start of the month. The result is a single, lagging number with little context about why it happened.
The "KPIs as Code" Way: Automate the calculation to get a real-time view of churn. More importantly, set up automated thresholds. If your churn rate for a specific customer segment spikes unexpectedly, KPIs.do can trigger an immediate alert.
import { kpis } from 'kpis.do';
// Track a churn event
const result = await kpis.track({
name: 'customer-churn-rate',
value: 1, // Represents one churned customer
dimensions: {
plan: 'Enterprise',
reason: 'non-renewal'
}
});
// An alert could be triggered if a threshold is crossed
console.log(result.alerts);
// Output: [{ name: 'High Enterprise Churn Alert', severity: 'critical' }]
LTV represents the total revenue you can expect to generate from a single customer throughout their relationship with your company. It's a forward-looking metric that helps you make smarter decisions about marketing spend, sales efforts, and customer retention.
The Old Way: A complex formula (often Average Revenue Per Account / Customer Churn Rate) calculated in a spreadsheet using other manually-derived metrics. It's rarely updated and almost impossible to segment effectively.
The "KPIs as Code" Way: With automated tracking of revenue and churn, LTV can become a dynamic, calculated KPI within the platform. By tracking the underlying metrics as code, your LTV is always up-to-date and can be automatically segmented by plan, acquisition channel, or any other dimension you track.
// LTV is often calculated from other KPIs, but you can track it directly
await kpis.track({
name: 'customer-ltv',
value: 4500, // Newly calculated LTV for a segment
dimensions: {
segment: 'smb',
acquisitionChannel: 'organic'
}
});
If LTV tells you how much a customer is worth, CAC tells you how much it costs to get them. This includes all your sales and marketing expenses—from ad spend to salaries—divided by the number of new customers acquired in a period.
The Old Way: A massive headache. You have to pull spending data from Google Ads, LinkedIn, Facebook, your marketing automation platform, and your payroll system. Getting an accurate, timely CAC is one of the most challenging manual reporting tasks.
The "KPIs as Code" Way: Use a performance tracking API to centralize cost data. Your different systems can push their spending data to a single endpoint. Your KPI definition then automates the calculation against the number of new customers acquired, giving you a near-real-time view of your acquisition efficiency by channel.
// Log marketing spend from a specific channel for the day
await kpis.track({
name: 'customer-acquisition-cost',
// This could add to a 'cost' accumulator for the CAC KPI
value: 500.00,
dimensions: {
spendType: 'marketing-ads',
channel: 'linkedin'
}
});
This is the ultimate measure of your SaaS business model's viability. It compares a customer's lifetime value to the cost of acquiring them. A healthy ratio (typically 3:1 or higher) indicates you have a profitable engine for growth.
The Old Way: A formula that's a perfect storm of manual reporting woes. It relies on two other metrics (LTV and CAC) that are themselves difficult to calculate, often out-of-date, and based on different data sets.
The "KPIs as Code" Way: This is where an agentic platform shines. Since your LTV and CAC are already defined and automated as code, you can create a third KPI, ltv-to-cac-ratio, that simply references the other two. It's a computed metric that runs automatically whenever its inputs change. This is the essence of metrics as code—building reliable, complex insights from simple, automated building blocks. You move from calculation to composition.
Treating KPIs as code isn't just about better dashboards. It's about closing the loop between insight and action. With a platform like KPIs.do, you can build powerful workflows:
Manual KPI tracking is a tax on your team's time and a drag on your company's agility. By embracing KPI automation and the "KPIs as Code" philosophy, you can free your team to focus on what truly matters: making data-driven decisions that improve performance.
Ready to transform your key metrics into automated, actionable services? Explore KPIs.do and start defining your performance as code today.