Smartech

Defining Actions

Please follow the below steps if you want to receive a callback whenever an action has been invoked from a Nudge. This guide will help you implement listeners and register them with Product Experience SDK.

Product Experience SDK will invoke the method in the registered listener whenever an action has been triggered. You can add additional logic in this method to perform any relevant tasks related to the action.

Step 1: Create a class implementing HanselActionListener interface and implement the following method:

package io.hansel.hanselsdk;

void onActionPerformed(String action){
  //This method will be called everytime an action has been performed.
  //action - Name of the action that has been performed.
}
fun onActionPerformed(action: String) {
  //This method will be called everytime an action has been performed.
  //action - Name of the action that has been performed.
}

Step 2: Register the HanselActionListener with the Product Experience SDK using the following code:

Every listener should be associated with a specific action. This gives you the flexibility to add different listeners for different actions. If you wish to add the same listener for all the actions, then register the same listener for all the actions separately.

//Create an instance of HanselActionListener
 HanselActionListener hanselActionListener = new HanselActionListener() {
            @Override
            public void onActionPerformed(String action) {
                            //Perform task based on action
            }
};

//Register the instance with this line:
Hansel.registerHanselActionListener("action Name", hanselActionsListener);
//Create an instance of HanselActionListener
val hanselActionListener = new HanselActionListener() {
            @Override
            public void onActionPerformed(String action) {
                            //Perform task based on action
            }
};

//Register the instance with this line:
Hansel.registerHanselActionListener("action Name", hanselActionsListener)

Step 3: Register listener for actions from Test Device:

Ensure that you register the listeners for actions which you added in Steps 1 and 2, from a test device. This can be done by invoking all the flows within the app, where the action listeners have been registered. To learn more on setting up test device, please click here.

Once you have done the above changes, registered actions will be populated on the Hansel panel.

Updated about a month ago


Defining Actions


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.