Cordova Integration Guide

This topic describes how integrate Workspace ONE Intelligence SDK into a Javascript Cordova application. The Cordova plugin is available for iOS and Android.

Installing the Workspace ONE Intelligence Cordova Plugin

You will need Cordova-4.0.0 or higher.

  1. Assuming you release your Cordova app on both Android and iOS, you will need an app ID for each. Both of these app IDs are passed to the plugin at initialization time.

  2. To integrate the WS1Intelligence plugin, run the following command from your application directory:

cordova plugin add cordova-plugin-ws1intelligence
  1. Initialize WS1Intelligence. Call WS1Intelligence.init() after the plugins are installed. This can be done from the onDeviceReady() function.

document.addEventListener('deviceready', onDeviceReady, false);

function onDeviceReady() {
   WS1Intelligence.init({ 'iosAppID' : 'YOUR_IOS_APP_ID',
                          'androidAppID' : 'YOUR_ANDROID_APP_ID'});
}

That’s it! You’re now ready to build and run your app.

App Loads

App Load events for a particular device are automatically tracked by the SDK after initialization.

App Loads are detected at two different times:

  1. At SDK initialization time. (Assumed to be app launch time)

  2. When the application is foregrounded by the user after a minimal amount of time in the background.

Network Insights

Network traffic can be logged manually through the Cordova plugin.

String method = "GET";
String url = "http://www.abc123def456.com";
long latency = 2000;
long bytesRead = 10000;
long bytesSent = 100;
int responseCode = 200;
int errorCode = 0;

WS1Intelligence.logNetworkRequest(method,
                                  url,
                                  latency,
                                  bytesRead,
                                  bytesSent,
                                  responseCode,
                                  errorCode);

Arguments

Name

Description

method

String HTTP verb such as “GET”, “HEAD”, “POST”, “PUT”, “DELETE”, “TRACE”, “OPTIONS”, “CONNECT”, or “PATCH” .

url

String, representing the contacted endpoint

latency

Number, representing the time between start of request and receipt of response, in milliseconds

bytesRead

Number, the number of bytes included in response body

bytesSent

Number, the number of bytes included in request body

responseCode

Number, HTTP status code, generally 100-599, e.g. 200 == OK, 400 == Bad Request, can be 0 if there is an error

errorCode

Number, a non-zero error code can be logged if network request failed to contact server, etc. Pass 0 if there was no error.

Logging User Flows

Use the beginUserFlow, endUserFlow, failUserFlow, and cancelUserFlow methods to utilize the User Flow feature.

User flows allow developers to track key interactions or user flows in their app such as login, account registration, and in app purchase. The Workspace ONE Intelligence SDK will automatically track application load time as a user flow. You can specify additional user flows by adding code to your application.

Beginning a user flow starts a user flow. Ending, failing, or cancelling a user flow stops a user flow. Otherwise, the user flow will be marked as crashed or timed out. If a crash occurs, all in progress user flows are marked crashed and will be reported with the crash.

All user flows will appear on Workspace ONE Intelligence portal except for cancelled user flows.

User flows with the same name are aggregated together in the portal by Workspace ONE Intelligence. Only one user flow for a given name can be in progress at a given time. If you begin a second user flow with the same name while another is in progress, the first user flow will be cancelled and the new one will take its place.

Here’s an example of how to log a single User Flow using the Cordova plugin:

WS1Intelligence.beginUserFlow("login");

// Run the code you want to monitor
var didLogin = runMyLoginCode();
if (didLogin) {
    WS1Intelligence.endUserFlow("login");
} else {
    WS1Intelligence.failUserFlow("login");
}

Starting a User Flow

Beginning a user flow tells Workspace ONE Intelligence SDK that the user flow has started. Workspace ONE Intelligence SDK starts timing the duration of the user flow and waits for the user flow to succeed, fail, or be cancelled in code.

Here’s an example of how to begin a User Flow:

WS1Intelligence.beginUserFlow("my_user_flow_name");

Ending a User Flow

Ending a user flow tells Workspace ONE Intelligence SDK that the given user flow has successfully completed. At this point, the user flow time is recorded, and the user flow will be reported to Workspace ONE Intelligence.

Here’s an example of how to end a User Flow, which is the same as marking it as succeeded:

WS1Intelligence.endUserFlow("my_user_flow_name");

Failing a User Flow

Failing a user flow tells Workspace ONE Intelligence SDK that the given user flow has failed. At this point, the user flow time is recorded, and the user flow will be reported to Workspace ONE Intelligence.

Here’s how to mark a User Flow as failed:

WS1Intelligence.failUserFlow("my_user_flow_name");

Cancelling a User Flow

Cancelling a user flow tells Workspace ONE Intelligence SDK that the given user flow has been cancelled. The user flow is not recorded and will not be reported to Workspace ONE Intelligence.

If a developer does not specify success, failure, or cancelled in code, then the only possible remaining final states a user flow can reach are crashed and timed out. See User Flows Final States for more information.

Here’s how to mark a User Flow as cancelled:

WS1Intelligence.cancelUserFlow("my_user_flow_name");

Logging Breadcrumbs

Use the leaveBreadcrumb API to write to a chronological log that is reported with crashes and exceptions.

A breadcrumb is a developer-defined text string (up to 140 characters) that allows developers to capture app run-time information. Example breadcrumbs may include variable values, progress through the code, user actions, or low memory warnings. For an introduction, see Breadcrumbs.

Here’s an example of how to leave a breadcrumb:

WS1Intelligence.leaveBreadcrumb("User tapped a button");

Logging Crashes

The WS1 Intelligence SDK will automatically detect application crashes and report them as it would in a native app.

Check Previous Session for Crash

If a crash occurred in the previous session, the plugin will respond with TRUE when the didCrashOnLastLoad function is called.

var callback = function(didCrash) {
  alert("didCrashOnLastLoad value is " + didCrash);
}

WS1Intelligence.didCrashOnLastLoad(callback);

Logging Cordova Exceptions

Use the logHandledException API to track error conditions that do not necessarily cause a crash.

Handled exceptions may be used for tracking exceptions caught in a try/catch statement, 3rd party library exceptions, and monitoring areas in the code that may currently be using assertions. Handled exceptions can also be used to track error events such as low memory warnings. For an introduction, see Handled Exceptions.

Handled exceptions are grouped by stacktrace, much like crash reports. Exceptions that are reported from cross-platform development environments, such as Cordova, Xamarin, or Flutter, are reported separately from native exceptions. Plugin Exceptions may be viewed in the “Plugin Exceptions” area of the Workspace ONE Intelligence portal.

A non-native app can report both native and plugin exceptions.

Here’s an example of how to log a plugin exception:

try {
  JSON.parse('this is not valid json');
} catch(e) {
  WS1Intelligence.logHandledException(e);
}

Setting a Username

Setting a username will allow the ability to monitor app performance for each user. We recommend setting a username to a value that can be tied back to your customer support system.

Here’s an example of how to set a user name:

WS1Intelligence.setUsername("current_user_name");

Opting In and Out of Analytics

Analytics reporting can be turned on and off client-side using the setOptOutStatus function in the Cordova plugin:

WS1Intelligence.setOptOutStatus(true);

You can check the opt-out status using the getOptOutStatus function at any time:

WS1Intelligence.getOptOutStatus(function(status) {
  alert("Opt Out Status: " + status);
});