/ Published in: JavaScript
1. add the function track_error_event() to your tracking snippet
2. call it when a Javascript Exception raises.
2. call it when a Javascript Exception raises.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<!-- GA Code Start --> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push( ['_setAccount','UA-XXXXX-X'], ['_trackPageview'] ); function track_error_event (exception) { _gaq.push(['_trackEvent', 'Exception ' + (exception.name || 'Error'), //event category exception.message || exception, //event action document.location.href //event label ]); } (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> <!-- GA Code End --> <script type="text/javascript"> try{ //Javascript Code goes here //Raises Division by zero exception var i = 1/0; } catch(e){ track_error_event(e); } </script>
URL: http://www.directperformance.com.br/en/javascript-debug-simples-com-google-analytics