On this page:

Related pages:

Your Rating:
Results:
PatheticBadOKGoodOutstanding!
14 rates

By initializing the instrumentation, the Cordova plugin will report the beacons similar to those collected by the JavaScript Agent. If you want to monitor the WebViews more like a native mobile application, such as add breadcrumbs, report crashes, take screenshots, etc., you will need to use the Cordova Plugin API. 

This page shows you how to use the SDK through example code. For the Cordova SDK API reference documentation, see the latest JSDoc documentation or the previous versions listed below:

Using the Cordova Plugin SDK API

Syntax

To call SDK API methods, use the following syntax: window.plugins.ADEUMMobilePlugin.<method>

Arguments

The last two arguments for all of the SDK API methods should always be two functions. The first function should handle successful cases and the last method should handle failures.

For example:

window.plugins.ADEUMMobilePlugin.changeAppKey("<EUM_APP_KEY>",
    (success) => {
        this.showAlert("changeAppKey return: success");
    },
    (error) => {
        this.showAlert("changeAppKey error:" + error);
    }
);

Add Methods to Call SDK APIs

To use the SDK APIs, you are recommended to create class methods that call the SDK APIs as shown below.

export class HomePage {
    ...
    someMethod(event) {
         window.plugins.ADEUMMobilePlugin.<method>(<arg1>, <success_function>, <failure_function>);
    }
    ...
}

Example

Thus, for the HomePage.js file, your HomePage class could have the method takeScreenshot that calls the SDK API method screenshot as shown here.

export class HomePage {
    ...
    takeScreenshot(event) {
      // Call the Cordova plugin SDK methods
      window.plugins.ADEUMMobilePlugin.screenshot(
       (success) => {
        this.showAlert("crash return: success");
       },
      (error) => {
        this.showAlert("crash error:" + error);
      });
    }
    ...
}

Change the App Key

To change the EUM application key, you use the method changeAppKey with the parameters below.

Parameter NameData TypeDescription
appKeystringThe EUM application key.
successfunctionA user-defined function that is called when changeAppKey is successful.
errorfunctionA user-defined function that is called when changeAppKey fails.

For example, you could create a new method that takes a new app key and passed it to the SDK API method changeAppKey.

changeAppKey(event, newAppKey) {
    window.plugins.ADEUMMobilePlugin.changeAppKey(newAppKey,
        (success) => {
            this.showAlert("changeAppKey return: success");
        },
        (error) => {
            this.showAlert("changeAppKey error:" + error);
        }
    );
}

Collect Additional Types of Data

You can use methods available in the ADEUMMobilePlugin class to collect five additional types of data:

Info Points

Information points allow you to track how your own code is running. You can see how often a method is invoked, and how long it takes to run by calling beginCall. When the callbacks success or error are called, the call to track the info point ends.

  • beginCall(name, functionName, args, success, error)

Parameters

The table below describes the parameters for the two methods:

NameTypeDescription
namestringThe name of the file or module where the info point is being recorded.
functionNamestringThe function that is invoking beginCall to track an info point.
successfunctionThe user-defined callback for successful cases.
errorfunctionThe user-defined callback for failed cases.

Example

For example, you can use create info points with something like the code below to determine how a method is invoked, and how long it takes to run:

beginCall(event) {
    window.plugins.ADEUMMobilePlugin.beginCall("home.ts", "callTrackerFunction", "event",
        (tracker) => {
            tracker.reportCallEndedWithReturnValue("Return from home.ts",
                (success) => { console.log("End call with return value success:" + success);},
                (error) => { console.log("End call with return value error:" + error); });
            },
            (error) => {
                console.log("Begin call error:" + error);
        }
    );
}

Custom Timers

You can create custom timers to time any arbitrary sequence of events within your code, even spanning multiple methods. You create the custom timers using the SDK API methods startTimer and stopTimer.

  • startTimerWithName(name, success, error)

  • stopTimerWithName(name, success, error)

 Parameters

The two methods take the following parameters:

NameTypeDescription
namestringThe name of the custom timer. Allowed characters are [A-Za-z\s0-9]. Illegal characters are replaced by their ASCII hex value.
successfunctionThe user-defined callback for successful cases.
errorfunctionThe user-defined callback for failed cases.

Example

For example, to track the time a user spends viewing a screen, the instrumentation could look like this:

startTimer(event) {
    window.plugins.ADEUMMobilePlugin.startTimerWithName(data.name,
        (success) => {
            this.showAlert("startTimerWithName return: success");
        },
        (error) => {
            this.showAlert("startTimerWithName error:" + error);
        }
    );
}
stopTimer(event) {
    window.plugins.ADEUMMobilePlugin.stopTimerWithName(data.name,
        (success) => {
            this.showAlert("stopTimerWithName return: success");
        },
        (error) => {
            this.showAlert("stopTimerWithName error:" + error);
        }
    );
}

Custom Metrics

You can also report custom metrics. 

You create custom metrics with the reportMetricWithName:

  • reportMetricWithName(name, value, success, error) 

Parameters

The reportMetricWithName method take the following parameters:

NameTypeDescription
namestringThe name of the custom metric. The metric names must consist of alphanumeric characters. Illegal characters are replaced by their ASCII hex value.
valuenumberif value is not a whole number an error will be returned.
successfunctionUser-defined success callback.
errorfunctionUser-defined error callback.

Example

For example, the following method could be used to report custom metrics:

reportMetric(event, data) {
    window.plugins.ADEUMMobilePlugin.reportMetricWithName(data.name, parseInt(data.value),
        (success) => {
            this.showAlert("reportMetricWithName : success");
        },
        (error) => {
            this.showAlert("reportMetricWithName error:" + error);
        }
    );
};

 Breadcrumbs

Breadcrumbs allow you to situate a crash in the context of your user's experience. Set a breadcrumb when something interesting happens. If your application crashes at some point in the future, the breadcrumb will be displayed along with the crash report. Each crash report displays the most recent 99 breadcrumbs.

You create and leave breadcrumbs with the following SDK API method:

  • leaveBreadcrumb(breadcrumb, mode, success, error)

Parameters

The method leaveBreadcrumb takes the following parameters:

NameTypeDescription
breadcrumbstringThe string to include in the crash report and sessions. Truncated at 2048 characters; empty values are ignored.
modenumber

The mode determining where the breadcrumb will be displayed:

  • 0 - for crashes only
  • 1 - for crashes and sessions.

The mode defaults to crashes if the value is not parseable.

successfunctionThe user-defined callback for successful cases.
errorfunctionThe user-defined callback for failed cases.

Example

This code example shows how to use the SDK API to leave a breadcrumb:

breadcrumb(mode) {
      window.plugins.ADEUMMobilePlugin.leaveBreadcrumb( "breadcrumb1", mode,
     (success) => {
        this.showAlert("leaveBreadcrumb return: success");
      },
      (error) => {
        this.showAlert("leaveBreadcrumb error:" + error);
    }
)  

Add Custom User Data

You can set and later remove any string key/value pair you think might be useful with the following methods:

  • setUserData(key, value, success, error)

  • removeUserData(key, success, error)

Parameters

The following table describes the parameters:

NameTypeDescription
keystringThe key identifying the key-value pair.
valuestringThe value associated with the key.
successfunctionThe user-defined callback for successful cases.
errorfunctionThe user-defined callback for failed cases.

Example

The code example below shows how to set and remove user data with the SDK API:

setCustomData(event, data) {
    window.plugins.ADEUMMobilePlugin.setUserData(data.name, data.value,
        (success) => {
            this.showAlert("setUserData return: success");
        },
        (error) => {
            this.showAlert("setUserData error:" + error);
        }
    );
};
removeUserData(event, key) {
    window.plugins.ADEUMMobilePlugin.removeUserData(key,
        (success) => {
            this.showAlert("removeUserData return: success");
        },
        (error) => {
            this.showAlert("removeUserData error:" + error);
        }
    );
}

Configure and Take Screenshots

Mobile screenshots are enabled by default. These screenshots will show up in the Sessions Details dialog.

You can configure the Controller UI to automatically take screenshots or use the Cordova plugin to manually take a screenshot as shown below:

screenshot(event) {
     // make a call to plugin
     console.log("screenshot click handler");
      window.plugins.ADEUMMobilePlugin.takeScreenshot(

     (success) => {
        this.showAlert("screenshot return: success");
      },
      (error) => {
        this.showAlert("screenshot error:" + error);
      });
}

This will capture everything, including personal information, so you must be cautious of when to take the screenshot. 


Enable Logging and Set Logging Level

You use the method loggingLevel to enable and set the logging level. You can set logging to one of the following levels:

ValueLogging LevelDescription
0NoneNo logs are displayed. This level disables logging.
1ErrorOnly error messages are displayed. This is the default logging level.
2WarnWarning and error messages are displayed.
3InfoWarning, errors, and developer-focused messages are displayed.
4DebugErrors, warnings, developer information, and debugging messages are displayed.
5VerboseErrors, warnings, developer information, debugging, and troubleshooting messages are displayed.
6AllAll the supported log messages are displayed.

You enable logging by setting the logging level in the instrumentation configuration. For example, in this example, you are enabling logging and setting the logging level to Info:

window.plugins.ADEUMMobilePlugin.initWithConfiguration(
    {
        "appKey": "<EUM_APP_KEY>",
        "loggingLevel": 3
     },
     (success) => {
        this.showAlert("initWithConfiguration return: success");
     },
     (error) => {
        this.showAlert("initWithConfiguration error:" + error);
     }
);
  • No labels