Return to Snippet

Revision: 45919
at May 11, 2011 02:10 by cristinachetroi


Initial Code
<!-- 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>

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

Initial Description
1. add the function track_error_event() to your tracking snippet 
2. call it when a Javascript Exception raises.

Initial Title
Debuging JS with Google Analytics by Eduardo C.

Initial Tags

                                

Initial Language
JavaScript