This topic describes how integrate Workspace ONE Intelligence SDK into a Javascript Cordova application. The Cordova plugin is available for iOS and Android.
You will need Cordova-4.0.0 or higher.
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.
To integrate the WS1Intelligence plugin, run the following command from your application directory:
cordova plugin add cordova-plugin-ws1intelligence
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 Load events for a particular device are automatically tracked by the SDK after initialization.
App Loads are detected at two different times:
At SDK initialization time. (Assumed to be app launch time)
When the application is foregrounded by the user after a minimal amount of time in the background.
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 |
---|---|
|
String HTTP verb such as “GET”, “HEAD”, “POST”, “PUT”, “DELETE”, “TRACE”, “OPTIONS”, “CONNECT”, or “PATCH” . |
|
String, representing the contacted endpoint |
|
Number, representing the time between start of request and receipt of response, in milliseconds |
|
Number, the number of bytes included in response body |
|
Number, the number of bytes included in request body |
|
Number, HTTP status code, generally 100-599, e.g. 200 == OK, 400 == Bad Request, can be 0 if there is an error |
|
Number, a non-zero error code can be logged if network request failed to contact server, etc. Pass 0 if there was no error. |
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");
}
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 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 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 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");
The WS1 Intelligence SDK will automatically detect application crashes and report them as it would in a native app.
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);
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 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");
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);
});