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 PxActionListener
interface and implement the following method:
class _PxActionListenerImpl extends PxActionListener {
@override
void onActionPerformed(String action) {
debugPrint('PXAction: $action');
}
}
Step 2: Register the PxActionListener
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.
NetcorePX.instance.registerPxActionListener(action,_PxActionListenerImpl());
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 main.dart class with the Product Experience SDK using the following code:
class _PxDeeplinkListenerImpl extends PxDeeplinkListener {
@override
void onLaunchUrl(String url) {
debugPrint('PXDeeplink: $url');
}
}
NetcorePX.instance.registerPxDeeplinkListener(_PxDeeplinkListenerImpl());
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.
Updated 3 months ago