FlurryAgent wrapper for Unity 3.2+

567908–20150–$AndroidFlurryAgent.unitypackage (59.4 KB)

Flurry (link) is a solution for analytics tracking on mobile devices.

This wrapper uses the Android Java classes built in to Unity to operate on the Flurry SDK. The included version of the Flurry Android SDK is 2.1.

The methods, and arguments of the Unity wrapper all correspond to the same methods on the FlurryAgent Java class.

Notes

  • Call ‘onEndSession’ from OnApplicationPause(true) as well as OnApplicationQuit()
  • Call ‘onStartSession’ from OnApplicationPause(false)
  • Use ‘setContinueSessionMillis’ to adjust the timeout on starting a new session vs. continuing the existing session. This interacts with OnApplicationPause functionality, since using something like the OpenFeint dashboard, or Google’s In-App Billing will cause a call to OnApplicationPause. The default value is 10 seconds. See the Flurry documentation for more information.

Known Issues

  • I’m not kidding…call onEndSession properly or you will not see your events show up.
  • The ‘setGender’ method is not implemented because I don’t need it and I didn’t really want to muck about with pulling the constants out of the Flurry class.

thanks! this is awesome.

Thank you very much for you contribution buddy :slight_smile:

Thanks :slight_smile:

Hey so Im getting a JNI unable to find method id error for all of the flurry methods. this is my code

using UnityEngine;
using System.Collections;
using System.IO;

public class GUIThings : MonoBehaviour
{

    FlurryAgent flurry = new FlurryAgent();

    void Start()
    {
        flurry.onPageView();
    }

    void OnGUI()
    {
         if (GUI.Button(new Rect(Screen.width - cameraImage.width, Screen.height - cameraImage.height, cameraImage.width, cameraImage.height), cameraImage))
		{
			flurry.logEvent("Uploaded Picture To Facebook");
		}
	}

    public void OnApplicationPause(bool pause)
    {
        if (pause == true)
        {
            flurry.onStartSession("MY ID");
            Application.LoadLevel("SplashScreens");
        }
        else
        {
            flurry.onEndSession();
            Application.LoadLevel("SplashScreens");
        }
    }

    public void OnApplicationQuit()
    {
        flurry.onEndSession();
    }
}

I also tried instead of flurry.whatever doing FlurryAgent.Instance.whatever and same thing.

Is this in the editor, or on the Android device. As far as I know, the AndroidJNI classes will only bind the Java methods on the Android device. In the editor, you will get that warning.

oh ok yeah it was editor. I just wasnt sure how to check if it was working, because on the android it doesnt seem to update my stats.

In my experience, it takest about 30 or so minutes to show up on the Flurry site.

oh ok. so the code i showed looks right though?

Possibly, are you calling onStartSession from anywhere but ApplicationPause? The first launch of your application will not invoke Pause, so you will likely want it in Start() also.

The reason you want it in Pause is because, if your application is exited and then resumed (via pressing the home button or whatever) than on resume, you will not get a call to Start() again, because Start() already happened during the previous session.

no i only call onStartSession from that pause. I will put it in Start() too. Thanks :slight_smile:

I’ve just tried to integrate this with my project, and I’m getting a crash with the following in the logcat:-

FATAL EXCEPTION: Thread 16
java.lang.ClassNotFoundException: com.flurry.android.FlurryAgent


Caused by: jave.lang.NoClassDefFoundError: com.flurry.android.FlurryAgent…

Is there some step I’m missing in using the package? I’m not too familiar with Android development as yet…

Thanks,

Elton

No one with any idea why this isn’t working for me? Is just installing the package all I shoul dneed to do, or is there more to it?

If you’re still having that problem, my guess is the FlurryAgent.jar isn’t being imported properly. I can’t point to any posts, but I seem to remember some people having trouble with .jar’s not updating.

And huge thanks to you ZeroStride, this plugin was amazing!

Hi guys, i’m having the same problem as eltonbird. The package name might be the problem? Do you guys have modified the manifest file to get it working?

Any help would be much appreciated.

Thanks

Is there the same kind of wrapper available for iphone?

Thank you!

Wow awesome, thank you!

This was incredibly useful. Thanks for sharing.

A couple of notes for others who stumble upon here.
Read This

Highly recommended so that you know what is going on.

If your app crashes on load make sure AndroidJavaClass(“com.flurry.android.FlurryAgent”); is not failing.
If it is failing make sure your .jar file is in the correct location otherwise Unity won’t find it.
Make sure the .jar file goes in Assets/Plugins/Android. I had mine in Assets/Assets/Plugins/Android and that caught me out for a few hours!

I have a query that have you implemented the functions for App Circle in .jar as I have tried to access appCircle default function names but unity giving error. Flurry Analytic is working fine.

If you have some problems … here’s my way :

I made it work in this way :

  1. I downloaded the sdk ( the first comment of the post )
  2. Put FlurryAgent.cs FlurryAgent.jar in Assets/ Plugin / Android…
  3. Created a Script called “Example.cs” attached on an Object which is always active.
  4. on the Start() function write these strings :
                _FlurryAgent = new FlurryAgent();     // need to Initialize the script
		_FlurryAgent.onStartSession("insert here your unique ID of the app");    
		_FlurryAgent.logEvent("Application is opened"); // on your events web site, you'll get this notification.
		_FlurryAgent.onPageView(); // to increment the analytics.
  1. Remember to call only once onStartSession() before opening a new one. You must CLOSE it before calling onStartSession() another time.

  2. Then write this code inside the Example.cs :

 	public void OnApplicationQuit() 
	{
		_FlurryAgent.onEndSession();	
	}
  1. Then you have to set up your Manifest :
    add this code after your activities :
<uses-permission android:name="android.permission.INTERNET" />
	<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
	<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  1. Then I added also a new activity but it seems to work also without it. Anyway my advice is to add it inside your activities:
<activity android:name="com.flurry.android.FlurryAgent" android:configChanges="keyboardHidden|orientation" />

Wait 2-3 hours. You’ll see your notification on the flurry web site !

  1. Enjoy. I wrote these steps cause I had some problems in setting flurry analytics up. So I’ll write my way.

Good Luck Guys,
Sheva