Starting a Session

From Fuseboxx Wiki
Jump to: navigation, search

Starting a Session

iOS

Earlier we showed you how to Track Session in order to check for Test Users. Now we will show you what else we can do with sessions. There is also a way to start a session without automatically registering for push notifications.

 -(void) applicationDidFinishLaunching:(UIApplication *)application{
     ...
     [FuseAPI startSession: @"<YOUR API KEY>"];
     
     //or with the delegate
     
     [FuseAPI startSession: @"<YOUR API KEY>" Delegate:<DELEGATE REFERENCE>];
 
     //Without registering for push tokens
 
     [FuseAPI startSession:@"<YOUR API KEY>" Delegate:<DELEGATE REFERENCE> AutoRegisterForPush:NO];
     ...
 }

The <DELEGATE REFERENCE> mentioned is a method of your choosing, after the startSession call is finished with the servers it makes a callback to <DELEGATE REFERENCE> so that <DELEGATE REFERENCE> will be called. As a convention we use startSessionRecieved, your startSessionRecieved method should do anything you want it to do with the data received from the Fuse Servers.


To create a FuseDelegate object, simply declare your object as follows:

 @interface YourFuseDelegate : NSObject <FuseDelegate>
 {
 }
 
 @end

The delegate protocol defines the following functions to signal the status of the startSession call (see FuseAPI.h file for full list of protocol functions):

 @protocol FuseDelegate <NSObject>
 @required
 -(void) sessionStartReceived;
 -(void) sessionLoginError: (NSNumber*) _error;
 @end


A recommended use for the startSessionRecieved method is to display an ad.

NoteBubble.png

startSession should be called early in the applicationDidFinishLaunching function in your application delegate.

Android

The most important function call is to register the start of an app session. The FuseBoxx™ servers identify the app using the "UNIQUE API KEY" that was generated for your app in the dashboard.

@Override
public void onCreate(Bundle savedInstanceState) {
   final Context appContext = getApplicationContext();
   final MessageCallback startSessionCallback = new MessageCallback(this){
       ...
   }

   FuseAPI.startSession("<UNIQUE API KEY>", this, appContext, startSessionCallback); 

} 

The Parameters of this call are:

game_id(APIkey): your app's API key (see Your API Keys page on FuseBoxx™)

activity_object: this if calling from main activity, null if otherwise

application_context: the application context (getApplicationContext())

MessageCallback: an object which is an instance of a class that extends the abstract class FuseCallback.java - You can also pass null. By extending the fuseCallback.java class you can implement the abstract methods.

Session information is the key metric used for tracking when a user is in the app, and is a component for certain KPI's (Key Performance Indicators). For example, in the main page of FuseBoxx™, the sessions per user KPI provides a means of gauging retention.

The Callback:

After you send a request to the FuseAPI, the FuseAPI will respond using callback functions. When you get a callback, you can handle the event as desired. For example, when you call startSession(), the corresponding callback is sessionStartReceived. You can override the function and handle the event anyway you want. As an example, you might want to show notifications or ads. To create a FuseCallback, simply declare the following object to pass into startSession:

 final MessageCallback startSessionCallback = new 
 MessageCallback(this) 
 { 
   @Override 
   public void sessionLoginError(int arg0) 
   { 
       // an error has occurred 
   } 

   @Override 
   public void sessionStartReceived() 
   { 
   } 

   // other abstract methods available 
 }; 

The delegate protocol defines the previous functions to signal the status of the sessionStart call (see FuseSDK.java file for full list of protocol functions).

startSession:

Override any of the functions and handle the event as you desire. For example, you can override the sessionStartReceived() function to display an ad:

@Override
public void sessionStartReceived(){
   FuseAPI.displayAd("", new FuseAdCallback(MainActivity.this);
}

FuseAdCallback: an object which is also an instance of a class that extends the abstract class FuseCallback.java - you can also pass a null.

suspendSession:

This function tracks each time a session has been suspended. It should be called in the onPause() method of the main activity.

 public static void suspendSession()
 
 //example
 protected void onPause(){
     FuseAPI.suspendSession();
 }

resumeSession:

This function tracks each time a session has been resumed. It should be called in the onResume() method of the main activity.

 public static void resumeSession(FuseCallback callback) {}
 
 //example
 @Override
 protected void onResume(){
     FuseAPI.resumeSession(this, new MessageCallback(this));
 }

MessageCallback: an object which is also an instance of a class that extends the abstract class FuseCallback.java - you can also pass a null.

endSession:

Should be called in the onTerminate() method of the application or onDestroy() of the main activity.

 public static void endSession() {}
 
 //example
 protected void onDestroy() { 
     FuseAPI.endSession();
 }

Unity

In Unity, the Fuse session is started automatically so there is nothing you need to do.

Adobe AIR

Overview

The very first thing you'll have to do is register the start of a session using the start session function. This tells our servers that a session has begun, and will immediately begin tracking session information. By passing your app's assigned API key to the start session function, it will authenticate your application with the Fuse servers.

You will want to call startSession as soon as your app is initialized.

Integration

public class YourApp extends app {
     fuse = new AirFuseAPI();
     fuse.startSession('<YOUR FUSE API KEY>');
}

Your API key is generated when you add your app to FuseBoxx™. It can be found in the configuration tab in a specific game, or the (Admin>Integrate SDK>Your API Keys) section of FuseBoxx™. The API key is a 36-digit unique ID.

Marmalade

The most important function call is to register the start of an app session. By passing it the assigned API key, this function will authenticate your application with the Fuse servers. To set up Marmalade to work with both iOS and Android, use the following code.

if (s3eDeviceGetInt(S3E_DEVICE_OS) == S3E_OS_ID_IPHONE)
{
    FuseAPIStartSession("Your iOS API Key");
}
else
{
    FuseAPIStartSession("Your Android API Key");
}

Note that either of the FuseAPIStartSession calls will work by themselves. If you are only developing an app for one platform, the if statement is unnecessary.

Session information is the key metric used for tracking when a user is in the app, and is a component for a certain KPI's (Key Performance Indicators). For example, in the main page of FuseBoxx™, the session per user KPI provides a means of gauging retention.

Your API key is generated when you add your App to FuseBoxx™. It can be found in the configuration tab in a specific game, or in the "Integrate API" section of FuseBoxx™ (Admin Tab > Integrate SDK on FuseBoxx™.com). The API key is s 36-digit unique ID.