Defining Actions

Please follow the below steps if you want to fire 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 function that you would like to use as a callback:

function actionHandler(userData, eventData) {
  // this method will be called whenever an Action is invoked
}

Using user input from Display Nudges:

You can use the userData object to consume values that the user has entered in case of nudges with user input (NPS, Rating, User Feedback and MCQ). userData object contains the following values based on the type of input nudge.

Net Promoter Score : {"nps_value": ""}

Rating and Review: {"rating_value": ""}

User Feedback: {"input_text1": ""}

Multi Choice Questionnaire: {"multichoice_value": ""}

🚧

Other Nudges - userData

In case of other display nudges, userData object would be an empty one.

Using event property data from Display Nudges:

Hansel also lets you access all the event properties that were fired along with the trigger event for this display nudge. Use the eventData object for the same.

eventData object consists of key value pairs in the following format:

  • <property 1>: < value >,
  • <property 2>: < value >,
    and so on.

For eg, if your event "add_to_cart" triggered a display nudge, the following properties would be available if they were fired with the event:
{ itemname:"macbook", itemprice": 800, "currency": "USD", quantity" 3... etc}

Step 2: Register your callback function with the Product Experience SDK using the following code:

Every callback is associated with a specific action.

Hansel.registerAction('<action>', actionHandler);

Step 3: Register callbacks for actions from Test Device:

Ensure that you register the callbacks for actions that you added in Steps 1 and 2, from a test device. This can be done by invoking all the flows within a test app, where the action callbacks 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.


Did this page help you?