API Reference - GravitumLabs/gravitum-ios-sdk GitHub Wiki
List Of Methods
- SetUserId
- SetUserName
- SetFacebookId
- SetDevicePushToken
- SetBirthday
- SetGender
- initWithParameters
- Init
- SendEvent
- SendMonetaryEvent
- SessionStart
- SessionEnd
SetUserId
SetUserId is optional method. You may provide your own user id as the unique user id for Gravitum service or you have your own web server with the custom player authentication), otherwise, it will be generated automatically. Just make sure, that the Id you provide will be unique for each user.
Parameters:
NSString newUserId - unique user Id depending on your implementation.
Example:
#!Objective C
Analytics * analytics = [[Analytics getAnalytics] initWithParameters:AppToken
AppSecret:AppSecret
SenderId:SenderId];
[analytics SetUserId:user_id];
[analytics Init];
SetUserName
To provide the user name use SetUserName method with the string name. Unlike the user ID, user name may not be unique. What name to provide is up to you without any restrictions.
Parameters:
String userName - user Name depending on your implementation.
Example:
#!Objective C
Analytics * analytics = [[Analytics getAnalytics] initWithParameters:AppToken
AppSecret:AppSecret
SenderId:SenderId];
[analytics SetUserName:user_name];
[analytics Init];
SetFacebookId
Set user's Facebook Id via SetFacebookId method call. The common approach if to get the user Facebook Id from Facebook SDK itself and provide to Gravitum Analytics.
Parameters:
NSString facebookId - the user Id from Facebook SDK.
Example:
#!Objective C
Analytics * analytics = [[Analytics getAnalytics] initWithParameters:AppToken
AppSecret:AppSecret
SenderId:SenderId];
[analytics SetFacebookId: facebookId];
[analytics Init];
SetDevicePushToken
If you have your own push notifications service implementation, you may use SetDevicePushToken method to provide the unique Id for each user device. If you don't pass any particular token, Gravitum will generate push token by itself via code in the the Init method.
Parameters:
NSString pushToken - the push token for current user device provided from your push notification service.
Example:
#!Objective C
Analytics * analytics = [[Analytics getAnalytics] initWithParameters:AppToken
AppSecret:AppSecret
SenderId:SenderId];
[analytics SetDevicePushToken:pushToken];
[analytics Init];
SetUserBirthday
The name of this method speaks for itself. Provide the user birthday via int's.
Parameters:
int userBirthDay - day of birth for current user. int userBirthMonth - month of birth for current user. int userBirthYear - year of birth for current user.
Example:
Analytics * analytics = [[Analytics getAnalytics] initWithParameters:AppToken
AppSecret:AppSecret
SenderId:SenderId];
[analytics SetBirthday:userBirthDay
monthBorn:userBirthMonth
yearBorn:userBirthYear];
[analytics Init];
SetUserGender
The name of this method speaks for itself. Provide the user gender via Gender enum constant.
Parameters:
(Gender)* gender - the gender of the current user.
Example:
#!Objective C
Analytics * analytics = [[Analytics getAnalytics] initWithParameters:AppToken
AppSecret:AppSecret
SenderId:SenderId];
[analytics SetGender:(Gender*)Male];
[analytics Init];
initWithParameters & Init
The main required methods you need to call to set up Gravitum Analytics. To properly initialize Gravitum iOS SDK add the following code to the didFinishLaunchingWithOptions method on your AppDelegate.m class.
Parameters:
NSString AppToken - the App Token provided to you by Gravitum.
NSString AppSecret - the App Token provided to you by Gravitum.
NSString SenderId - Please use @"" for now. This is in for a future feature.
Example:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
Analytics * analytics = [[Analytics getAnalytics] initWithParameters:AppToken
AppSecret:AppSecret
SenderId:SenderId];
[analytics Init]; //Launch analytics;
return YES;
}
SendEvent
The simplest way to send events. Use this method if you don't need to send any data/parameters with your event. When just the event Id will be enough for you.
Parameters:
NSString eventId - unique event Id depending on your implementation.
Example:
#!Objective C
NSString * eventId = @"First Start Of a Program";
[[Analytics getAnalytics] SendEvent:eventId];
or
#!Objective C
[[Analytics getAnalytics] SendEvent:@"First Start Of a Program"];
SendEvent (with event data)##
Send an event with provided Id and event data/params.
Parameters:
String eventId - unique event Id depending on your implementation.
NSMutableDictionary<NSString,NSObject>** eventData - you can provide any event data you want as a NSDictionary. What data to send with analytics event depends on your game project.
Example:
#!Objective C
NSMutableDictionary<NSString*,NSObject*>* eventData = [[NSMutableDictionary<NSString*,NSObject*> alloc] init];
[eventData setValue:@"string_data" forKey:@"custom_string_data"];
[eventData setValue:[NSNumber numberWithInteger:10101] forKey:@"custom_int_data"];
[[Analytics getAnalytics] SendEvent:@"sample_event" data:eventData];
SendMonetaryEvent
This specific Analytics event type is used to record a Purchase event. The common approach is to track the In-App Purchases with such kind of events. So, send this event on every successful In-App Purchase. Provide the product Id, price and the currency code of the real In-App Purchase. All these events you will find in one place in Gravitum Dashboard.
Parameters:
String eventId - unique In-App product Id.
double price - In-App product price.
String currency - user locale currency code. Please use ISO 4217
Example:
#!Objective C
NSString * eventId = @"coins";
double price = 0.99;
NSString * currency = @"USD";
[[Analytics getAnalytics] SendMonetaryEvent:eventId price:price currency:currency];
or
#!Objective C
[[Analytics getAnalytics] SendMonetaryEvent:@"coins" price:0.99 currency:@"USD"];
SessionStart
To setup session tracking you have to add two method calls in the right places of your AppDelegate.m class. The first one is SessionStart. Add this method to applicationDidBecomeActive method
Example:
#!Objective C
- (void)applicationDidBecomeActive:(UIApplication *)application {
[[Analytics getAnalytics] SessionStart];
}
SessionEnd
This method is used for sending the request to the server about game session stop. SessionEnd method should be called from applicationWillResignActive method of your main activity.
Example:
#!Objective C
- (void)applicationWillResignActive:(UIApplication *)application {
[[Analytics getAnalytics] SessionEnd];
}