Calculate Your ROI
class CostPerLeadCalculator {
constructor() {
this.data = {};
this.currentStep = 0;
this.steps = [
{ question: "How much do you spend on lead generation per month?", key: "monthlySpend" },
{ question: "How many leads do you generate per month?", key: "leadsPerMonth" },
{ question: "How many SDRs (Sales Reps) do you have?", key: "numSDRs" },
{ question: "What is their average monthly salary (including commissions)?", key: "sdrSalary" },
{ question: "How much do you spend on tools and software per month?", key: "softwareCost" }
];
this.init();
}
init() {
this.chatContainer = document.createElement("div");
this.chatContainer.id = "cpl-calculator";
this.chatContainer.innerHTML = `<div id='chat-box'></div><input id='chat-input' type='text' placeholder='Type your answer...'><button id='chat-submit'>Submit</button>`;
document.body.appendChild(this.chatContainer);
this.chatBox = document.getElementById("chat-box");
this.chatInput = document.getElementById("chat-input");
this.chatSubmit = document.getElementById("chat-submit");
this.chatSubmit.addEventListener("click", () => this.processAnswer());
this.chatInput.addEventListener("keypress", (event) => {
if (event.key === "Enter") {
this.processAnswer();
}
});
this.displayMessage("Let's calculate your cost per lead!", "bot");
this.nextStep();
}
displayMessage(message, sender) {
const msgDiv = document.createElement("div");
msgDiv.className = sender;
msgDiv.innerText = message;
this.chatBox.appendChild(msgDiv);
this.chatBox.scrollTop = this.chatBox.scrollHeight;
}
nextStep() {
if (this.currentStep < this.steps.length) {
this.displayMessage(this.steps[this.currentStep].question, "bot");
} else {
this.calculateCPL();
}
}
processAnswer() {
const answer = this.chatInput.value.trim();
if (!answer) return;
this.displayMessage(answer, "user");
// Ensure only valid numbers are processed
const cleanedAnswer = answer.replace(/,/g, "").trim(); // Remove commas
const parsedValue = parseFloat(cleanedAnswer);
if (isNaN(parsedValue) || parsedValue <= 0) {
this.displayMessage("Please enter a valid positive number.", "bot");
this.chatInput.value = "";
return;
}
this.data[this.steps[this.currentStep].key] = parsedValue;
this.chatInput.value = "";
this.currentStep++;
this.nextStep();
}
calculateCPL() {
const { monthlySpend = 0, leadsPerMonth = 1, numSDRs = 0, sdrSalary = 0, softwareCost = 0 } = this.data;
const totalCost = monthlySpend + (numSDRs * sdrSalary) + softwareCost;
const costPerLead = leadsPerMonth > 0 ? (totalCost / leadsPerMonth).toFixed(2) : "N/A";
this.displayMessage(`Your cost per lead is approximately $${costPerLead}.`, "bot");
this.displayMessage("Want to lower your CPL? Let's talk!", "bot");
}
}
// Initialize the calculator after the page fully loads
document.addEventListener("DOMContentLoaded", function() {
new CostPerLeadCalculator();
});