Google Analytics Exceptions Tracking: Introduction
As an app developer, unexpected production issues can affect your product’s reputation if not resolved quickly.ย Suffice it to say, they can ruin your dinner and weekend plans!
Exception Tracking, a method for automatically detecting and responding to exceptions in the target application as they occur, can save you hours (or even days) of troubleshooting! A clear policy on how to track exceptions saves you time in diagnosing, reproducing, and correcting the issues. By using Google Analytics Exception tracking you can spend more time fixing the issue, rather than finding the issue.
This post guides you on how to track exceptions for Android and iOS apps in Google Analytics using Google Tag Manager. After reading this blog, youโll be able to generate a report called โCrashes and Exceptionsโ in Google Analytics.
Letโs begin!!
Two major steps to be followed to implement Exception Tracking are:
- GTM Configuration
- DataLayer Implementation
GTM Configurations:
The first step includes creating a tag, a trigger, and variables in Google Tag Manager (GTM) Interface. This tag will fire when specified rules are triggered.
Create a GTM tag that fires on โexceptionOccuredโ trigger.
Note: Tag configuration will be the same for both Android and iOS platforms.
- Create 2 variables โexception_descriptionโ and โis_fatalโ as shown in the following screenshots to collect the exception description and to check whether it is fatal.
2. Create a trigger that fires on the custom event called โexception_occuredโ.
ย
ย 3. Create a tag with track type โExceptionโ and add โException Descriptionโ and โIs Fatalโ variables to the same.
DataLayer Implementation:
Once the tag is created in GTM and the container is published, you will need to push a DataLayer snippet from the app. The snippet consists of key-value pairs where the keys are GTM triggers and variables which are defined in the Exception Tracking tag and the values are assigned from the app to specific keys
When an exception occurs in the app, you must be capturing it in the catch block where youโll also have the description. Youโll need to push a DataLayer from the catch block.
Hereโs how it works!
Follow the steps mentioned below to implement the DataLayer snippet in your Android or iOS app.
For Android:
- Create a method to push an event and exception to DataLayer.
- SetDatalayer event names as โexceptionOccuredโ & push the two other variables as shown in the above image with the same event.
- Call this method (as shown in the below image) inside each catch block of your application.
For iOS:
Push the โexception_occuredโ event with 2 DataLayer variables from the catch block as shown below:
When the above code executes, you can check that the exception is being sent to Google Analytics in the logs as shown below image.
Google Analytics Report Visualization:
Now letโs have a look at the data in Google Analytics.
Open the โCrashes and Exceptionsโ report by selecting Behaviour ->ย Crashes and Exception from the left panel in Google Analytics. This report, in a default manner, shows all crashes and exceptions next to app versions.
The GA report will be visible as shown below:
So now you can track all of your applicationโs errors easily and fix them as soon as possible by spending less time finding & more resolving them.ย
Google Analytics can also give you different parameters like Mobile Device Brand where these exceptions occur. This will be extremely useful for a developer to regenerate those issues and solve them quickly.
Keep coding. Enjoy ๐
For any assistance or more details on Exception Tracking, please drop us a message in the comment section below and our experts will be glad to assist you!!








