Jump to content


Photo
* * * * * 1 votes

Client-Side Website Error Logging


  • Please log in to reply
1 reply to this topic

#1 Jill Whalen

Jill Whalen

    Administrator

  • Administrators
  • 70 posts

Posted 09 April 2012 - 10:19 AM

From ThetaBoard Blog: A way to see errors that your visitors may see on your site but don't tell you about. They have a number of solutions posted, but the Google Analytics one caught my eye:

You simply modify your "window.onerror" method to register an "Event" in Google Analytics:

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345678-1']);
_gaq.push(['_setDomainName', 'yoursite.com']);
_gaq.push(['_addIgnoredRef', 'yoursite.com']);
_gaq.push(['_trackPageview']);


(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);
})();

// ADD THIS AT THE BOTTOM OF YOUR GOOGLE ANALYTICS TRACKING CODE //
window.onerror = function(message, file, line) {
var sFormattedMessage = '[' + file + ' (' + line + ')] ' + message;
_gaq.push(['_trackEvent', 'Exceptions', 'Application', sFormattedMessage, null, true]);
}
</script>


In a few hours, you'll start seeing your errors show up in Google Analytics. You'll find your Events data in Content > Events.


Posted Image

#2 Joseph Chambers

Joseph Chambers

    New Member

  • Members
  • Pip
  • 1 posts

Posted 09 April 2012 - 03:30 PM

i love this, thank you!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users