-
Notifications
You must be signed in to change notification settings - Fork 429
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
Sending Firebase analytics from OnApplicationQuit #451
Comments
Hi @ColorTwist, I've done a little bit of digging on this, and have a short answer and a fun answer. The short answer is that you should be safe to send the data in OnApplicationQuit, but I'd probably recommend OnApplicationPause on iOS and Android. The long answer is that on Android, events are sent in Google Play Services. Once you log an event, it should get logged even if your app isn't running. On iOS, the behavior is a little different. Firebase Analytics attempts to send all events up in the call to applicationDidEnterBackground. If you look at the documentation for OnApplicationQuit, it indicates that this may not be called immediately unless you have "Exit on Suspend" selected in the player settings. This leads me to assume that it's associated with the applicationWillTerminate callback which will happen after applicationDidEnterBackground. In this case though, and since the user may be offline anyway when an event is logged, Firebase Analytics does try to cache all the events locally. Then, the next time your game is running and the player has internet access, it will try to upload your events. I have seen subtle changes between Unity versions when relying on this sort of native-level behavior in the past. The good news is that you can easily test the exact behavior for your combination of Unity, Analytics, your player settings, and your particular stack of other native plugins quickly using realtime analytics. I hope that this all helps! |
Thanks, @patm1987 for the reply. Then I'll have to move to Regarding iOS, I guess the 'fun' with it will be with I publish the APP on iOS :) |
Awesome! I'm closing this issue, but do not hesitate to re-open and comment some more if you have no related questions. I do find that, when at all possible, it's best to try to treat OnApplicationPause(true) as a pseudo-quit (in that you should try to persist everything as if you will need to resume from there, but try not to logically quit the game if possible). Something that occurred to me is that onDestroy (what typically corresponds to OnApplicationQuit) may not always get called on Android: https://developer.android.com/reference/android/app/Activity.html#onDestroy() and I think similar rules may apply to iOS, especially in low memory situations. |
Hello,
Question, would it be a good practice to send some information to Firebase analytics from the App in the function OnApplicationQuit (Triggers when the application quits),
could it cause any issues?
I want to send values like how much time used in the App and some other statics before quit.
I am sending total time as a float of total seconds dividing by 60 to get a float value 'like' minutes and seconds.
The text was updated successfully, but these errors were encountered: