Events
You can attach and subscribe to events in order to run logic in your app when something happens in Stories. This way, you can:
- control what is shown,
- override events from StorifyMe stories,
- intercept click events and run internal logic,
- and many other use cases
Example code
The best way to attach listeners is by overriding native StorifyMe events:
void onLoad(int widgetId, String storiesJson) {
debugPrint("onLoad: $storiesJson");
}
void onFail(String exceptionMessage) {
debugPrint("onFail: $exceptionMessage");
}
void onStoryOpened(String storyJson, int index) {
debugPrint("onStoryOpened: $storyJson");
}
void onStoryClosed(String storyJson) {
debugPrint("onStoryClosed: $storyJson");
}
void onAction(String type, String dataJson) {
debugPrint("onAction: $type");
}
void onEvent(String type, String dataJson) {
debugPrint("onAction: $type");
}
void onStoryShared(String storyJson) {
debugPrint("onStoryShared: $storyJson");
}
Future<StorifyMeStoryDeeplinkTriggerCompletion> onStoryDeeplinkTriggered(
String? storyJson) {
debugPrint('onStoryDeeplinkTriggered: $storyJson');
return Future.value(
StorifyMeStoryDeeplinkTriggerCompletion.openStoryByDefault);
}
onLoad()
onLoad
method is invoked when the widget loads successfully.
void onLoad(int widgetId, String storiesJson) {
debugPrint("onLoad: $storiesJson");
}
onFail()
onFail
method is invoked when the widget loading fails. Use this even to for example hide the widget, or re-try loading.
void onFail(String exceptionMessage) {
debugPrint("onFail: $exceptionMessage");
}
onStoryOpened()
onStoryOpened
method is invoked any time a user opens a story.
void onStoryOpened(String storyJson, int index) {
debugPrint("onStoryOpened: $storyJson");
}
onStoryClosed()
onStoryClosed
method is invoked when the user closes the story and the full screen preview.
void onStoryClosed(String storyJson) {
debugPrint("onStoryClosed: $storyJson");
}
onAction()
onAction
method is invoked when the user engages with one of the engaging components. This way you can override for example a button click event and instead of opening the product details page on the website, you can open it in the app itself.
Or when they answer on the quiz question, based on the answer, you might want to send them to some specific page.
void onAction(String type, String dataJson) {
debugPrint("onAction: $type");
}
onEvent()
onEvent
method is invoked every time some analytics even is happening. It can be a slide view event, engaging element answer or similar.
While this method can be used to collect analytics on your side, we suggest adding the additional analytics processors in StorifyMe admin app under integrations.
void onEvent(String type, String dataJson) {
debugPrint("onAction: $type");
}
onStoryShared()
onStoryShared
method is invoked when the user shares the story.
void onStoryShared(String storyJson) {
debugPrint("onStoryShared: $storyJson");
}
onStoryDeeplinkTriggered()
The onStoryDeeplinkTriggered
method is designed to handle deep links triggered from a Story within the StorifyMe widget. This function provides developers with the ability to customize the behavior when a Story deep link is activated.
Future<StorifyMeStoryDeeplinkTriggerCompletion> onStoryDeeplinkTriggered(
String? storyJson) {
debugPrint('onStoryDeeplinkTriggered: $storyJson');
return Future.value(
StorifyMeStoryDeeplinkTriggerCompletion.openStoryByDefault);
}