Invocation

This section covers how to change the event done by the user to invoke the SDK, as well as the default feature to be used once the SDK is invoked.

By default, Instabug is invoked when the device is shaken. This can be customized to several other out-of-the-box modes to show the SDK. You can also show the SDK manually from a custom gesture or a button you add to your app.

Invocation Events

You can set the SDK to be shown using one of the following modes:

  • Shake device
  • Take a screenshot
  • Tap on a floating button shown above your app's UI
  • Do a 2-finger swipe from right to left

To customize the invocation event, pass one of the values of the Instabug.invocationEvent enum when starting the SDK.

//iOS
//You can specify the invocation event while initializing the SDK
cordova.plugins.instabug.activate(
    {
        ios: 'MY_IOS_TOKEN'
    },
    cordova.plugins.bugReporting.invocationEvents.button,
    function () {
        console.log('Instabug initialized.');
    },
    function (error) {
        console.log('Instabug could not be initialized - ' + error);
    }
);

//You can change the invocation event later on at run time
//First argument is an array of events
cordova.plugins.bugreporting.setInvocationEvents(
           [cordova.plugins.bugReporting.invocationEvents.shake, cordova.plugins.bugReporting.invocationEvents.button],
           function () {
               console.log(‘Instabug invocation events set!);
           },
           function (error) {
               console.log(‘Instabug invocation events could not be set -  + error);
           }
       );
//Android 
//Change the invocation event in the builder method generated in MyApplication class
new Instabug.Builder(this, "APP_TOKEN")
	.setInvocationEvent(InstabugInvocationEvent.SHAKE)
	.build();

Here are the possible invocation events. You can find the possible invocation events below. The None event can be used in case you want to prevent the SDK from being invoked by the normal way and invoke it later on manually whenever you need or under certain conditions. In case you are using the floating button, you can set its default position as explained here.

cordova.plugins.bugReporting.invocationEvents.shake
cordova.plugins.bugReporting.invocationEvents.button
cordova.plugins.bugReporting.invocationEvents.screenshot
cordova.plugins.bugReporting.invocationEvents.swipe
cordova.plugins.bugReporting.invocationEvents.none

Shaking Threshold

If you are using the shaking gesture as your invocation event you can set how sensitive your device is to the shaking. The higher the value the less sensitive the device will be to shaking.

//Can be changed through the activate method
cordova.plugins.instabug.activate(
    {
        ios: 'MY_IOS_TOKEN'
    },
    cordova.plugins.bugReporting.invocationEvents.shake,
    {
       shakingThresholdAndroid:12, //Default value: 11
       shakingThresholdIPhone: 2,  //Default value: 2.5
       shakingThresholdIPad: 0.5   //Default value: 0.6
    },
    function () {
        console.log('Instabug initialized.');
    },
    function (error) {
        console.log('Instabug could not be initialized - ' + error);
    }
);

Manual Invocation

You can also invoke the event manually as follows.

//The first parameter represents the invocation mode
//The second parameter represents the invocation option
cordova.plugins.bugReporting.invoke(
            cordova.plugins.bugReporting.invocationModes.feedback, // this is optional
            [cordova.plugins.bugReporting.invocationOptions.emailFieldHidden,
             cordova.plugins.bugReporting.invocationOptions.commentFieldRequired], // this is optional
            function () {
                console.log('Invoke method successful');
            },
            function (error) {
                console.log('Invoke method not successful  ' + error);
            }
        )

Normally when the SDK is invoked the users are shown a window from which they can select what exactly they want to do.

Alternatively, you could show the SDK with a specific feature.

//You can specify the invocation event while initializing the SDK
cordova.plugins.instabug.activate(
    {
        ios: 'MY_IOS_TOKEN'
    },
    cordova.plugins.bugReporting.invocationEvents.button,
    {
      defaultInvocationMode: 'bug'
    },
    function () {
        console.log('Instabug initialized.');
    },
    function (error) {
        console.log('Instabug could not be initialized - ' + error);
    }
);

//The first parameter represents the invocation mode
//The second parameter represents the invocation options
cordova.plugins.bugReporting.invoke(
            cordova.plugins.bugReporting.invocationModes.chat, // this is optional
            [cordova.plugins.bugReporting.invocationOptions.emailFieldHidden,
             cordova.plugins.bugReporting.invocationOptions.commentFieldRequired], // this is optional
            function () {
                console.log('Invoke method successful');
            },
            function (error) {
                console.log('Invoke method not successful  ' + error);
            }
        )

Here are the possible modes.

cordova.plugins.bugReporting.invocationModes.chat
cordova.plugins.bugReporting.invocationModes.chats
cordova.plugins.bugReporting.invocationModes.bug
cordova.plugins.bugReporting.invocationModes.feedback
cordova.plugins.bugReporting.invocationModes.options

The following are the possible invocation options.

cordova.plugins.bugReporting.invocationOptions.emailFieldHidden
cordova.plugins.bugReporting.invocationOptions.emailFieldOptional
cordova.plugins.bugReporting.invocationOptions.commentFieldRequired
cordova.plugins.bugReporting.invocationOptions.disablePostSendingDialog