Sending Event Data from the Mobile App

Here is an example of how you can upload an Event Data.

  1. Set an event data with arbitrary key-value pairs. In our example, we are setting key-value pairs such as "gender", "city", "location", "children" and "age".

  2. Calls the trackEvent method while specifying an "event type" and the event data (optional). The event type can be any string like "installed" or "level up". When you specify "Filter by type" section during your Metric definition, this event type value will be used to filter the target data. In our example, we are using "MyUesr".

Objective-C:

// Set an event type.
NSString *eventType = @"MyUser";

// Set key-value pairs.
NSMutableDictionary* extras = [NSMutableDictionary dictionary];
[extras setObject:@"M" forKey:@"gender"];
[extras setObject:@"San Francisco" forKey:@"city"];
[extras setObject:@"US" forKey:@"location"];
[extras setObject:[NSNumber numberWithInt:2] forKey:@"children"];
[extras setObject:[NSNumber numberWithInt:35] forKey:@"age"];

// Upload the event data to Kii Cloud.
BOOL success = [KiiAnalytics trackEvent:eventType withExtras:extras];
if (!success) {
  // Handle the error.
  return;
}

Swift:

// Set an event type.
let eventType = "MyUser"

// Set key-value pairs.
var extras = [String:AnyObject]()
extras["gender"] = "M"
extras["city"] = "San Francisco"
extras["children"] = 2
extras["age"] = 35

// Upload the event data to Kii Cloud.
let success = KiiAnalytics.trackEvent(eventType, withExtras: extras)
if (!success) {
  // Handle the error.
  return
}

The trackEvent method will send the event data. This method acts as a non-blocking API. If sending the event data failed, it will be resent the next time the trackEvent method is executed.