Nudges - Defining Actions & Handling Deeplinks

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.

Defining Actions

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 hanselActionsListener = object :HanselActionListener {
            override fun onActionPerformed(action: String?) {
                //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.

Handling Deeplink from Launch URL option

Please follow the below steps if you want to receive a callback for Button Action Launch Url whenever a button is clicked. This guide will help you register and implement a listener with the Product Experience SDK.

Register the HanselDeepLinkListener in your Application class with the Product Experience SDK using the following code:

Hansel.registerHanselDeeplinkListener(new HanselDeepLinkListener() {
            @Override
            public void onLaunchUrl(String url) {
       		// Perform task based on url 


            }
        });
//Create an instance of HanselActionListener
        val hanselActionsListener = object :HanselDeepLinkListener {
            override fun onLaunchUrl(url: String?) {
                //Perform task based on url
            }
        }
        //Register the instance with this line:
        Hansel.registerHanselDeeplinkListener(hanselActionsListener)

For example, in the below screenshot, the URL parameter will have the value http://www.google.com
Note: Registering DeepLinkListener for the "Launch Url" option, will override the default behavior of launch URL option for all nudges.

392