user2002721
user2002721

Reputation: 159

how to integrate firebase analytics in android?

i have use FireBase analytics process that is given in google but after that not track any data in firebase analytics. how to integrate firebase analytics in android ?

Upvotes: 3

Views: 3918

Answers (2)

Pravinsingh Waghela
Pravinsingh Waghela

Reputation: 2534

Follow the below steps to implement Google Firebase Analytics to your Android App:

  1. Add Google Firebase to your project. Register Your App at [Google Firebase Console][1]
  2. If you're creating a new Firebase project, enable Google Analytics during the project creation workflow.
  3. If you have an existing Firebase project that doesn't have Google Analytics enabled, you can enable Google Analytics from the Integrations tab of your Project settings.
  4. Add the dependency for the Google Analytics Android library to your module (app-level) build.gradle file.

Java : implementation 'com.google.firebase:firebase-analytics:17.5.0'

Kotlin : implementation 'com.google.firebase:firebase-analytics-ktx:17.5.0'

  1. Declare the com.google.firebase.analytics.FirebaseAnalytics object at the top of your each activity:

Java : private FirebaseAnalytics mFirebaseAnalytics;

Kotlin : private lateinit var firebaseAnalytics: FirebaseAnalytics

  1. Initialize it in the onCreate() method:

    Java :

    // Obtain the FirebaseAnalytics instance... mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

    Kotlin :

    // Obtain the FirebaseAnalytics instance.. firebaseAnalytics= Firebase.analytics

You have successfully Integrated the Firebase Analytics in your App.

Now for Logging Events Follow the below procedure :

The following code logs a SELECT_CONTENT event when a user clicks on a specific element in your app.

Java :

Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.ITEM_ID, id);
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name);
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "image");
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle);

Kotlin :

firebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_ITEM) {
    param(FirebaseAnalytics.Param.ITEM_ID, id)
    param(FirebaseAnalytics.Param.ITEM_NAME, name)
    param(FirebaseAnalytics.Param.CONTENT_TYPE, "image")
}

Upvotes: 1

Arel Guatno
Arel Guatno

Reputation: 870

If you followed the steps here then you'll have to wait for 24 hours to see the data in the console. It updates periodically.

Upvotes: 3

Related Questions