Home

Awesome

cordova-plugin-bugfender

⚠️ NOTE: If you're starting a new project we recomend you to use Capacitor with it's corresponding Bugfender SDK.

This plugin adds Bugfender support for Cordova applications under iOS and Android. Also works on Cordova-based projects such as Phonegap and Ionic.

Requirements

You will need Cordova 9, Ionic 4 or a newer.

For iOS, you will need macOS and CocoaPods installed on your system. iOS deployment target version is required to be 10.0 at least.

You can set the minimum version by adding this preference to the <platform name="ios"> tag in your config.xml:

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

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

pod repo update

Installing in Cordova

In the command line, run (replace XXX with your app key):

cordova plugin add cordova-plugin-bugfender --variable BUGFENDER_APP_KEY=XXX --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;

Then use Bugfender.log() to log anything you want. Syntax is the same as console.log().

For a basic use of Bugfender, that's all you need to do. Read on to learn more advanced options.

Installing in Ionic

In the command line, run (replace XXX with your app key):

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

Wherever you want to use Bugfender, import it:

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

Then use Bugfender.log() to log anything you want. Syntax is the same as console.log().

For a basic use of Bugfender, that's all you need to do. Read on to learn more advanced options.

Configuration variables

Application key

The BUGFENDER_APP_KEY variable idicates the Bugfender application to log to. You can get one at bugfender.com.

Automated logger configuration (optional)

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

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.

Reference

Manual logging

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:

Device associated data

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

For example:

// when user logs in
Bugfender.setDeviceKey('email', 'test@example.com');
...
// when user logs out
Bugfender.removeDeviceKey('email');

Send logs programatically

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

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.

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.

For example:

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