flurry / unity-flurry-sdk

Unity plugin for Flurry SDK
Apache License 2.0
25 stars 5 forks source link

Android flurry sessions are not starting when I call Flurry.Builder.Build() #6

Closed jamged closed 4 years ago

jamged commented 4 years ago

Unity Version: 2018.4.6.f1 Unity Flurry Plugin Version: 2.1.0 Platform: Android

Problem Behavior

Flurry analytics session is not tracked immediately upon calling Flurry.Builder.Build() in my C# script, but rather will only start tracking after I sleep/wake the app after calling the Build() method.

Expected Behavior

Flurry analytics session should start tracking immediately upon calling Flurry.Builder.Build() method in my C# script.

Details

I have imported the .unitypackage into my project and created a script similar to the example FlurryStart.cs to initialize the flurry analytics within my C# code. I noticed that after calling Flurry.Builder.Build() method, a session is not automatically tracked in the Flurry dashboard. Calling Flurry.GetSessionId() at this point returns 0. If I send the app to the background and then return it to the foreground, THEN a session will start tracking on the flurry dashboard and I will have a valid Session Id returned by the Flurry.GetSessionId(). This means for users that launch the app for a while and then quit without every sleeping/sending it to background, their flurry session is never tracked.

Example Minimal Unity Project

I have created a minimal Unity example project demonstrating this behavior, but unfortunately it is too large to attach to the gitlab issue. I can send it via email to the development team if it would be helpful.

poting-oath commented 4 years ago

@jamged Yes, the session creation delay is expected, but normally the data should still be saved.

From the native Flurry, if Flurry init happened in Activity (as Unity does), the session creation will happen when the next Activity goes in Foreground. However, the data should still be saved.

Flurry is working on improving this delay.

If you see the data loss happened, please use Manifest file + Application.java to initialize Flurry instead (rename AndroidManifest_Flurry-template.xml to AndroidManifest.xml) to init Flurry from the Application level. Then this delay will be fixed. Please see the README for Flurry Push, but you don't need to enable Push though.

If you need the FlurryUnityApplication.java (to remove all Push codes), you can find it in our old release. https://github.com/flurry/unity-flurry-sdk/blob/4cc80b1cec2047d37f5ba6b1a5eb394dda091f03/Plugins/Android/FlurryUnityApplication.java

Thanks a lot for your report!

jamged commented 4 years ago

Thank you for your response!

Regarding this comment:

From the native Flurry, if Flurry init happened in Activity (as Unity does), the session creation will happen when the next Activity goes in Foreground. However, the data should still be saved.

I thought if you pass the Activity context to the Android FlurryAgent Builder.build() method, then the session will start immediately in that Activity without needing to wait for the next activity to come to the foreground? ( See android documentation reference here). I see in this plugin's FlurryAgentAndroid.Build() method you are obtaining and passing the current activity context to the builder (Reference Here), but it seems the FlurryAgent does not behave as the documentation says since no session is started. Note that our Unity project was using a very old 1.x version of the android flurry SDK, and using the deprecated FlurryAgent.init() method and passing the current activity context we could see sessions starting immediately. However It seems with the new Builder initialization flow this is not happening even when the Activity context is passed in.

Regarding modifying the AndroidManifest.xml to use FlurryUnityApplication:

This is currently not an option since we need to use android:name="androidx.multidex.MultiDexApplication" for multidex support on Android SDK 20 and below, and the FlurryUnityApplication implementation does not extend MultiDexApplication (more info here: https://developer.android.com/studio/build/multidex#mdex-gradle )

Would you be able to add a multidex support to the FlurryUnityApplication Application subclass?

poting-oath commented 4 years ago

We just added support in our native SDK, this will be fixed in the next release in January.

poting-oath commented 4 years ago

Before that, please continue using the AndroidManifest.xml + FlurryUnityApplication.java approach. Thanks!

poting-oath commented 4 years ago

@jamged For the MultiDexApplication support, please just replace extends Application with extends MultiDexApplication in FlurryUnityApplication.java.

From our library provider's concern, we should not make it default to MultiDexApplication, because it will need all user's apps depend on androidx.multidex:multidex.

poting-oath commented 4 years ago

@jamged 2.3.0 just released with the session delay fix. Please try whether it fixes your issue or not. Thanks!

jamged commented 4 years ago

@poting-oath I have tested the latest 2.3.0 release, and the issue is resolved. Thank you!