Bounce rate is a metric that measures the percentage of single-page sessions on your website. In Google Analytics 4 (GA4), the concept of "bounce rate" has been replaced by "engagement rate." However, if you need to calculate a bounce rate similar to Universal Analytics for comparative purposes or specific analysis, you can do so using GA4 data. A "bounce" in this context is a session that was not engaged.
function calculateBounceRate() {
var totalSessionsInput = document.getElementById("totalSessions");
var engagedSessionsInput = document.getElementById("engagedSessions");
var resultDiv = document.getElementById("result");
var totalSessions = parseFloat(totalSessionsInput.value);
var engagedSessions = parseFloat(engagedSessionsInput.value);
if (isNaN(totalSessions) || isNaN(engagedSessions)) {
resultDiv.innerHTML = "Please enter valid numbers for Total Sessions and Engaged Sessions.";
return;
}
if (totalSessions <= 0) {
resultDiv.innerHTML = "Total Sessions must be greater than zero.";
return;
}
if (engagedSessions totalSessions) {
resultDiv.innerHTML = "Engaged Sessions must be between 0 and Total Sessions.";
return;
}
var bouncedSessions = totalSessions – engagedSessions;
var bounceRate = (bouncedSessions / totalSessions) * 100;
resultDiv.innerHTML = "