Custom event at end of session

Hello,

We tried to create a custom event at the end of a user’s session to record how much player use their energy in one session.

  1. This event is not fired when player end their session, instead they are fired when player begin a new session after that but it’s not recorded, instead it says “Analytic not initialized” ?
  2. Also, this custom event somehow is fired every time the game went to background even just for one second, instead of “went idle for 30 minutes” as Unity Analytic would normally count one session?

Appreciate any advice.

Code

void OnApplicationPause (bool isPause) {

if (isPause)

RecordSessionEnd ();

}

void RecordSessionEnd () {

var staminaUsed = PlayerPrefs.GetInt (KeyConstants.SESSION_STAMINA_USE, 0);

CharacterManager.onStaminaUse -= RecordStaminaUse;

var totalStamina = 0;

foreach (var pc in CharacterManager.GetAllCharacters ()) {

if (pc.boughtStatus)

totalStamina += pc.GetStamina ();

}

Analytics.RecordSessionEnd (staminaUsed, totalStamina);

}

Thank you

#1 If you fire an event right before an app goes into background(ex: OnApplicationPause), this doesn’t guarantee that it will get sent, because the app has limited time and resources right before going to background. However it shouldn’t show as “Analytics not initialized”
What version of Unity are you using and what platform do you see this behaviour or “Analytics not initialized”?

#2 We have our own logic that the user must have minimized/loggedout of the app for 30mins for a new session to start.
If you want to mimic this, you can store the timestamp OnApplicationPause(false) and OnApplication(true) and compare the diff to see if it has been 30 mins.

Thanks for the answer. We are using Unity 4.6.3F1 on Android.