Debugging JS with GA by Yahel Carmon


/ Published in: JavaScript
Save to your folder(s)

1. no need to wrap the (potentially) offending code in try/catch
2. use window.onerror:


Copy this code and paste it in your HTML
  1. <script>
  2. (function(){
  3. var old = window.onerror;
  4. window.onerror = function (msg, url, line) {
  5. if(typeof old==="function") { old(msg,url,line);}
  6. _gaq.push(['_trackEvent', 'Error Log', msg, url+'_'+line]);
  7. };
  8. }());
  9. </script>
  10. <script type="text/javascript">
  11.  
  12. var _gaq = _gaq || [];
  13. _gaq.push(['_setAccount', 'UA-XXXXXXXXX-Y']);
  14. _gaq.push(['_trackPageview']);
  15.  
  16. (function() {
  17. var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  18. ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  19. var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  20. })();
  21.  
  22. </script>

URL: http://dl.dropbox.com/u/397675/error_test.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.