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 protocol and implement the following method:

#import <Hansel/Hansel-umbrella.h>

- (void) onActionPerformed: (NSString*) action {
  //This method will be called everytime an action has been performed.
  //action - Name of the action that has been performed.
}
func 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. Product Experience SDK only maintains a weak reference to the listener to avoid memory leaks.

#import <Hansel/Hansel-umbrella.h>

//For example if the class name implementing HanselActionListener protocol is 'HanselActionsHandler'.
//Create an instance of the class
HanselActionsHandler* hanselActionsHandler = [[HanselActionsHandler alloc] init];
  
  
//Register the instance with this line:
[Hansel registerHanselActionListener:@"action name" andListener:hanselActionsHandler];
//For example if the class name implementing HanselActionListener protocol is 'HanselActionsHandler'.
//Create an instance of the class
let hanselActionsHandler = HanselActionsHandler()
  
  
//Register the instance with this line:
Hansel.registerHanselActionListener(action: "action name", listener: hanselActionsHandler)

Step 3: Register listener for actions from Test Device:

Ensure that you register the listeners for actions that 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 devices, please click here.

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

Updated 6 months 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.