This content originally appeared on DEV Community and was authored by Michael
As developers and builders, we live in a world of logic, data, and optimization. We refactor code to be more efficient, we A/B test features for better engagement, and we scrutinize server costs to the penny. So why does marketing ROI often feel like a black box of fuzzy metrics and gut feelings?
It doesn’t have to.
Calculating B2B marketing ROI is just another data problem. It’s about tracking the right inputs, applying the right formulas, and building a system to measure what matters. Let’s ditch the vague spreadsheets and write some code to understand the real return on our marketing budget.
The Flaw in Simple ROI
Your first instinct might be to use the classic ROI formula:
ROI = (Net Profit - Marketing Cost) / Marketing Cost
For selling a simple product, this works. But in B2B, where sales cycles can last months and customer relationships span years, this formula is dangerously misleading. It doesn’t account for the long-term value of a customer. We need a more sophisticated model.
Your Core Marketing KPIs: The Big Three
Think of these metrics as the public methods of your MarketingAnalytics
class. They are the essential calculations you need to determine the health of your customer acquisition engine.
1. Customer Acquisition Cost (CAC)
This is the total cost of convincing a lead to become a customer. It’s your ‘cost per new User()
‘. To calculate it, you need to sum up all your marketing and sales expenses over a given period and divide by the number of new customers acquired in that same period.
Formula:
CAC = (Total Marketing Spend + Total Sales Spend) / Number of New Customers Acquired
Let’s model this in JavaScript:
/**
* Calculates the Customer Acquisition Cost (CAC).
* @param {number} marketingSpend - Total marketing expenses for a period.
* @param {number} salesSpend - Total sales expenses for the same period.
* @param {number} newCustomers - Number of new customers acquired.
* @returns {number} The cost to acquire a single customer.
*/
function calculateCAC(marketingSpend, salesSpend, newCustomers) {
if (newCustomers === 0) {
return Infinity; // Avoid division by zero
}
return (marketingSpend + salesSpend) / newCustomers;
}
// Example:
const totalMarketingCost = 5000; // e.g., ads, content creation
const totalSalesCost = 10000; // e.g., salaries, commissions
const customersThisQuarter = 15;
const myCAC = calculateCAC(totalMarketingCost, totalSalesCost, customersThisQuarter);
console.log(`Our CAC is: $${myCAC.toFixed(2)} per customer.`); // Output: Our CAC is: $1000.00 per customer.
2. Customer Lifetime Value (LTV)
LTV represents the total revenue you can reasonably expect from a single customer account throughout your business relationship. In B2B SaaS, this is the holy grail. A high LTV means recurring revenue, stability, and growth.
Formula:
LTV = (Average Revenue Per Account * Gross Margin) / Customer Churn Rate
- Average Revenue Per Account (ARPA): What you charge, on average, per month or year.
- Gross Margin: The percentage of revenue left after accounting for the cost of goods sold (COGS). For SaaS, this is often high (e.g., 80-90%) because server costs are relatively low per customer.
- Customer Churn Rate: The percentage of customers who cancel their subscriptions in a given period.
/**
* Calculates the Customer Lifetime Value (LTV).
* @param {number} arpa - Average Revenue Per Account (per period, e.g., monthly).
* @param {number} grossMargin - The gross margin percentage (e.g., 0.8 for 80%).
* @param {number} churnRate - The customer churn rate percentage (e.g., 0.05 for 5%).
* @returns {number} The total predicted value of a customer.
*/
function calculateLTV(arpa, grossMargin, churnRate) {
if (churnRate === 0) {
// A theoretical case of zero churn could imply infinite LTV
// In reality, you'd cap this at a reasonable lifetime (e.g., 10 years)
// For this function, let's return a very high number as a signal.
return arpa * grossMargin * 120; // Example: 10 year lifetime
}
const lifetimeValue = (arpa * grossMargin) / churnRate;
return lifetimeValue;
}
// Example:
const monthlyARPA = 250;
const margin = 0.85; // 85% Gross Margin
const monthlyChurn = 0.02; // 2% monthly churn
const myLTV = calculateLTV(monthlyARPA, margin, monthlyChurn);
console.log(`Our LTV is: $${myLTV.toFixed(2)}.`); // Output: Our LTV is: $10625.00.
3. The LTV to CAC Ratio
This is it. This is the single most important metric for determining marketing ROI and the long-term viability of a B2B business. It tells you how much value you’re generating for every dollar you spend acquiring a customer.
- < 1:1 -> You’re losing money with every new customer. The business model is broken.
- 1:1 -> You’re only breaking even. Unsustainable.
- 3:1 -> This is widely considered the gold standard. You have a healthy, scalable business.
- > 5:1 -> You’re doing great, but you might actually be under-investing in marketing and could grow faster.
/**
* Analyzes the LTV to CAC ratio.
* @param {number} ltv - The Customer Lifetime Value.
* @param {number} cac - The Customer Acquisition Cost.
* @returns {object} An object containing the ratio and a health assessment.
*/
function analyzeLtvCacRatio(ltv, cac) {
if (cac === 0 || cac === Infinity) {
return { ratio: null, assessment: 'CAC is invalid.' };
}
const ratio = ltv / cac;
let assessment = 'Concerning';
if (ratio >= 5) {
assessment = 'Excellent (Consider scaling spend)';
} else if (ratio >= 3) {
assessment = 'Healthy & Sustainable';
} else if (ratio >= 1) {
assessment = 'Needs Improvement';
}
return {
ratio: ratio.toFixed(2),
assessment: assessment
};
}
// Using our previous results:
const healthCheck = analyzeLtvCacRatio(myLTV, myCAC);
console.log(`LTV:CAC Ratio: ${healthCheck.ratio}:1`); // Output: LTV:CAC Ratio: 10.63:1
console.log(`Assessment: ${healthCheck.assessment}`); // Output: Assessment: Excellent (Consider scaling spend)
Tying it All Together
Now, you can stop guessing about your marketing budget. Instead of asking “How much should we spend?”, you can ask “How many customers can we profitably acquire at our current CAC?”
By tracking these KPIs, you transform marketing from an expense into a predictable growth engine. You can confidently tell your team or your investors, “For every $1000 we put into this channel, we get back $10,630 over the customer’s lifetime.”
That’s a conversation every developer, founder, and engineer should know how to have. It’s not just marketing; it’s the core logic of a sustainable business.
Originally published at https://getmichaelai.com/blog/calculating-b2b-marketing-roi-metrics-and-formulas-you-need-
This content originally appeared on DEV Community and was authored by Michael