Pages

Thursday, May 19, 2011

Tracking Web Page Load and Site Speed Using Google Analytics

Recently I came across one of the interesting feature "Track Page Load Time" in Google Analytics APIs.

This feature provides the metrics on the Page Load Time within the Site Speed Report. This gives us a good opportunity to identifying slow loading pages and fix them for improving the Search Engine Ranking as load time is one of the factor in the page ranking.

Following is the code snippet for capturing the Page Load Time:

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview'],['_trackPageLoadTime']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>

Note that by default Site Speed Reports are not enabled. The function call _gaq.push['_trackPageLoadTime']) enables this report.

No comments: