Skip to main content

Cordova/Phonegap

info

The Cordova Plugin can be found at Github Bugfender Cordova

Bugfender is a game-changing platform that logs every detail your users experience and feeds the data directly to an easy-to-use web console. Bugfender SDK is multi-platform and available for mobile and web apps, so you can use the same tool for all your apps.

Specifically for Cordova/Phonegap developers, Bugfender offers powerful capabilities to remotely monitor and debug any log or error. You can easily reproduce and fix issues using our detailed log viewer and the stack trace of exceptions.

If you don't have a Bugfender account yet, go to Bugfender Signup and come back here.

Requirments

Bugfender has a Cordova plugin that you can install to use our service for iOS and Android development using Cordova or Phonegap.

Bugfender requires Cordova 9, Ionic 4 or newer.

iOS

Requirements for iOS:

  • Mac computer
  • CocoaPods
  • iOS deployment target version is required to be 10.0 at least.

Edit your config.xml file, look for the iOS platform and add the following preference below:

<platform name="ios">
<preference name="deployment-target" value="10.0" />
...
</platform>

You will also need to update your Cocoapods specs, otherwise the installation might fail:

pod repo update

Android

Requirements for Android:

  • Android Studio
  • Cordova 9 or better

Install the Bugfender Plugin

Installing it for Cordova/Phonegap

In your console, type the following command:

cordova plugin add cordova-plugin-bugfender --variable BUGFENDER_APP_KEY=YOUR_APP_KEY ----variable BUGFENDER_AUTOMATIC=UI,CRASH --save

If using TypeScript: you also need to declare the Bugfender global variable in the files where you need it:

declare var Bugfender: any;
note

Remember to change YOUR_APP_KEY with the app key of your app. You can get an app key by signing up to Bugfender. For all the available options see our reference.

Installing in Ionic

In your console, type the following command:

ionic cordova plugin add cordova-plugin-bugfender --variable BUGFENDER_APP_KEY=YOUR_APP_KEY --save

Wherever you want to use Bugfender, import it:

import { Bugfender } from 'cordova-plugin-bugfender/www/bugfender';

Configuration variables

Automated logger configuration (optional)

The BUGFENDER_AUTOMATIC variable is a comma separated set of the following values:

  • NONE: no logging is done automatically. Only logs you manually send via the log, fatal, error, warn, info, debug and trace methods are sent to the server.
  • UI: user interaction and screen changes are logged automatically. Please note only interactions with native elements will be logged.
  • CRASH: crashes are logged automatically.
  • LOG: (Android only) anything logged to Logcat is fetched and sent automatically. This might include log messages generated by the system or libraries in your project.
  • ALL: all automated loggers are enabled. As of today, this is equivalent to UI,LOG,CRASH, but more loggers could be included in the future. This enables all of them.

You can specify this variable when installing the plugin as a --variable, for example cordova plugin add cordova-plugin-bugfender --variable BUGFENDER_APP_KEY=XXX --variable BUGFENDER_AUTOMATIC=NONE --save.

Base URLs (optional)

If you have your own Bugfender instance, you will need to set BUGFENDER_API_URL and BUGFENDER_BASE_URL according to the provided instructions.

Hide device name

The BUGFENDER_HIDE_DEVICE_NAME enables hiding the device name if you do not want to collect it automatically. Set it to any value, for example --variable BUGFENDER_HIDE_DEVICE_NAME=YES.

Usage

Send Logs

You can use Bugfender in a similar way you would use the console object.

You can log strings, numbers or booleans:

Bugfender.log('Hello! This is three:', 3, 'And this is true:', true);

You can log objects, they will be converted to a JSON string:

Bugfender.log('Current score:', {user: 'John', points: 100});

You can specify a format argument as first parameter:

Bugfender.log("%s has %d points", "Sam", 100);

Format arguments available are as follows:

Substitution stringDescription
%o or %OOutputs a JavaScript object which will be serialized as JSON
%d or %iOutputs an integer. Number formatting is supported, for example console.log("Foo %.2d", 1.1) will output the number as two significant figures with a leading 0: Foo 01
%sOutputs a string.
%fOutputs a floating-point value. Formatting is supported, for example console.log("Foo %.2f", 1.1) will output the number to 2 decimal places: Foo 1.10

The following logging levels are available:

  • fatal([fmt,] message,...)
  • error([fmt,] message,...)
  • warn([fmt,] message,...)
  • info([fmt,] message,...)
  • debug([fmt,] message,...)
  • trace([fmt,] message,...)
  • log([fmt,] message,...) (equivalent to debug)

Device associated data

Using these functions you can associate key-value pairs to a device, like a dictionary.

  • setDeviceKey(key, value): sets a key-value pair. You can set strings, numbers or booleans
  • removeDeviceKey(key): removes a key-value pair

For example:

// when user logs in
Bugfender.setDeviceKey('email', '[email protected]');
...
// when user logs out
Bugfender.removeDeviceKey('email');

Send Issues

Bugfender allows you to send issues to the server. An issue is similar to an exception but they are showed in the issues section and you can send issues any time from the app, even if the device is not enabled in the system. Issues are useful to keep track of important errors that you can detect in your code.

For sending an issue you can use the following function:

Bugfender.sendIssue('Issue title', 'Description of the issue');

Advanced Usage

Send logs programatically

You can override the Bugfender website settings with the following functions.

  • forceSendOnce: Synchronizes all logs with the server once, regardless if this device is enabled or not. This method is useful when an error condition is detected and the logs should be sent to the server for analysis, regardless if the device is enabled in the Bugfender Console. Logs are synchronized only once. After that, the logs are again sent according to the enabled flag in the Bugfender Console. This command can be called anytime, and will take effect the next time the device is online.
  • setForceEnabled(enabled): Synchronizes all logs with the server all the time, regardless if this device is enabled or not. This method is useful when the logs should be sent to the server regardless if the device is enabled in the Bugfender Console. Logs are synchronized continuously while setForceEnabled is true. This command can be called anytime, and will take effect the next time the device is online.

Device identifier

When using Bugfender for the first time, a device identifier is generated. The device identifier is unique to the device and installation. It is not related to the device in any way (UDID, MAC address, Android ID, ...). Uninstalling and installing the application again will generate a new device identifier.

  • getDeviceIdentifier(callback): Gets the Bugfender internal device identifier. The result is provided in a callback function, the only argument being a string.

For example:

Bugfender.getDeviceIdentifier(function(deviceId){
alert("Bugfender device id: " + deviceId);
});

Disk usage

Bugfender caches logs in the mobile device internal memory temporarily if there is no Internet connection to send logs. There is the possibility to limit the amount of disk space that this cache can take. If the cache becomes full, the oldest logs will be discarded.

  • setMaximumLocalStorageSize(size): Set the maximum space available to store local logs. This value is represented in bytes. There’s a limit of 50 MB. By default it's configured to 5 MB.

For example:

// set cache size limit to 10 MB
Bugfender.setMaximumLocalStorageSize(10*1024*1024);