Sending Event Data from the Mobile App

Here is how we upload Event Data.

  1. Create a KiiEvent instance by calling the event method while specifying an "event type" (optional).

    This event type can be any string such as "installed" or "level up". It will be used for filtering the event data in the case when you've set a filter in your metric definition.

    In our example, we are setting "MyUser" as the event type.

  2. Set arbitrary key-value pairs in the instance with the set method.

    In our example, we will set key-value pairs such as "gender", "city", "location", "children" and "age".

  3. Call the push method to cache the event data. It will be automatically uploaded to Kii Cloud in an optimal interval.

Check the following sample code:

  • // Create a KiiEvent instance.
    KiiEvent event = KiiAnalytics.event("MyUser");
    
    // Set key-value pairs.
    event.set("gender", "M");
    event.set("city", "San Francisco");
    event.set("location", "US");
    event.set("children", 2);
    event.set("age", 35);
    
    // Upload the event data to Kii Cloud.
    try {
        event.push();
    } catch (IOException e) {
      // Handle the error.
    }
  • // Create a KiiEvent instance.
    KiiEvent event = KiiAnalytics.event("MyUser");
    
    // Set key-value pairs.
    event.set("gender", "M");
    event.set("city", "San Francisco");
    event.set("location", "US");
    event.set("children", 2);
    event.set("age", 35);
    
    // Upload the event data to Kii Cloud.
    event.push(new KiiEventCallback() {
      @Override
      public void onPushCompleted(KiiEvent target, Exception exception) {
        if (exception != null) {
          // Handle the error.
          return;
        }
      }
    });