Blog

Home > Analytics FAQs > Is it possible to measure the number of visitors abandoning before website fully loads?

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.

Share:

Data that Moves Your Business

Connect with Marketlytics

Join 120,000+ Marketers

Stay ahead with expert insights on marketing analysis, data-driven strategies, and industry trends.

Omair

Revenue Growth Analyst
Data Unification Specialist, previously at a leading Ecommerce Giant

Case Studies

Discover our latest success stories
and see how innovative strategies
drive measurable results.

Get a Free Attribution Dashboard

Gain clear insights into what’s
driving conversions and optimize
your marketing spend with ease.

Are you Ready to Fast Track your Marketing Attribution Decisions and Maximize your ROI?

Businesses that leverage automated marketing
attribution see a 20-30% improvement in ad
spend efficiency.