:::: MENU ::::

How to track remote javascript errors using Google Analytics?

JavaScript Error Tracking from remote user browser using Google Analytics

Although you can code and debug carefully your javascript code using “use strict” and try catch statement, there might be a situation where unexpected errors can occur for several reasons.

  • Collision of namespace or variables.
  • Scripts timeouts
  • Syntax errors due to encoding or escaping.
  • Thirdpary plugin (in wordpress, joomla, drupal) may creating javascript issues.
  • You may not have tested your in mobile browser like iphone or android.

So, here are the tips to get error logged into your google analytics account using event tracking.

window.onerror function

It’s an event handler for runtime javascript errors.

window.onerror() paramteters

  1. First one is – Error String
  2. Second one is – Error document or script URL
  3. Third one is – Line Number
  4. Forth one is – Column Number (may not support in all browser)
  5. Fifth one is – Stack Trace (may not support in all browser)

Basic Error Tracking Syntax

Error Tracking using Google Analytics

Viewing client side javascript errors with Google Event Tracking

  • Login to your google analytics
  • In Left Navigation panel find Behavior
  • Click Events then Overview
  • You  will find Exceptions in Event Category, Click on it
  • Then new screen will appear, find Event Label within Primary Dimension filters and click it.
  • There you will get all errors. See demo screenshot below

javascript_errors_in_ga

Creating Custom Report to get operating system / browser / its version wise error breakup

  • From top orange bar in google analytics, find Customization next to Reporting tab.
  • Click + New Custom Report
  • General Information = Error Tracking
  • Report Content => Name = JavaScript Errors
  • Metric Group = Total Events
  • Dimensions Drilldowns =>
    Event Category > Operating System > Browser > Browser Version > Event Label
  • Finally Click Save.

error_tracking_ga

 

 

Viewing Custom Report

  • Again select Customization tab from top orange navigation bar.
  • Select and click Error Tracking
  • Click Exceptions
  • Click Operating System you want to check errors for.
  • Then click Browser and then its version
  • Now errors are precisely breakup by browser version so go ahead and fix your javascript error for that particular browser.

error_tracking_filter

Getting Error Alert from Google Analytics Intelligence Event feature

You can get daily email from google analytics for your custom alerts. So, lets create daily events alert for above javascript event tracking.

javascript_error_alert

  • Navigate to Intelligence Event (in left menu)
  • Click Daily Events and find + Create a Custom Alert
  • Set Alert Name = javascript errors
  • Period = Day
  • Alert Conditions => Event Category [Matches exactly] Exceptions
    Alert me when => Total Events [Is greater than] 10
  • Save Alert

ga_alert

Now you should get daily javascript error in your email. You can even setup your mobile phone to receive message about above report in above configuration.

Wrapping Up : How to use above code in your website?


So, what do you think ?

  •