Skip to content

Instantly share code, notes, and snippets.

@metinsaylan
Forked from pwenzel/404-error-tracking.html
Created August 9, 2017 06:33
Show Gist options
  • Save metinsaylan/2873a7b81e51982d1c6fb6ca8e92d584 to your computer and use it in GitHub Desktop.
Save metinsaylan/2873a7b81e51982d1c6fb6ca8e92d584 to your computer and use it in GitHub Desktop.
Track 404 errors as events with Google Universal Analytics, capturing the referrer as well.
<script type="text/javascript">
// Track 404 errors with Universal Analytics
if($('body').hasClass('error404')) {
ga('send', 'event', 'error', '404', 'page: ' + document.location.pathname + document.location.search + ' ref: ' + document.referrer, {'nonInteraction': 1});
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment