Google Analytics-JS Error Tracking Using Google GTM Events

javascript error tracking

What? How? Why? Was that your reaction when you read the title of my blog? Well, as a developer, it is important for us that the code we have written, should not break or should not be blocked by other scripts. Users are very creative these days – if at all tester misses some use cases, users will encounter some of those for sure. So, you need to make sure that your website is working well with every release and every publish of GTM.

It gives me immense pleasure to introduce Google Tag Manager’s unsung hero “Javascript error tracking feature”. GTM has this beautiful trigger named JavaScript Error ( also known as gtm.pageError dataLayer event ) enabled when any JS error occurs on the page.

Google Tag ManagerImage: javascript inbuilt variable in GTM

And to complement that trigger, it has built-in variables like

  • Error Message ( also known as gtm.errorLineNumber dataLayer variable : It will give value which represents the error description in string format
  • Error Url ( also known as gtm.errorMessage dataLayer variable ): It will give third party js file URL or any file URL which from which error occurred.
  • Error Line ( also known as gtm.errorUrl dataLayer variable ): This is an integer value that shows which line number has caused an error.

When javascript error occurs on site, GTM pushes a dataLayer which contains above-mentioned information with it and voila, you can now track errors in Analytics. Resolve those errors to improve the website performance.

Javascript Error Tracking

GIF: js error tag configuration

Precautions while implementing JavaScript Error Tracking:
  • Create a separate view to record these errors. Exclude them from Master view and the reason behind creating a new view for such tracking is that it will affect the actual user data by adding javascript error events in user’s session.
  • You can also restrict the JavaScript Error tracking to fire on specific conditions only
Usage of JavaScript Error Tracking:
  • Set alerts if your error rate reaches tocertainlevel. This will enable you tominimisethe risk in case of any important functionality on your website breaks down or gets affected via a third party script.Google Analytics Javascript error tracking

Image: Custom Alert for javascript error in google analytics

  • Know which third party scripts are causing issues. Fix them. Below screenshot shows which files are causing these errors.dataLayer variable in GTM

    Image: Custom Alert for javascript error in google analytics

JavaScript Error tracking provides a whole new avenue in which we can use data in Google Analytics. This data will help you identify glitches on the website and you will get a notification over mail or on phone based on the configuration set in custom alerts. The faster you act in such cases, the less damage takes place. Most importantly, improve your website performance by resolving the errors which block important scripts execution.

So, start tracking errors on website and get to know the culprits who are affecting your website performance and most importantly, act faster in disaster cases. Feel free to reach out to us in case of any query or leave a comment in the section below. We also provide Google Tag Manager & Google Analytics

, , , ,
Previous Post
Google Optimize 360 : The Power House of Personalization
Next Post
How to implement Google Tag Manager for Android

2 Comments. Leave new

  • A bit new to Google Analytics. I’ve created a new GTM JS Error tag and created a a goal in the new view. JS error tracking works correctly and I am able to see the events in GA. However as per your comment “Exclude them from Master view” I’m unsure how i can exclude it from the master view. Any help will be greatly appreciated.


Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed