This topic describes how to use Apteligent with HTML5. Apteligent provides the HTML5 library using a content delivery network (CDN) for simplicity so that you can get crash reporting up and running within your application as quickly as possible.
Obtain your app ID from Workspace ONE Intelligence platform.
To set up basic integration:
Include the following Apteligent Javascript library from our CDN in your HTML using a <script>
tag:
<script type="text/javascript" src="https://d1a62freaxhn7x.cloudfront.net/v2/24/crittercismClientLibraryMin.js"></script>
Call Crittercism.init
with your Apteligent App ID, when the document is ready (the document.ready
event).
The following example HTML document shows adding Apteligent to an application that uses jQuery.
<!DOCTYPE html>
<html>
<head>
<title>Example Document with Apteligent</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="https://d1a62freaxhn7x.cloudfront.net/v2/24/crittercismClientLibraryMin.js"></script>
<script type="text/javascript">
$(document).ready(function() {
Crittercism.init({
appId: 'appId', // Example: 47cc67093475061e3d95369d
appVersion: '1.0' // Developer-provided application version
});
});
</script>
</head>
</html>
Crittercism.init(options)
takes a single argument, options
.
The options
is a JSON dictionary containing key value pairs.
Keys
Name
Description
appId
AppId string obtained from Apteligent for a registered HTML5 app
appVersion
Developer-provided application version (optional)
debug
true
, causes HTML5 SDK to print messages to console.log (optional)
View the raw CrittercismIntegrationWithJQuery.html hosted on GitHub.
Now you have the basic crash reporting available from Apteligent. The rest of this topic describes optional features that you can add to your HTML code.
Note
Hybrid Apps don’t and shouldn’t call Crittercism.init()
.
Hybrid Apps should include Apteligent Javascript library
using a <script>
tag.
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. Handled exceptions may be viewed in the “Handled Exceptions” area of the Workspace ONE Intelligence portal.
Here’s an example of how to log a handled exception:
try {
JSON.parse('this isnt valid json');
} catch(e) {
Crittercism.logHandledException(e);
}
Developers can set user metadata to tracking information about individual users. For an introduction, see User Name.
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:
Crittercism.setUsername("TomCritter");
Note
The Logging Userflows API is currently only supported for Hybrid Apps . The Logging Userflows API methods currently act as NOP’s in pure HTML5 web apps.
Use the beginTransaction
, endTransaction
, and failTransaction
methods to log userflows.
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 userflow:
Crittercism.beginTransaction("login");
var didLogin = runMyLoginCode();
if didLogin {
Crittercism.endTransaction("login");
} else {
Crittercism.failTransaction("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 userflow:
Crittercism.beginTransaction("my_transaction");
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 userflow, which is the same as marking it as succeeded:
Crittercism.endTransaction("my_transaction");
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 userflow as failed:
Crittercism.failTransaction("my_transaction");
Use the setTransactionValue
method to modify the value of a userflow.
The value of a userflow should be specified in cents.
A developer may optionally set the value of each user flow. This allows stakeholders to more accurately evaluate the business impact of failing user flows. Setting user flows values within the app is most useful when the value of a user flow can change based on user interactions. One example is in-app purchases of varying quantities.
In addition to being able to specify user flows values in the code, a default user flows value may be specified in the Workspace ONE Intelligence portal. This allows changing user flows values on the fly.
var valueInCents = 999;
Crittercism.setTransactionValue("my_transaction", valueInCents);
Note
The Logging Network Requests API is currently only supported for Hybrid Apps . The Logging Network Requests API methods currently act as NOP’s in pure HTML5 web apps.
Use the logNetworkRequest
method to manually log network library network access to URL’s.
Here’s an example of how to log a network request:
Crittercism.logNetworkRequest("GET",
"http://www.abc123def456.com",
2000,
10000,
100,
200,
0)
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. |
The HTML5 SDK supports iOS and Android hybrid applications. A hybrid app is a mobile application built using both native code as well as javascript code which is run in a webview. Using the installation instructions below, you will be able to monitor the performance of both the native code as well as javascript code in the webview in a unified view.
To properly instrument a hybrid app, you’ll need to follow these steps:
Install the Apteligent Native SDK
Download and install the native Apteligent SDKs.
For iOS, follow the installation guide here: Installing Workspace ONE Intelligence SDK for iOS
For Android, follow the installation guide here: Installing the Android SDK
Initialize the Apteligent Native SDK
After the SDKs are installed, initialize the native Apteligent SDK in your app. To obtain an app_id, register an iOS or Android app and use the app_id for that app. Registering a separate HTML5 app is not necessary.
For iOS: Basic Setup
For Android: Initializing Workspace ONE Intelligence SDK
Enable Webview Monitoring
To monitor the performance of webviews including javascript error monitoring, enable monitoring the webview in the native SDK.
For iOS: Monitoring Web Views
For Android: Instrumenting WebView
Note
Hybrid apps automatically report uncaught JavaScript exceptions as handled exceptions to Apteligent. Hybrid apps also automatically log XMLHttpRequest network requests.
In addition to automatically monitoring the performance of webviews, users can optionally add instrumentation to measure custom Userflows and custom logging in the HTML5 code to help debug errors:
Integrate HTML5 SDK
In order to set up custom logging from the HTML5 SDK, include the Apteligent JavaScript library. This will allow your JavaScript code to call any of the other HTML5 SDK API methods. The JavaScript code layer of a hybrid app does not need to call Crittercism.init()
since initialization is performed by the native code layer of the hybrid app. Once the JavaScript library is included, calls to any of the HTML5 SDK methods will call the native code layer.
<script type="text/javascript" src="https://d1a62freaxhn7x.cloudfront.net/v2/24/crittercismClientLibraryMin.js"></script>
Custom Logging in Hybrid Apps
Add Breadcrumbs in both JavaScript and native code to help debug errors in crashes, handled exceptions, or userflows. All JavaScript exceptions are automatically sent as Handled Exceptions. Breadcrumbs can be logged in both the native SDK as well as the HTML5 SDK. Regardless of where breadcrumbs are logged, they will appear in all crashes, handled exceptions, and userflows.
To add a breadcrumb in the HTML5 SDK: Logging Breadcrumbs
For iOS: Logging Breadcrumbs
For Android: Logging Breadcrumbs
Custom Userflows in Hybrid Apps
A common performance problem in many hybrid apps is UI lag and errors when the app switches between the hybrid UI and the webview. Measure these transitions by adding Userflows. Since the Apteligent HTML5 SDK can communicate directly with the native SDK, you can begin and end Userflows between the two SDKs.
For example, you can begin a Userflow in your native iOS SDK:
Objective-C
[Crittercism beginUserflow:@"Load Checkout Page"];
Swift
Crittercism.beginUserflow("Load Checkout Page")
Then, you can end that same Userflow in your HTML5 SDK:
Crittercism.endTransaction("Load Checkout Page");
This will allow you to measure the UI lag for transitioning between the native layer and the webview as well as monitor any crashes or javascript errors during the transition. For more information on instrumenting Userflows, see the following:
For HTML5: Logging Userflows
For iOS: Logging User Flows
For Android: Logging User Flows