Callbacks
To listen to events triggered by the Nudge SDK, you need to implement the NudgeCallbackListener
interface.
1. Implement Nudge Callback
Implement the NudgeCallbackListener
in your screen:
class _HomePageState extends State<HomePage>
with SingleTickerProviderStateMixin implements NudgeCallbackListener {
...
}
2. Register the Callback
Register the listener in the initState
method:
@Override
void initState() {
super.initState();
NudgeCallbackManager.registerListener(this);
}
3. Listening to Events
Now, you can listen and respond to events:
@override
void onEvent(NudgeCallbackData event) {
print("callback event: ${event}");
switch (event.type) {
case "CORE":
break;
case "UI":
break;
default:
break;
}
}
NudgeCallbackData Schema
The NudgeCallbackData
structure consists of the following fields:
Field | Type | Description |
---|---|---|
data | Map<String, dynamic> | A payload containing event-specific data. |
type | String | The type of event triggered. |
action | String | The specific action associated with the event. |
method | String | The method or source that triggered the event. |
type | action | data |
---|---|---|
CORE | NUDGE_INITIALISED | { sdk_version: string } |
NUDGE_USER_IDENTIFIER_SUCCESS | { user_details: { name: string, email: string, phone_number: string, external_id: string } } | |
NUDGE_USER_IDENTIFIER_FAILURE | { user_details: { name: string, email: string, phone_number: string, external_id: string }, error: string, message: string } | |
NUDGE_TRACK_EVENT | { event: string, response: object } | |
NUDGE_REWARD_RECEIVED | { rewards: object[] } | |
UI | NUDGE_EXPERIENCE_OPEN | {CAMPAIGN_ID : string, CAMPAIGN_NAME : string, DISPLAY_NAME: string, DISPLAY_TYPE : string, DISPLAY_ID: string} |
NUDGE_EXPERIENCE_DISMISS | {CAMPAIGN_ID : string, CAMPAIGN_NAME : string, DISPLAY_NAME: string, DISPLAY_TYPE : string, DISPLAY_ID: string}} | |
NUDGE_EXPERIENCE_HIDDEN | { ... } | |
NUDGE_COMPONENT_CTA_CLICK | {TARGET: string, CAMPAIGN_ID: string, CAMPAIGN_NAME: string, WIDGET_NAME: string, WIDGET_ID: string, DISPLAY_NAME: string, CLICK_TYPE: string, DISPLAY_ID: string} ` |
This schema provides a structured format for handling event-driven interactions within your Flutter application using the Nudge SDK.