Skip to content

Add type safe builders to log analytics events #3172

Open
@thatfiredev

Description

@thatfiredev

What feature would you like to see?

I would like to have type safe builders in Firebase Analytics that would help developers logging events. This way developers would know which data type each parameter expects, and it would also be easier for developers to know which parameters are optional and which ones are required.

How would you use it?

For example, the builder to log the SCREEN_VIEW event would look something like this:

FirebaseAnalytics analytics = FirebaseAnalytics.getInstance()
ScreenViewEvent screenViewEvent = ScreenViewEvent.Builder()
    .setClass("MainActivity")
    .setName("Main Screen")
    .build();
analytics.logEvent(screenViewEvent);

Other than being type-safe, I think this is less verbose than the current usage:

FirebaseAnalytics analytics = FirebaseAnalytics.getInstance()

Bundle parameters = new Bundle();
parameters.putString(FirebaseAnalytics.Param.SCREEN_CLASS, "MainActivity");
parameters.putString(FirebaseAnalytics.Param.SCREEN_NAME, "Main Screen");

analytics.logEvent(FirebaseAnalytics.Event.SCREEN_VIEW, parameters);

If at some point one of the event gets deprecated, we can deprecate the builder class for that event.
If one of the parameter gets deprecated, we can deprecate the respective method.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions