Problem/Bug with OnApplicationQuit

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:

  1. 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.
  2. How can we resume the analytics session after Application.CancelQuit ?

Thanks in advance,
Chris

Hi @Chris-Herold ,

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().

2648049--186571--Screen Shot 2016-05-24 at 1.03.32 PM.png

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!

Ray

Thank you for the quick response.

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.

@Chris-Herold , could you please submit a support ticket at Unity Cloud with the following information:

  • The platform that the issue is occurring on
  • The editor build version you’re running
  • List of reproducible steps so that we can try to recreate the issue

This will allow us to take a closer look at the project and try to find a resolution.

Thank you for bringing this to our attention and I look forward to hearing from you!

Ray

1 Like

@Chris-Herold , I just wanted to shoot you a quick update:

It seems like OnApplicationQuit does not terminate Analytics as long as CancelQuit is called in Unity 5.4 Beta.

We are currently working with our engineers to fix that issue in 5.3 and I will update this thread once it is fixed :slight_smile:

1 Like