Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Code Snippets

FlurrySH - Flurry analytic for Shiva (iOS & Android)

Paste down any little snippets or request a new one.

FlurrySH - Flurry analytic for Shiva (iOS & Android)

Postby capiright » 25 Nov 2011, 14:42

Hi,

This thread will be my simple implementation for Flurry analytic.
** Please go to http://www.flurry.com to create your user account and application. Download all the relevant materials and read the short description of their API.

This code implements
onStartSession
onEndSession
LogEvent( sEventId)
LogEvent( sEventId, time==true)
LogEvent( sEventId,(map) params)
LogEvent( sEventId,(map) params, time==true)
EndTimedEvent( sEventId )

** Shiva3D code:
1. Import the FlurrySH.STE which will place the FlurrySH user AI in your code.
2. Check out the comments in onLogEvent to see how to use the function in depth.

** Eclipse project
1. import class sdg.utils.flurysh.android.FlurryAgentWrapper.java
2. import FlurrySH.c under JNI folder
3. If you need the engine headers place /S3DX under JNI folder
4. Import Flurry lib as given by Flurry to your project. Right click your project->Properties->Java Build Path->Use External JARs
5. go to FlurryAgentWrapper.java and assign sProductKey your Flurry product key

Code: Select all
private final String sProductKey = "<Your Product Key>";


6. Go to S3DClient.cpp and include FlurrySH.c like so:
Code: Select all
#include "FlurrySH.c"
// @@END_JNI_INCLUDES@@


7. Look for begin jni hook events and add the function like so:
Code: Select all
//----------------------------------------------------------------------       
// @@BEGIN_JNI_INSTALL_EVENT_HOOKS@@
flurrysh_registerCallbacks( pJavaVM );
//----------------------------------------------------------------------           


8. Go to yourApp.java class and look for onStart method, the enter the startSession call below the super class call

Code: Select all
//------------------------------------------------------------------
// @@BEGIN_ACTIVITY_METHODS@@   
//------------------------------------------------------------------
@Override
protected void onStart ( )
{
Log.d ( Globals.sApplicationName, "--------------------------------------------" ) ;
Log.d ( Globals.sApplicationName, "Start activity " + Globals.sApplicationName ) ;
Log.d ( Globals.sApplicationName, "--------------------------------------------" ) ;
super.onStart ( ) ;
       
//*** FLURRY CODE ***//
FlurryAgentWrapper.getInstance().startSession( this );       
}


9. Look for the onStop event and enter endSession under the super class call:
Code: Select all
protected void onStop ( )
{
Log.d ( Globals.sApplicationName, "--------------------------------------------" ) ;
Log.d ( Globals.sApplicationName, "Stop activity " + Globals.sApplicationName ) ;
Log.d ( Globals.sApplicationName, "--------------------------------------------" ) ;
super.onStop ( ) ;
       
//*** FLURRY CODE ***//
FlurryAgentWrapper.getInstance().endSession( this );
}



** XCode Project
- Same as above go to Flurry and see how to include their lib + get your product key

@@@ IMPORTANT: I JUST NOTICED THAT FLURRY CHANGED ITS LIB NAME FlurryAnalytics.h is now called Flurry.h

1. Go to S3DEngine_AppDelegate.m import flurry analytics
Code: Select all
#import "FlurryAnalytics.h"


2. Stay in the same file and start session under applicationDidFinishLaunching
Code: Select all
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
    //---- FLURRY CODE STARTING SESSION  ------///
    [FlurryAnalytics startSession:@"<Your Flurry Product Key>"];


3. Extract the Zip file attached and import the 4 XCode files into Classes of your project.

4. Open S3DEngine_EAGLView.m and import flurrysh.h
Code: Select all
#import "flurrysh.h"


5. Locate layoutSubviews and register the callbacks under [self setFrame...]
Code: Select all
- (void)layoutSubviews
{
    [self setFrame:[[UIScreen mainScreen] bounds]];
   
    flurrysh_registerCallbacks();



Now you are good to go :)

Some remarks:
-- I assume your game is an entire session. You may want to break it or play with it.
-- Make sure you allow the use of internet in your manifest
-- The timed events have not been logging properly even though I see all the FlurryAgent calls going out as intended. I opened a ticket on Flurry but if you find a bug in my code let me know. (Android)
-- iOS version is limited a bit to make the Android and iOS unified on the Shiva side. IF you need to extend it go for it.
-- Feel free to review and extend the code to make sure I had not done something wrong. It is the first time I write JNI code.
-- @Giggsy: if you recognize bits of your code don't sue me :P
Last edited by capiright on 22 Oct 2012, 09:28, edited 4 times in total.
User avatar
capiright
Platinum Boarder
Platinum Boarder
 
Posts: 518

Re: FlurrySH - Flurry analytic for Shiva

Postby giggsy » 25 Nov 2011, 15:16

Hi,

that is awesome!

We need iOS flurry for our upcoming game, so we plan to add it within the next two weeks.
Would be cool if we can save the time and you get it done before us ;)
Do you have an ETA?
User avatar
giggsy
Platinum Boarder
Platinum Boarder
 
Posts: 1105
Location: Austria

Re: FlurrySH - Flurry analytic for Shiva

Postby capiright » 25 Nov 2011, 15:23

Hopefully by the end of next week as I need it too. Sort of doing it on my idle thread tho
User avatar
capiright
Platinum Boarder
Platinum Boarder
 
Posts: 518

Re: FlurrySH - Flurry analytic for Shiva

Postby giggsy » 29 Nov 2011, 08:10

FYI: I am starting with Flurry (basic integration) today.
User avatar
giggsy
Platinum Boarder
Platinum Boarder
 
Posts: 1105
Location: Austria

Re: FlurrySH - Flurry analytic for Shiva

Postby capiright » 29 Nov 2011, 13:22

Good timing, I just finished testing it :) it takes a while for Flurry to update the dashboard
User avatar
capiright
Platinum Boarder
Platinum Boarder
 
Posts: 518

Re: FlurrySH - Flurry analytic for Shiva (iOS & Android)

Postby giggsy » 29 Nov 2011, 13:50

Haha, nice!
I was just downloading Flurry ... thanks!

Regarding [FlurryAnalytics startSession:@"<Your Flurry Product Key>"]; in AppDelegate.m: I was thinking of adding a onStartSession and onStopSession event ... I think that should also work?
Cause this way I can keep the App-Key inside Shiva
User avatar
giggsy
Platinum Boarder
Platinum Boarder
 
Posts: 1105
Location: Austria

Re: FlurrySH - Flurry analytic for Shiva (iOS & Android)

Postby capiright » 29 Nov 2011, 14:05

You can do that, just remember that you don't have endSession in iOS.

BTW, I have to stress that I don't have a lot of experience with ObjC so if you could double check my code that would be great.
User avatar
capiright
Platinum Boarder
Platinum Boarder
 
Posts: 518

Re: FlurrySH - Flurry analytic for Shiva (iOS & Android)

Postby giggsy » 29 Nov 2011, 19:18

Out of curiosity ... how long did it take until you saw something in the dashboard?
User avatar
giggsy
Platinum Boarder
Platinum Boarder
 
Posts: 1105
Location: Austria

Re: FlurrySH - Flurry analytic for Shiva (iOS & Android)

Postby capiright » 29 Nov 2011, 20:53

giggsy wrote:Out of curiosity ... how long did it take until you saw something in the dashboard?


It could tame about 3 or 4 hours
User avatar
capiright
Platinum Boarder
Platinum Boarder
 
Posts: 518

Re: FlurrySH - Flurry analytic for Shiva (iOS & Android)

Postby redmotion » 04 Jun 2012, 11:05

Hi,
Just looking at adding Flurry at the moment. Everything seems to slotting into place but I'm not sure how to deal with this part:
1.import class sdg.utils.flurysh.android.FlurryAgentWrapper.java


How do I import this java class into my Eclipse project?

Thanks in advance.
User avatar
redmotion
Platinum Boarder
Platinum Boarder
 
Posts: 574

Re: FlurrySH - Flurry analytic for Shiva (iOS & Android)

Postby giggsy » 04 Jun 2012, 12:25

There might be an easier way, but I do it like this:
Each "sub-package" is it's own folder ... so you got:
src/sdg/utils/flurysh/android/FlurryAgentWrapper.java or in what ever package your file should be in
User avatar
giggsy
Platinum Boarder
Platinum Boarder
 
Posts: 1105
Location: Austria

Re: FlurrySH - Flurry analytic for Shiva (iOS & Android)

Postby redmotion » 04 Jun 2012, 13:14

Thanks Giggsy, I tried sticking it into the src folder already, the problem I'm having is how to tell eclipse to include/link/etc to it. The folder doesn't show up even if I restart eclipse.
User avatar
redmotion
Platinum Boarder
Platinum Boarder
 
Posts: 574

Re: FlurrySH - Flurry analytic for Shiva (iOS & Android)

Postby giggsy » 04 Jun 2012, 15:14

Try pressing F5 in Eclipse on the project root
User avatar
giggsy
Platinum Boarder
Platinum Boarder
 
Posts: 1105
Location: Austria

Re: FlurrySH - Flurry analytic for Shiva (iOS & Android)

Postby redmotion » 04 Jun 2012, 18:03

Well F5 made appear ok, so thanks for that but I've probably put it in the wrong place or hooked up wrong.

The first line in the instructions says "import class sdg.utils.flurysh.android.FlurryAgentWrapper.java", but I've no idea what this means, I'm assuming this is why these errors are happening when I try to do a build:
[javac] C:Shiva_Projectseclipse_ChromaSphere_LiteChromaSphere_LitesrccomredmotiongameschromasphereliteChromaSphere_Lite.java:387: cannot find symbol
[javac] symbol : variable FlurryAgentWrapper
[javac] location: class com.redmotiongames.chromaspherelite.ChromaSphere_Lite
[javac] FlurryAgentWrapper.getInstance().startSession( this );
[javac] ^
[javac] C:Shiva_Projectseclipse_ChromaSphere_LiteChromaSphere_LitesrccomredmotiongameschromasphereliteChromaSphere_Lite.java:469: cannot find symbol
[javac] symbol : variable FlurryAgentWrapper
[javac] location: class com.redmotiongames.chromaspherelite.ChromaSphere_Lite
[javac] FlurryAgentWrapper.getInstance().endSession( this );
[javac] ^
[javac] Note: C:Shiva_Projectseclipse_ChromaSphere_LiteChromaSphere_LitesrccomredmotiongameschromasphereliteS3DSurfaceView.java uses unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 2 errors


EDIT: fixed it by adding import sdg.utils.flurrysh.android.FlurryAgentWrapper; to the myapp.java import declarations and removing the exclusions from the sdg folder.
User avatar
redmotion
Platinum Boarder
Platinum Boarder
 
Posts: 574

Re: FlurrySH - Flurry analytic for Shiva (iOS & Android)

Postby redmotion » 04 Jun 2012, 22:57

I've got a session registered on Flurry but as yet, no events recorded. Do they take longer to show up?
User avatar
redmotion
Platinum Boarder
Platinum Boarder
 
Posts: 574

Next

Return to Code Snippets