Created
August 31, 2012 11:01
-
-
Save morkeleb/3551461 to your computer and use it in GitHub Desktop.
A simple javascript file that attaches to jquerys ajax events and logs metrics based on server performance.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
$(document).ready(function() { | |
function saveTime(e, jqxhr, settings) { | |
settings.startTime = new Date().getTime(); | |
} | |
function registerTime(e, jqxhr, settings) { | |
_gaq.push(['_trackEvent', 'AjaxResponseTime', settings.type, settings.url.split('?')[0] ,(new Date().getTime() - settings.startTime), true]); | |
} | |
$(document).ajaxSend(saveTime); | |
$(document).ajaxComplete(registerTime); | |
$(document).ajaxError(function(event, xhr, settings) { | |
_gaq.push(['_trackEvent', 'AjaxError', xhr.status || xhr.statusText || 'Unknown', settings.url.split('?')[0],(new Date().getTime() - settings.startTime), true]); | |
}); | |
window.onerror = function(msg, url, lineno) { | |
_gaq.push(['_trackEvent', 'JavaScriptError', msg, url+":"+lineno, true]); | |
}; | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment