firebase / firebase/firebase-android-sdk

Add type safe builders to log analytics events

Open
#3,172 2 comments 0 reactions 0 assignees View on GitHub
api: analytics type: feature request
Dominant language
Java
Stars
2.6k
Forks
710
Avg merge
2d 23h
Merged PRs (30d)
34

Description

## 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](https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Event#SCREEN_VIEW) would look something like this:

```java
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:
```java
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.