quickstart-android icon indicating copy to clipboard operation
quickstart-android copied to clipboard

setCurrentScreen in onResume sends screen_view twice

Open lucalooz opened this issue 6 years ago • 6 comments

We are trying to set a custom name or class name to the screen of the screen_view event but the event is sent twice even if we do it inside onResume of the activity.

https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics#setCurrentScreen(android.app.Activity,%20java.lang.String,%20java.lang.String)

lucalooz avatar Jan 09 '19 13:01 lucalooz

@llooz can you provide some code that reproduces the problem? Is this in an Activity or a Fragment? And does it send twice automatically or do you have to resume the app?

samtstern avatar Jan 11 '19 23:01 samtstern

I'm experiencing the same issue. I call setCurrentScreen in the onResume of an activity and I see in the debug view in my firebase console 2 events: one with the default name and one with the custom name I passed to setCurrentScreen. This is the exact same behaviour reported for the iOS sdk here: https://github.com/firebase/firebase-ios-sdk/issues/1894

Do you have any insight on how to avoid this? Tracking screen views at the moment is pretty unusable because I can't rely on the numbers I see, due to those duplications.

serenasoldo avatar May 08 '19 09:05 serenasoldo

Same issue here. It's really not hard to repro at all. Just put a call to setScreenName() in any activity's onResume() and no-where else and you get double events.

Definitely disappointing to expect it to work properly. It only dupes when creating the Activity. IOS bug hasn't moved in almost an entire year so not expecting much any traction at all. It's fixable, but I can see why y'all would punt.

You could probably use WeakReference<Activity> if setScreenName is called in Activity.onCreate() and if Activity isn't known, hold the reference and resolve it when the onResume() gets called that generates the bad event. This would also help you avoid the other behavior where calling setScreenName in onCreate() doesn't fire anything if the Activity isn't known yet. Then the SDK would work forgivingly without the extra event noise. You also wouldn't have to worry about knowing whether an explicit call to setScreenName is coming, you could just assume if someone tries to set early, resolve it when you get the actual lifecycle event. No need to try to translate intent.

raderto avatar Aug 05 '19 21:08 raderto

Still facing this issue, is there a fix for this yet?

udaisubramaniam avatar Dec 04 '19 11:12 udaisubramaniam

Still encountering the same problem.

In fact, a lot of trouble reporting events and parameters using firebase...

niloleartVY avatar Apr 20 '20 16:04 niloleartVY

Guys please follow @raderto's comment. Move your screen_view from onResume() to onCreate(). This will always give you unique & non-redundant screen view events.

Lets close this issue.

RahulSDeshpande avatar Jan 19 '23 07:01 RahulSDeshpande