This calculator helps you determine your conversion rate based on the number of visitors and the number of conversions. A conversion can be any desired action a visitor takes, such as making a purchase, signing up for a newsletter, filling out a form, or downloading a resource.
function calculateConversionRate() {
var visitorsInput = document.getElementById("totalVisitors");
var conversionsInput = document.getElementById("totalConversions");
var resultDiv = document.getElementById("result");
var totalVisitors = parseFloat(visitorsInput.value);
var totalConversions = parseFloat(conversionsInput.value);
if (isNaN(totalVisitors) || isNaN(totalConversions)) {
resultDiv.innerHTML = "Please enter valid numbers for both visitors and conversions.";
return;
}
if (totalVisitors <= 0) {
resultDiv.innerHTML = "Total number of visitors must be greater than zero.";
return;
}
if (totalConversions < 0) {
resultDiv.innerHTML = "Total number of conversions cannot be negative.";
return;
}
var conversionRate = (totalConversions / totalVisitors) * 100;
resultDiv.innerHTML = "Your Conversion Rate is: " + conversionRate.toFixed(2) + "%";
}
#conversion-rate-calculator {
font-family: sans-serif;
border: 1px solid #ccc;
padding: 20px;
border-radius: 8px;
max-width: 400px;
margin: 20px auto;
background-color: #f9f9f9;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
.form-group input[type="number"] {
width: calc(100% – 12px);
padding: 8px;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 15px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #45a049;
}