Exception Tracking in Android & iOS Apps using Google Analytics

Exceptional Tracking – An Introduction

As an app developer, unexpected production issues can affect your product’s reputation if not resolved quickly.  Suffice 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 from hours (or even days) of troubleshooting! A clear policy on how to track exceptions save your time in diagnosing, reproducing and correcting the issues. By using Google Analytics Exception tracking you can spend more time in 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 which fires on “exceptionOccured” trigger.

Note: Tag configuration will be same for both Android and iOS platform.

  1. 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.

Datalayer1
Datalayer2

2. Create a trigger which fires on custom event called “exception_occured”.


trigger

 3. Create a tag with track type “Exception” and add “Exception Description” and “Is Fatal” variables to the same.

tag

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 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 DataLayer snippet in your Android or iOS app.

For Android:

  1. Create a method to push an event and exception to DataLayer.
    datalayer syntax
  2. SetDatalayer event name as “exceptionOccured” & push the two other variables as shown in the above image with the same event.

  3. Call this method (as shown in the below image) inside each catch block of your application.
    calling datalayer push

For iOS:

Push the “exception_occured” event with 2 DataLayer variables from the catch block as shown below:

ios snippet

When the above code executes, you can check that the exception is being sent to Google Analytics in the logs as shown in below image.
logs

 

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 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:

report
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 in resolving. 

Google Analytics can also give you different parameters like Mobile Device Brand where these exceptions occur. This will be extremely useful as 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!!

The following two tabs change content below.
Sameer Sanghavi

Sameer Sanghavi

Sameer is a Partner & VP of Customer Development at Tatvic Analytics, heading the operations for the company in North America. He has been working across a global footprint, in creating strategies & building a synergistic portfolio of businesses for the firm, whose philosophy is to help enterprises make better data-driven decisions. Sameer’s background has been in running successful technology businesses and leading large initiatives.
, , , ,
Previous Post
4 Steps to Extended Email Campaign Tracking & Actionable Insights
Next Post
Tangled up in DeepLinking? Firebase has a solution!

7 Comments. Leave new

Leave a Reply

Your email address will not be published.

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

Menu