Kony Fabric console User Guide: SDKs > Android SDK > Metrics Service Object APIs

Invoking a Metrics Service

When the Android SDK is initialized, it will automatically collect various standard metrics from a client and the standard metrics will be accessible using the Standard Reports within Console.

The AndroidSDK also provides the ability for a developer to send additional custom metrics from a client app to back-end to capture additional information. These custom data sets will be accessible using the Custom Reporting feature within Console where a business analyst can design and share reports using a combination of standard and custom metrics.

Additionally, the Android SDK provides an Events API that allows an app to track user actions within the app to gain insight into the user journey.The developer can send various standard events such as form entry, touch events, service requests, gestures and errors. The developer can also send custom events to capture any app specific scenarios or transactions. These events can be analyzed within Console by using the Standard Reports or user defined Custom Reports. For more details, refer to Custom Metrics and Reports Guide.

This section lists all MetricsService object APIs.

Create an instance of MetricsService

The MetricsService class sets the configuration for APM event reporting.

 //Sample code to create an instance of MetricService with variable name "getMetricsService"
mKonyClient = new KonyClient();
MetricsService metricsClient = null;
try {
    metricsClient = mKonyClient.getMetricsService();
} catch (KonyCMSException e) {
    e.printStackTrace();

setUserID

The setUserID API sets the user ID for the data gathered from an application. The user ID allows the data to be tracked on a user basis for broad analysis like how many different users used the application. It also helps to track activities of a specific user, which can help in seeing what activities were done before a crash, or what events led to a transaction not passing through. The user ID allows the same user to be tracked across different devices as well.

 //Sample code to set up the user ID of application user
String mUserId = "<user-id>";
metricsClient.setUserId(mUserId);

Note:  The UserId related to metrics. The UserId length cannot be more than 100 characters.

sendEvent

The sendEvent API allows a developer to send event details from an application to server for analytics and reporting purposes. The event data is added to a buffer and sent to server as per configuration values set by the developer using setEventConfig API.

 //Sample code to send reports
String eventSubType = "<event-sub-type>";
String formID = "<form-id>";
String widgetID = "<widget-id>";
String flowTag = "<flow-tag>";
String metaData = "<meta-data>";
try {
    metricsClient.sendEvent(MetricsService.EventType.EVENT_TYPE_CUSTOM, eventSubType, formID, widgetID, flowTag, metaData);
} catch (KonyCMSException e) {
    e.printStackTrace();
}

The following are the enums event types with values:

The following are the parameters for an event type:

flushEvents

The flushEvents API allows a developer to force events to be sent to the server. The entire current event buffer is loaded and sent to the server for processing. The flushEvents API used as an override to send event data to server before the configured value or a service call that flushes the buffer.

 //Sample code to flushEvents

metricsClient.flushEvents();

getEventsInBuffer

The getEventsInBuffer returns a list of the buffered events.

 //Sample code to eventsInBuffer
Vector < Hashtable > bufferEvents = metricsClient.getEventsInBuffer();

setFlowTag

The setFlowTag API sets an event flow tag to be associated with all new events that are reported by using the sendEvent API.The flow tag is used to ease searching event data in terms of application flows like loginflow, searchflow. The setFlowTag also helps sorting and filtering data while building custom reports or running standard reports for the application events.

 //Sample code to setFlowTagString myFowTag = "<flow-tag>";
try {
    metricsClient.setFlowTag(myFowTag);
} catch (KonyCMSException e) {
    e.printStackTrace();
}

clearFlowTag

The clearFlowTag API clears the currently set event flow tag.

 //Sample code to clearFlowTag
metricsClient.clearFlowTag();

getFlowTag

The getFlowTag API gets the currently set event flow tag.

 //Sample code to getFlowTag
String mFlowTag = metricsClient.getFlowTag();

reportError

The reportError API enables an app to report an error event to metrics server.

 //Sample code to reportError
String errorcode = "<error-code>";
String errorType = "<error-type>";
String errorMessage = "<error-message>";
String errorDetails = "<error-details>";
try {
    metricsClient.reportError(errorcode, errorType, errorMessage, errorDetails);
} catch (KonyCMSException e) {
    e.printStackTrace();
}

Parameters:

reportHandledException

The reportHandledException API enables apps to report a handled exception event.

 //Sample code to send exception to metrics server
String exceptioncode = "<exception-code>";
String exceptionType = "<exception-type>";
String exceptionMessage = "<exception-message>";
String exceptionDetails = "<exception-details>";
try {
    metricsClient.reportHandledException(exceptioncode, exceptionType, exceptionMessage, exceptionDetails);
} catch (KonyCMSException e) {
    e.printStackTrace();
}

Parameters:

setEventConfig

The setEventConfig API takes the required values to set the event configuration values. When eventConfigType is - CONF_TYPE_BUFFER event autoFlushCount and maxBufferCount are considered.

 //Sample code to setEventConfig
int autoFlushCount = 20;
int maxBufferCount = 800;
try {
    metricsClient.setEventConfig(MetricsService.EventConfigType.CONF_TYPE_BUFFER, autoFlushCount, maxBufferCount);
} catch (KonyCMSException e) {
    e.printStackTrace();
}

Parameters:

setBatchSize

The setBatchSize API allows a developer to specify the batch size to be set to flush events. Default batch size is 50.

 //Sample code to set batch size to flush eventsint batchSize = 20;
try {
    metricsClient.setBatchSize(batchSize);
} catch (KonyCMSException e) {
    e.printStackTrace();
}

sendCustomMetrics

The sendCustomMetrics API sends custom metrics event.

 //Sample code to send data to reporting service with group id as "formID"
Hashtable mtable = new Hashtable();
mtable.put("<key>", "<Values>");
String key = "<metrics-key>";
metricsClient.sendCustomMetrics(formID, mtable);

For more details about custom metrics and reports, refer to Custom Metrics and Reports Guide.

Parameters:

Event Details

For all event details, ts and SID values are automatically filled by MBaaS Client SDK, as part of the reportEvent, reportError and reportHandledException API calls. In case of automatically captured events, flowTag is also automatically filled with the currently set flowTag. Following are event specific details to be used while interfacing with MBaaS SDK.

FormEntry

FormExit

Touch

ServiceRequest

ServiceResponse

Gesture

Orientation

Error

HandledException

Crash

Custom

AppTransition

AppLoad

Copyright © 2020 Kony, Inc. All rights reserved.