Kony Fabric console User Guide: SDKs > Kony Visualizer SDK > Invoking a Metrics Service

Invoking a Metrics Service Object

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

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

Additionally, the JS 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 application specific scenarios or transactions. These events can be analyzed within Kony Fabric 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.

Note: On SDK initialization, the Metrics Service is available with the variable name KNYMetricsService.

Configuring Application Events Reporting

The MetricsService class sets the configuration for APM event reporting.

* @param reportingMode{string }specifies the event reporting mode which can be currently only set to "Buffer"

* @param bufferAutoFlushCount{number }In case the reportingMode is set to Buffer, this property specifies the number of events to be buffered before flushing.

* @param maxBufferCount{number }In case the reportingMode is set to Buffer, this property specifies the maximum number of events that can be buffered. Events exceeding the maxBufferCount will be ignored.

* @Availability Applicable on All native Platforms (iOS, Android)

 //Sample code to set the configuration for application events.
KNYMetricsService.setEventConfig("Buffer", 50, 200);

setBatchSize

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

Parameters:

//Sample code to set batch size to flush events
KNYMetricsService.setBatchSize(20);

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.

setUserID = function( /**string */ setUserId, ) {}
//Sample code to set up the user ID of application user
kony.setUserID("myUserID");

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

Note: KNYMetricsService.setUserId has been removed from apps built with Kony Visualizer Enterprise.

sendEvent

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

Note:  From Kony V8 SP3 and latest plug-in versions of 7.2, 7.3, V8.2 and above, the sendEvent API will not capture the network calls to image URLs as part of serviceRequest/serviceResponse events. This is applicable for both manual invocation from an application code and for events captured automatically from the Project Settings.

sendEvent = function( /**string */ eventType, /**string */ eventSubType, /**string */ formID, /**string */ widgetID, /**string */ flowTag, /**JSObject [Key value pairs]*/ metaInfo) {}
//Sample code to send reports
KNYMetricsService.sendEvent("FormEntry", "frmHome", "frmHome", "widgetID", "flowTag", {
    "key1": "value1"
});

Note: This API is required to be used only if the application developer chooses to send their own custom events. All event types chosen for automatic event tracking from the Metrics APM tab in application properties or set using the setEventTracking API will automatically be tracked.

setFlowTag

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

setFlowTag = function( /**string */ flowtag, ) {}
//Sample code for the setFlowTag API
KNYMetricsService.setFlowTag("MyFlowTag");

setEventTracking

The setEventTracking API sets the event types to be tracked.

getEventTracking

The getEventTracking API gets the list of all event types that are being tracked currently.

getEventTracking = function() {}
//Sample code for the getEventTracking API

var events = KNYMetricsService.getEventTracking();

clearFlowTag

The clearFlowTag API clears the currently set event flow tag.

clearFlowTag = function() {}
//Sample code for the clearFlowTag API
KNYMetricsService.clearFlowTag();

getFlowTag

The getFlowTag API gets the currently set event flow tag.

getFlowTag = function() {}
//Sample code for the getFlowTag API

var flowtag = KNYMetricsService.getFlowTag();

reportError

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

reportError = function( /**string */ errorCode, /**string */ errorType, /**string */ errorMessage, /**string */ errorDetails, ) {}
//Sample code for the reportError API
KNYMetricsService.reportError("1234", "SpecificError", "custom error message", "{errfile:file.js}");

Note:  This API is required to be used only if the application developer chooses to send their own error events. If Error event type is chosen for supported platforms via application properties or setEventTracking API, error tracking will automatically be done.

reportHandledException

The reportHandledException API enables apps to report a handled exception event. Application developers can use this API to report handled exceptions in the application code.

reportHandledException = function( /**string */ exceptionCode, /**string */ exceptionType, /**string */ exceptionMessage, /**string */ exceptionDetails, ) {}
//Sample code to send exception to metrics server
KNYMetricsService.reportHandledException("1234", "SpecificException", "custom exception message", "{errfile:file.js}");

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 is used as an override to send event data to a server before the value configured in seteventconfig for autoflushcount is reached.

flushEvents = function() {}
//Sample code for the flushEvents API
KNYMetricsService.flushEvents();

sendCustomMetrics

The sendCustomMetrics API allows the developer to send custom metrics from the application.

The custom metrics keys should already be registered in Kony Fabric Console for the application before data is sent from the application.

sendCustomMetrics = function( /**JSObject [Array]*/ groupId, /**data*/ data, ) {}
//Sample code for the sendCustomMetrics API
KNYMetricsService.sendCustomMetrics("formID", {
    "metric": "metricdata"
});

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

Global Error Handler

The uncaughtexceptionhandler APIs are available only for iOS and Android native apps built from Kony Visualizer.

setUncaughtExceptionHandler

This API allows a developer to register a callback function to be invoked for uncaught JS exception.

kony.lang.setUncaughtExceptionHandler("< Callback function for ErrorHandling >");
//Sample code for the setUncaughtExceptionHandler API
function myErrorHandler() {}
kony.lang.setUncaughtExceptionHandler(myErrorHandler);

getUncaughtExceptionHandler

This API allows a developer to get the function that is currently registered for the uncaught JS exceptions.

//Sample code for the getUncaughtExceptionHandler API
kony.lang.getUncaughtExceptionHandler()

Event Details

For all event details, timestamp of event and session identifier 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. The following are event specific details to be used while interfacing with MBaaS SDK while manually invoking sendEvent API to send event data.

FormEntry

FormExit

Touch

ServiceRequest

ServiceResponse

Gesture

Orientation

Error

HandledException

Crash

Custom

Copyright © 2020 Kony, Inc. All rights reserved.