Tracking User Activity Time/Length

You can also track total time spent by the user in completing specific activity/event. For example, you can track total/average time spent by app users in completing level x in your app. This can be achieved by putting an API hook at the start and end of level x in your game as shown in below snippet.

Start Activity

To start tracking the activity time, put the following at the start of the activity. For example, if the user has started playing level X, you can pass the name of the activity as level X in the method startActivity.

  • create User Api for Android
  • create User Api for J2ME
  • create User Api for Android
  • create User Api for iOS
  • create User Api for Java
  • create User Api for .NET
  • create User Api for Unity
  • create User Api for Ruby
  • create User Api for Rest
  •  create User Api for WP7/WP8
  • create User Api for Flash
String activityName = "Level1";
JSONObject properties = new JSONObject ();
properties.put ("Name", "Level1");
properties.put ("State", "Started");
properties.put ("Score", 0);
properties.put ("Difficulty", "Easy");
properties.put ("IsCompletedSecretMission", false);
eventService.startActivity(activityName, properties, new App42CallBack() {
public void onSuccess(Object response) 
{
	App42Response app42Response = (App42Response) response;   
	System.out.println("App42Response Is : " + app42Response);
}
public void onException(Exception ex) 
{
	System.out.println("Exception Message"+ex.getMessage());
}
});		            
		
NSString *activityName = @"Level1";
NSDictionary *properties = @{@"key": @"value"};
App42Response *response = [eventService startActivityWithName:activityName andProperties:properties];
NSLog(@"IsResponseSuccess = %d",response.isResponseSuccess);
Coming Soon
Coming Soon
var activityName = "Level1";
var properties = "{\"Name\":\"Level1\",\"State\":\"Started\"}"
eventService.startActivity(activityName, properties, {
	success: function (object) {
		var eventObj = JSON.parse(object)
		console.log("Success is :: " + eventObj);
	},
	error: function (error) {
		console.log("Exception is: " + error);
	}
});
Coming Soon
String activityName = "Level1";
Dictionary<String,object> properties = new Dictionary<string, object> ();
properties.Add ("Name", "Level1");
properties.Add ("State", "Started");
properties.Add ("Score", 0);
properties.Add ("Difficulty", "Easy");
properties.Add ("IsCompletedSecretMission", false);
App42Log.SetDebug(true);		//Prints output in your editor console
eventService.StartActivity(activityName, properties, new UnityCallBack()); 
public class UnityCallBack : App42CallBack
{
	public void OnSuccess(object response)
	{
		App42Response app42Response = (App42Response) response;   
		App42Log.Console("App42Response Is : " + app42Response);
	}
	public void OnException(Exception e)
	{
		App42Log.Console("Exception : " + e);
	}
}
Coming Soon
Coming Soon
Coming Soon
Coming Soon
NA

End Activity

At the finish of the activity, use the following to mark the finish. You have to pass the same name of activity which was used to start. In this example, we are using level1 as the name of the activity.

  • create User Api for Android
  • create User Api for J2ME
  • create User Api for Android
  • create User Api for iOS
  • create User Api for Java
  • create User Api for .NET
  • create User Api for Unity
  • create User Api for Ruby
  • create User Api for Rest
  •  create User Api for WP7/WP8
  • create User Api for Flash
String activityName = "Level1";
JSONObject properties = new JSONObject ();
properties.put ("Name", "Level1");
properties.put ("State", "Ended");
properties.put ("Score", 40000);
properties.put ("Difficulty", "Easy");
properties.put ("IsCompletedSecretMission", true);
eventService.endActivity(activityName, properties, new App42CallBack() {
public void onSuccess(Object response) 
{
	App42Response app42Response = (App42Response) response;   
	System.out.println("App42Response Is : " + app42Response);
}
public void onException(Exception ex) 
{
	System.out.println("Exception Message"+ex.getMessage());
}
});		             
		
NSString *activityName = @"AppOpen";
NSDictionary *properties = @{@"key": @"value"};
App42Response *response = [eventService endActivityWithName:activityName andProperties:properties];
NSLog(@"IsResponseSuccess = %d",response.isResponseSuccess);
Coming Soon
Coming Soon
var activityName = "Level1";
var properties = "{\"Name\":\"Level1\",\"State\":\"Ended\"}"
eventService.endActivity(activityName, properties, {
	success: function (object) {
		var eventObj = JSON.parse(object)
		console.log("Success is :: " + eventObj);
	},
	error: function (error) {
		console.log("Exception is: " + error);
	}
});
Coming Soon
String activityName = "Level1";
Dictionary<String,object> properties = new Dictionary<string, object> ();
properties.Add ("Name", "Level1");
properties.Add ("State", "Ended");
properties.Add ("Score", 40000);
properties.Add ("Difficulty", "Easy");
properties.Add ("IsCompletedSecretMission", true);
App42Log.SetDebug(true);		//Prints output in your editor console
eventService.EndActivity(activityName, properties, new UnityCallBack()); 
public class UnityCallBack : App42CallBack
{
	public void OnSuccess(object response)
	{
		App42Response app42Response = (App42Response) response;   
		App42Log.Console("App42Response Is : " + app42Response);
	}
	public void OnException(Exception e)
	{
		App42Log.Console("Exception : " + e);
	}
}
Coming Soon
Coming Soon
Coming Soon
Coming Soon
NA

Activity Report

You can view reports of tracked activities i.e. you can measure currently started activities along with average time spent in completing those activities as shown below:

ActivityReport

More Details?

bullet Go To Event Service Usage Guide