You are here

santianoEvent - Page Load performance

Container Reference: 
Tag Type: 
Custom HTML
Tag Description: 
Reports on the time the pageURL took to load.
	<script>
// Evolution of Simo's tutorial on Page Load Times
// https://www.simoahava.com/analytics/page-load-time-universal-analytics/
// I Modified it to look good on Google Data Studio :)
// and added extra steps to show when we pages take more than 6 seconds to load

// !!! This depends on the santianoEvent Tag
  
var perfData = window.performance.timing;
var pageLoadTime = perfData.domComplete - perfData.navigationStart;
var loadTime = "";
var pageLoadTimeInSecs = parseFloat(pageLoadTime / 1000).toFixed(2);

if (pageLoadTime < 1000) { loadTime = "0-1 seconds"; }
else if (pageLoadTime < 2000) { loadTime = "1-2 seconds"; }
else if (pageLoadTime < 3000) { loadTime = "2-3 seconds"; }
else if (pageLoadTime < 4000) { loadTime = "3-4 seconds"; }
else if (pageLoadTime < 5000) { loadTime = "4-5 seconds"; }
else if (pageLoadTime < 6000) { loadTime = "5-6 seconds"; }
else if (pageLoadTime < 7000) { loadTime = "6-7 seconds"; }
else if (pageLoadTime < 8000) { loadTime = "7-8 seconds"; }
else if (pageLoadTime < 9000) { loadTime = "8-9 seconds"; }
else if (pageLoadTime < 10000) { loadTime = "9-10 seconds"; }
else { loadTime = "More than 10 seconds"; }

 
dataLayer.push({'event': 'santianoEvent',
                 'eventCommand': 'pageLoadPerformance',
                 'eventCategory': 'Page Load Performance', 
                 'eventAction': loadTime,
                 'eventLabel': {{pageURL}},
                 // 'eventSegment': pageLoadTimeInSecs +' seconds',
                 // 'eventPartition': undefined
                });

</script>