Well, it is not. Let me show you how
Prerequisites
- Google Analytics Account https://analytics.google.com/
- Firebase Project https://console.firebase.google.com/
- Android Application. I created one using Android Studio.
Add Firebase to your App
- On the Firebase console, click on the Android icon to add your App.
- Enter your App package name and a nickname. Then click on the (Register app) button.
- Download the config file and add it to your project as per the screen below
- Follow the instructions in step 3 to update the gradle files.
- Now our app is ready for Firebase Integration.
Use the Analytics SDK on your App
- Declare the FirebaseAnalytics object at the top of MainActivity.
private FirebaseAnalytics mFirebaseAnalytics;
- Initialize it in the onCreate() method
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
- Run the App and check the Firebase Dashboard
- Add a button to your activity, update the onCreate as below to log the click event of the button
Button button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mFirebaseAnalytics.logEvent("button_clicked", null);
}
});
Run the App and click on the button. Then check the Firebase Dashboard for the event.
Check the Logcat tab, and you will find the logged event.
That's it... I told you it is easy.
Check the code here
Follow me on Twitter for more tips about #coding, #learning, #technology, #Java, #JavaScript, #Autism, #Parenting...etc.
Check my Apps on Google Play
Cover image Luke Chesser
Top comments (0)