Skip to content

Instantly share code, notes, and snippets.

@videoMonkey
Created June 3, 2013 16:47
Show Gist options
  • Save videoMonkey/5699503 to your computer and use it in GitHub Desktop.
Save videoMonkey/5699503 to your computer and use it in GitHub Desktop.

404 and 500 error reporting (before I forget)

The following snippet will make it easier to find content that is erroring:

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXXX-X']);
  _gaq.push(['_setDomainName', 'xxxxxxx.com']);
<% if(title.indexOf('404') != -1 ) { %>
  _gaq.push(['_trackPageview'],'/404.html/?url=' + document.location.pathname + document.location.search + '&ref=' + document.referrer]);
<% } else if ( title.indexOf('500') != -1 ) { %>
  _gaq.push(['_trackPageview'],'/500.html/?url=' + document.location.pathname + document.location.search + '&ref=' + document.referrer]);
<% } else { %>
  _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);
})();
</script>

Using this link I managed to set up email alerts for 404s

And I think that is it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment