Is it possible to measure the number of visitors abandoning before website fully loads?

Yes, It is possible. We can achieve this by using the performance timing API to first calculate the time it takes for the website to fully load by adding a custom listener that will fire on All Pages Trigger:


<script>
window.addEventListener('load', function() {
    var loadTime = window.performance.timing.loadEventEnd - window.performance.timing.navigationStart;
    dataLayer.push({'event': 'pageFullyLoaded', 'loadTime': loadTime});
});
</script>

Next, we can use events like beforeunload to track the user abandonment by creating another listener:

<script>
window.addEventListener('beforeunload', function() {
    if (!window.pageFullyLoaded) {
        dataLayer.push({'event': 'pageAbandoned', 'reason': 'beforeLoad'});
    }
});

window.addEventListener('load', function() {
    window.pageFullyLoaded = true;
});
</script>

Now that we have the listeners in place, we can use dataLayer variables to capture the loadTime and the reason parameters from the custom Listener dataLayer push using Google Tag Manager (GTM) and send this data to Google Analytics 4 (GA4) or another tools of your likings.

Don't miss out when new resources launch

Our customer analytics experts share wisdom only once a month

Share now

We are a digital analytics consultancy that helps businesses turn customer and marketing data into clear, actionable insights. We empower teams to optimize performance, make smarter decisions, and drive measurable growth.