Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

It is necessary to initialize Firebase Analytics in every Activity?

I don´t want to send any special logs to the Firebase Analytics console, just check in which screens is the user spending more time and so on.

When I used AnalyticsTracker it was compulsory to add it everywhere, so do you can set the specific name of every screen with the Tracker.xml file.

The official documentation says:

Add the dependency for Firebase Analytics to your app-level build.gradle file:

compile 'com.google.firebase:firebase-core:9.2.1'

Declare the FirebaseAnalytics object at the top of your activity:

private FirebaseAnalytics mFirebaseAnalytics;

Then initialize it in the onCreate() method:

mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

So I guess I´ve to do this in every page where I want to get data, haven´t I?

like image 435
Óscar Avatar asked Jul 22 '16 10:07

Óscar


People also ask

Where do I initialize Firebase Analytics?

Declare the FirebaseAnalytics object at the top of your activity: private FirebaseAnalytics mFirebaseAnalytics; Then initialize it in the onCreate() method: mFirebaseAnalytics = FirebaseAnalytics.

Does Firebase Analytics work offline?

Firebase Analytics will store logged evens locally on the device (online or offline). When its time to upload the data and the devices has network connection Firebase Analytics will batch the data in as fewer uploads as possible, compress it and attempt to upload the data.

What is the difference between Google Analytics and Firebase Analytics?

Google analytics also supported mobile analytics though android and IOS sdk's which sent Screen hits to google analytics. There was a difference between Mobile and web google analytics accounts. Firebase is a platform developed by Google for creating mobile and web applications.


1 Answers

No. You just need to create global variable in an Class which extends Application class

      public class MyApplication extends Application {     public static  FirebaseAnalytics mFirebaseAnalytics;     @Override         public void onCreate() {             super.onCreate();           mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);     }     }  

After, you add the following line in your manifest, in the Application tag

<application   android:name=".MyApplication"   ... 
like image 125
Hoshouns Avatar answered Sep 23 '22 23:09

Hoshouns