Google analyticks with nutracking in onapplicationquit not working

Hello,

I am trying to send some events with information to Google Analytics.

It works fine when I put the event codes in for example my gameOver function, but I don’t want to send the information (like playtime, selected language, total number of games) everytime someone dies, but only once for every game sesiion. So I put the same code in OnApplicationQuit with a debug underneath it to test if the function is being called, the debug shows me that the function is being called but nothing is send to Google Analytics.

Example of working event:

private void GameOver () {
		
		
		
		string sessionName = "GameSession2";
        
        NuTracking.Instance.AddGenericEvent(sessionName, "Result", "GameDurationInSeconds", Random.Range(10, 20));
        NuTracking.Instance.AddGenericEvent(sessionName, "Result", "GameScore", Random.Range(1000, 10000));

Above example works and triggers the event in google analytics everytime someone dies.
However when I put that code in OnApplicationQuit() (example below) the event isnt sent to Google Analytics, but the debug log shows me that the function has been called properly.

 void OnApplicationQuit() {
string sessionName = "GameSession1";
		
		NuTracking.Instance.AddGenericEvent(sessionName, "Result", "GameDurationInSeconds", Random.Range(10, 20));
		NuTracking.Instance.AddGenericEvent(sessionName, "Result", "GameScore", Random.Range(1000, 10000));

Debug.Log("speeltijd: "+speeltijd);

}

Any suggestions or alternatives?

Kind regards

I’m the author of NuTracking. Here is an updated NuTracking.cs, which flushes all the GA events on its OnApplicationQuit(). You may try it to see if it works. [11926-nutracking.cs.zip|11926]

However, Unity might have no guarantee of the order of OnApplicationQuit(). So after adding new events, you could also manually call

NuTracking.Instance.FlushRequestQueue()

to make sure all these events would be sent.

On iOS devices, sometimes you may also consider to send the stats when application goes to background, as the OS may kill it silently. You may check this post link text for more details.