Firebase Analytics For Android Shouldn’t Be This Hard

Firebase (2 Part Series)

1 Firebase Analytics For Android Shouldn’t Be This Hard
2 Google Sign-In on Android using Firebase

Well, it is not. Let me show you how

Prerequisites

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;

Enter fullscreen mode Exit fullscreen mode

  • Initialize it in the onCreate() method
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

Enter fullscreen mode Exit fullscreen mode

  • 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);
            }
        });

Enter fullscreen mode Exit fullscreen mode

  • 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

Firebase (2 Part Series)

1 Firebase Analytics For Android Shouldn’t Be This Hard
2 Google Sign-In on Android using Firebase

原文链接:Firebase Analytics For Android Shouldn’t Be This Hard

© 版权声明
THE END
喜欢就支持一下吧
点赞5 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容