Right place for Flurry endSession()

Hi! I am starting to use SDKBox Flurry plugin in my Cocos2d-JS-3.8 game. Documentations tells us that (on Android) we should use:

sdkbox.PluginFlurryAnalytics.endSession();

What is right place for this line? Right now, I insert the line into Listener added by such way:

cc.eventManager.addCustomListener(“game_on_hide”, gameHide);

The problem is that any pop-up dialog such as Play Service Login / Achievements etc. calls for this Listener. It is not good as the session is not ended.

Could you please advice more proper place to insert Flurry session end. Thanks!

Hi @AndreyFomin

You can do this way by overriding the onDestroy() or onStop() functions as mentioned here in the verified answer.

or inside your ~AppDelegate() destructor.

1 Like

Thanks pabitrapadhy!

To record a session is actually really tricky, especially on Android.

Depends how do you want to count as a session.
##iOS
It you count everytime user opens your app as one session, you actually want to startSession in applicationDidEnterBackground and call endSession in applicationWillEnterForeground, because on iOS most of the time when user click on the icon of your game, it’s really just switch them from background.

##Android
You can still put startSession in applicationDidEnterBackground and endSession in applicationWillEnterForeground, you have to be really careful. The sad thing is that on android consider your app is in background if there is a pop up dialog on top of it, so things like “open a IAP dialog”, “watch a video” will considered switch to background. In that case, you’ll need to put in logic to discard those garbage session data. something like

If iap
    disable session tracking
if showing_ad
    disable session tracking
2 Likes