The process is actually really simple. Much easier than it was in the previous Google Tag Manager interface.
By the way, uncaught refers to an error which hasn’t been captured and handled by any of the scripts on the page. The most common way to catch an error is to use
Anyway, you start by making sure the Built-In Variables are activated.
If you’re curious about these Built-In Variables, check the relevant section of my Variable Guide For Google Tag Manager.
Next, head on over to Triggers, and create a new one:
Finally, you need a Google Analytics Event Tag, which collects and concatenates all this information. Here’s what I use:
An example result using these settings would be something like:
Event Action: Uncaught ReferenceError: appear is not defined
Event Label: 1255:
I’m sending the event as Non-Interaction: True, because it’s not a user interaction, and I don’t want it to be counted as such.
And that’s it for the implementation!
Now, there are some things you might want to consider when implementing this on your own website. The next chapter will tackle these issues.
1. Track errors as Google Analytics Goals
2. Use Environments or the Debug Mode
This way only errors triggered by your testers and developers will be recorded. The downside, of course, is that it’s not an authentic setting, and no matter how much you test and debug, you will always miss some things.
3. Add manual sampling
Another way to prevent every single error from dispatching is to manually sample the hits that are sent to Google Analytics. You could, for example, only let the Trigger fire for 50% of recorded errors. You can use the Random Number Built-In Variable here:
The trick is to only fire the Trigger when the Random Number Variable returns a number that ends in 0, 1, 2, 3 or 4. That’s 50% of the possible numbers it can end in.
Naturally, the downside here is that you might miss some outlier errors, which only pop up every now and then. But you should still catch most of the significant ones.
4. Script Error
It’s a good idea to host as many scripts as possible on your own website. Not only will you know more about the errors that are thrown, but also being subservient to an external CDN can introduce security issues, if the third party decides to add some malicious or dangerous code to the library you’re using (or if they’re hacked).
I hope this tip has been useful. Tracking errors is one of the ways to make sure that your website is catering an optimized experience for your visitors. Google Analytics provides a great tool for tracking these errors, because it also lets you create session- and user-scoped segments around error events. With those segments, you can start analyzing the actual business impact of errors thrown on the site.
An error in the eCommerce checkout funnel can be destructive to your business, and using Google Analytics for detection can help you get on top of things before you’ve lost too much money.