Punit Makwana
Punit Makwana

Reputation: 17

Android Firebase Analytics not working correcty

I want to track which button is clicked using Google Firebase Analytics.

Code I tried:

public class MainActivity extends AppCompatActivity {
private FirebaseAnalytics mFirebaseAnalytics;
  @Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
  }

  public void onClick(View view) {
    int btn_id = view.getId();
    if (view.getId() == R.id.Btn1) {
        //Some content
    } else if (view.getId() == R.id.Btn2 {
        //Some content
    } else if (view.getId() == R.id.Btn3) {
        //Some content
    }
        Bundle params = new Bundle();
        params.putString(FirebaseAnalytics.Param.ITEM_ID, String.valueOf(btn_id));
        mFirebaseAnalytics.logEvent("homebtn_event", params);
  }
}

The above code tracks clicks on buttons but does not returns btn_id or which button is clicked in Firebase Analytics data

Upvotes: 2

Views: 3363

Answers (3)

djabi
djabi

Reputation: 5767

Unfortunately Firebase Analytics doesn't automatically provide parameter reporting for custom events/parameters. You have two options to understand how your button is clicked:

  1. You can link the account to BigQuery and select the "homebtn_event" event with "homebtn_event" parameters of given value. BigQuery has free tier that should allow you to do this for free (assuming your app is not one of the major apps). This will give you a lot of flexibility to query the data.

  2. You can use one of the predefined events + predefined parameter that has reporting in Firebase Analytics. You can use SELECT_CONTENT(ITEM_ID) for example:

    Bundle bundle = new Bundle(); bundle.putString(Param.ITEM_ID, String.valueOf(btn_id)); bundle.putString(Param.CONTENT_TYPE, "button"); mFirebaseAnalytics.logEvent(Event.SELECT_CONTENT, bundle);

Upvotes: 2

h_patel
h_patel

Reputation: 744

You can try this :

  firebaseAnalytics = com.google.firebase.analytics.FirebaseAnalytics.getInstance(c);
    Bundle bundle = new Bundle();
    bundle.putString("homebtn_event",String.valueOf(btn_id));
    firebaseAnalytics.logEvent(com.google.firebase.analytics.FirebaseAnalytics.Event.LOGIN, bundle);
    firebaseAnalytics.setAnalyticsCollectionEnabled(true);
    Log.v("homebtn_event",String.valueOf(btn_id));

Upvotes: -2

Paresh
Paresh

Reputation: 6857

Firebase analytics event will be visible on Dashboard after 24 hours

But

You can enable verbose logging to monitor logging of events by the SDK to help verify that events are being logged properly. This includes both automatically and manually logged events.

You can enable verbose logging with a series of adb commands:

adb shell setprop log.tag.FA VERBOSE
adb shell setprop log.tag.FA-SVC VERBOSE
adb logcat -v time -s FA FA-SVC

This command displays your events in the Android Studio logcat, helping you immediately verify that events are being sent.

Reference

Upvotes: 4

Related Questions