We want to send a CustomEvent in OnApplicationQuit to record a range of user metrics.
However, OnApplicationQuit ends the analytics session and there is no way to resume it.
Possible bug:
Analytics doesn’t seem to care about Application.CancelQuit, which means when the user cancels our Exit Dialog, there is no way to re-init analytics and it remains NonInitialized for the rest of the play session.
Questions:
How can we send a CustomEvent when the app is about to close (user closes the app window using the OS close button) ? It doesn’t seem possible with the current setup.
How can we resume the analytics session after Application.CancelQuit ?
I understand your frustration due to the inability to send a CustomEvent in OnApplicationQuit. We have noted this issue and are currently looking for a resolution.
A temporary work around is to use Application.CancelQuit inside your OnApplicationQuit. A boolean can be created to determine if you are actually quitting or not, and a CustomEvent can be sent after CancelQuit().
Note: This does not work on iPhones but should work in both 5.3 and 5.4beta.
Let me know if this works for you or if you have any more questions!
Sadly, your example does not work as you might expect.
The problem is that when OnApplicationQuit fires,
the Analytics session has already ended (because its OnApplicationQuit fires before any script).
And CancelQuit does not resume the session.
In production that means anytime a user cancels the exit dialog, we are left with NonInitialized Analytics.