1

We have a requirement to send all the Android app events captured by Firebase analytics to our own server via a service call. Then forward those events to the Firebase analytics. Is it even possible? How can this be done? It does not seem to be the right approach but this is the requirement.

Niket Singh
  • 159
  • 12
  • There is no REST API for posting to Google Analytics for Firebase. See https://stackoverflow.com/questions/38232464/is-there-any-rest-api-to-send-data-to-firebase-analytics, https://stackoverflow.com/questions/50355752/firebase-analytics-from-remote-rest-api – Frank van Puffelen Jun 27 '18 at 16:21

1 Answers1

0

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

implementation 'com.google.firebase:firebase-core:16.0.1'

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

private FirebaseAnalytics mFirebaseAnalytics;

MainActivity.java

Then initialize it in the onCreate() method

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

MainActivity.java

Log events

Once you have created a FirebaseAnalytics instance, you can use it to log either predefined or custom events with the logEvent() method. You can explore the predefined events and parameters in the FirebaseAnalytics.Event and FirebaseAnalytics.Param reference documentation.

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

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

This are the events you can log

https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Event

and this the params

https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Param

then after retrieving the events you can send it to your own server, and then you can use your own logic to post them.

Gastón Saillén
  • 12,319
  • 5
  • 67
  • 77
  • 1
    is there any example for how `then after retrieving the events` in Android client? – Kane May 13 '22 at 16:35