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 trackEventWithExtrasAndCallbacks 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".

  • // Initialize the Kii Cloud SDK with the analytics option.
    Kii.initializeWithSite("<AppID>", "<AppKey>", KiiSite.US, deviceID);
    
    ......
    
    // Set an event type.
    var eventType = "MyUser";
    
    // Set key-value pairs.
    var extras = {
      "gender": "M",
      "city": "San Francisco",
      "location": "US",
      "children": 2,
      "age": 35
    };
    
    // Upload the event data to Kii Cloud.
    KiiAnalytics.trackEventWithExtrasAndCallbacks(eventType, extras, {
      success: function() {
        // Do something.
      },
      failure: function(errorString) {
        // Handle the error.
      }
    });
  • // Initialize the Kii Cloud SDK with the analytics option.
    Kii.initializeWithSite("<AppID>", "<AppKey>", KiiSite.US, deviceID);
    
    ......
    
    // Set an event type.
    var eventType = "MyUser";
    
    // Set key-value pairs.
    var extras = {
      "gender": "M",
      "city": "San Francisco",
      "location": "US",
      "children": 2,
      "age": 35
    };
    
    // Upload the event data to Kii Cloud.
    KiiAnalytics.trackEventWithExtrasAndCallbacks(eventType, extras).then(
      function() {
        // Do something.
      }
    ).catch(
      function(error) {
        var errorString = error.message;
        // Handle the error.
      }
    );

You would have implemented the SDK initialization process as an event at completion of HTML page loading. Rewrite the Kii.initializeWithSite() method, which initializes the SDK, based on the above sample code.

Specify the device ID to the deviceID of the Kii.initializeWithSite(). The device ID should be different for each device or browser which runs the Web app. Generate a unique value such as UUID at the initial launch of the Web app to use it as the device ID. Store this value to a storage such as Web Storage to keep it unchanged after next launch. Specify the same value for subsequent launches.