Posted By

cristinachetroi on 05/11/11


Tagged

Analytics


Versions (?)

Debuging JS with Google Analytics by Eduardo C.


 / Published in: JavaScript
 

URL: http://www.directperformance.com.br/en/javascript-debug-simples-com-google-analytics

  1. add the function trackerrorevent() to your tracking snippet
  2. call it when a Javascript Exception raises.
  1. <!-- GA Code Start -->
  2. <script type="text/javascript">
  3. var _gaq = _gaq || [];
  4. _gaq.push(
  5. ['_setAccount','UA-XXXXX-X'],
  6. ['_trackPageview']
  7. );
  8. function track_error_event (exception) {
  9. _gaq.push(['_trackEvent',
  10. 'Exception ' + (exception.name || 'Error'), //event category
  11. exception.message || exception, //event action
  12. document.location.href //event label
  13. ]);
  14. }
  15. (function() {
  16. var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  17. ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  18. var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  19. })();
  20. </script>
  21. <!-- GA Code End -->
  22.  
  23. <script type="text/javascript">
  24. try{
  25. //Javascript Code goes here
  26. //Raises Division by zero exception
  27. var i = 1/0;
  28. }
  29. catch(e){
  30. track_error_event(e);
  31. }
  32. </script>

Report this snippet  

You need to login to post a comment.