Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot log screen view event when the app is not active #7577

Closed
KelvinJin opened this issue Feb 22, 2021 · 6 comments · Fixed by #8605
Closed

Cannot log screen view event when the app is not active #7577

KelvinJin opened this issue Feb 22, 2021 · 6 comments · Fixed by #8605
Assignees
Milestone

Comments

@KelvinJin
Copy link

[REQUIRED] Step 1: Describe your environment

  • Xcode version: Xcode 12.4
  • Firebase SDK version: 7.3.1
  • Installation method: Swift Package Manager
  • Firebase Component: Analytics, Crashlytics

[REQUIRED] Step 2: Describe the problem

It appears that the system FaceID/TouchID authentication prompt is putting the app into a resigned/non-active state. And sending screen_view event during the prompt is ignored by Firebase SDK due to the limitation that no screen_view events are allowed when the app is not active.

The console printed out the error: Cannot log screen view event when the app is not active.

I'm not sure what's the best way to solve this to be honest. Not sure if it's fair to assume Firebase SDK would take care of this situation.

Steps to reproduce:

Perform a FaceID/TouchID authentication as soon as the app is coming back from background while sending out a screen_view event.

Relevant Code:

LAContext().evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: "some reason") { }
Analytics.logEvent(AnalyticsEventScreenView, [
AnalyticsParameterScreenName: "MyView",
AnalyticsParameterScreenClass: "MyViewClass"
])
@google-oss-bot
Copy link

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.
@ryanwilson
Copy link
Member

Hey @KelvinJin, sorry for the trouble you're seeing. This may be a silly suggestion, but does moving the logEvent call before the call to bring up the FaceID prompt work in your case? I'm not sure off the top of my head if we can detect the FaceID prompt showing in the app or not.

@KelvinJin
Copy link
Author

KelvinJin commented Feb 23, 2021

@ryanwilson Hey Ryan, thanks for the reply. I tried both order but it won't work unless I add some sort of delay by using for instance DispatchQueue.main.asyncAfter. This issue also applies to the case if we're to show a view right after success of the FaceID authentication. That view's screen view event won't get sent unless we add some sort of delay.

I think the underlying problem is that Firebase is observing applicationWillResignActive to disable screen view tracking but sometimes when this happens, the app is actually visible and screens are being updated. One example being when you receive a phone call and that iOS phone call banner will show up from the top of your device which will put the app into non-active state. If we send screen view events during this period, it won't be captured.

I couldn't really provide any constructive advice other than maybe instead of observing applicationWillResignActive, Firebase should observe applicationDidEnterBackground?

It's not a big big deal for me to add some delay in order to workaround this issue but I'm worried that a random delay might cause further issues. For instance, if I delay the screen view event by 2 seconds but don't delay the following interactive events. Then the interactive events might be associated with a wrong firebase_screen if they happen within that 2 seconds.

Let me know if you have any other ideas! Thanks.

@ryanwilson
Copy link
Member

Thanks for the detailed reply! I'm not sure all the considerations made here so I'll defer to someone who knows more than I do. @htcgh any ideas if this is working as intended or there's a way we can determine the type of non-active state here?

@unxavi
Copy link

unxavi commented Apr 28, 2021

Just to add to this... I'm seeing the same. My case is a bit different. I ask notification permission and as soon as the user respond, we show a new screen and this screen is not tracked

Cannot log screen view event when the app is not active

@sbo-nemlig
Copy link

Any updates on this one? , we are having the same issues

@htcgh htcgh mentioned this issue Aug 31, 2021
@paulb777 paulb777 added this to the 8.7.0 - M103 milestone Aug 31, 2021
@firebase firebase locked and limited conversation to collaborators Oct 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.