Firebase Analytics Events And Crashlytics Integration With Android Application

By Kunal Kapoor
15-05-2018
3420

Firebase Analytics Events and Crashlytics is an important service provided by Firebase. It enables app developers to see the user analytics and detect app bugs and crashes on a common platform.



Seting up Firebase Analytics events and Crashlytics is a very simple task. Follow the following steps to start integrating

1. Integrate Firebase with your Android project. Click here to read on how to integrate Firebase with Android project.


2. Open Firebase Dashboard panel and go to Analytics link provided. Click on "Learn More"




3. Then go to option called "Android Setup"


4. Since you have already integrated Firebase (Click here if not), then you dont need to add dependency again.

Perform the next two steps given in documentation.

On top of your java file, declare the object for FirebaseAnalytics

private FirebaseAnalytics mFirebaseAnalytics;


Then initialize the object in the onCreate() method.

mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);



5. After the completion of above steps, your project is ready to log events. 
To log events you need to declare a bundle and pass that bundle in the firebase object
Bundle bundle = new Bundle();
bundle
.putString(FirebaseAnalytics.Param.ITEM_ID, id);
bundle
.putString(FirebaseAnalytics.Param.ITEM_NAME, name);
bundle
.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "CONTENT_TYPE");
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle);

The above bundle records the button click event. You can give the id, name, CONTENT_TYPE parameters as per your own project needs.