Skip to content

Instantly share code, notes, and snippets.

@pwenzel
Created February 20, 2015 05:19
Show Gist options
  • Save pwenzel/eb4f04552ef410f60406 to your computer and use it in GitHub Desktop.
Save pwenzel/eb4f04552ef410f60406 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>
@bjorn-ali-goransson
Copy link

@jnachtigall undefined is unnecessary, Google themselves do not use it in their examples. But you're correct on the "1" thing.

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