-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
The starting point is to create the brand new Xcode application project. But since you are here, I think, you already have one. So, let's import the SDK's core library into the project. All the following instructions will be illustrated with the screenshots, it will not take much time.
1. Drag and drop Library files to your project files, as at a picture
2. Pop-up with options to add files will appear. Make sure, that in Destination the "Copy times if needed" box is checked.
3. With library integrated, to make sure, that there no problem appeared - make testing build of an Application (cmd + B).
Let's move to the actual programming and start with the SDK initialisation. To properly initialise Gravitum iOS SDK and the following code to the didFinishLaunchingWithOptions method on your AppDelegate.m class.
#!Objective C
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
Analytics * analytics = [[Analytics getAnalytics] initWithParameters:AppToken
AppSecret:AppSecret
SenderId:SenderId];
/////////////////////////////////////////////////////////////////////////////////
// Optional
[analytics SetUserId: userID];
[analytics SetUserName: userName;
[analytics SetGender: (Gender*)userGender];
[analytics SetBirthday: userBirthDay
monthBorn: userBirthMonth
yearBorn: userBirthYear
];
// Optional end
/////////////////////////////////////////////////////////////////////////////////
[analytics Init]; //Launch analytics;
return YES;
}The main aspects are [analytics initWithParameters] (the place, where Analytics takes main key parameters), and [analytics Init] - method, which begins Analytics initialization. Important: All the method calls between [analytics initWithParameters] and [analytics Init] methods - are optional methods. Those methods used to set additional user metadata.
Now we have done with SDK initialisation and ready to go with the events tracking.
The simplest way to send events shown below. Use this method if you don't need to send the data with your event. When just the event Id will be enough for you. Take a look at the following code snippet
#!Objective C
[[Analytics getAnalytics] SendEvent:@"First_Start"];To send custom event with data bundle use following code sample. You can provide any event data you want as a NSDictionary or NSMutableDictionary. What data to send with analytics event depends on your game project.
#!Objective C
NSMutableDictionary<NSString*,NSObject*>* eventData = [[NSMutableDictionary<NSString*,NSObject*> alloc] init];
[eventData setValue:@"Hello_data" forKey:@"custom_string_data"];
[eventData setValue:[NSNumber numberWithInteger:10101] forKey:@"custom_int_data"];
[[Analytics getAnalytics] SendEvent:@"sample_event" data:eventData];One more specific Analytics avant type is Purchase event. The common approach is to track the In-App Purchases with such kind of events. So, send this event every success 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. Purchase event use example is following
#!Objective C
[[Analytics getAnalytics] SendMonetaryEvent:@"coins" price:0.99 currency:@"USD"];The last but not least is session tracking feature of Gravitum Service. To setup tracking you have to add two method calls in the right places of your AppDelegate.m class. The first one is [[Analytics getAnalytics] SessionStart];. Add this method to applicationDidBecomeActive method as shown below.
#!Objective C
- (void)applicationDidBecomeActive:(UIApplication *)application {
[[Analytics getAnalytics] SessionStart];
}[[Analytics getAnalytics] SessionEnd]; method should be called from applicationWillResignActive method from you main activity.
#!Objective C
- (void)applicationWillResignActive:(UIApplication *)application {
[[Analytics getAnalytics] SessionEnd];
}
Important: You shouldn't send any event according to tracking session length. All the duration tracking events will be sent under the hood. Game session metrics you will find in your Gravitum Developer Dashboard. If you need more detailed information about each API, you can find all the SDK API References here.


