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, List<StorifyMeStory> stories) {
debugPrint("onLoad: $stories");
}
void onFail(String exceptionMessage) {
debugPrint("onFail: $exceptionMessage");
}
void onStoryOpened(StorifyMeStory story, int index) {
debugPrint("onStoryOpened: $story");
}
void onStoryClosed(StorifyMeStory story) {
debugPrint("onStoryClosed: $story");
}
void onAction(String type, String dataJson) {
debugPrint("onAction: $type");
}
void onEvent(String type, String dataJson) {
debugPrint("onAction: $type");
}
void onStoryShared(StorifyMeStory story) {
debugPrint("onStoryShared: $story");
}
void onShopping(String type, String dataJson) {
debugPrint('onShopping, type: $type, data: $dataJson');
}
Future<StorifyMeStoryDeeplinkTriggerCompletion> onStoryDeeplinkTriggered(
StorifyMeStory? story) {
debugPrint('onStoryDeeplinkTriggered: $story');
return Future.value(
StorifyMeStoryDeeplinkTriggerCompletion.openStoryByDefault);
}
onLoad()
onLoad
method is invoked when the widget loads successfully.
void onLoad(int widgetId, StorifyMeStory story) {
debugPrint("onLoad: $story");
}
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(StorifyMeStory story, int index) {
debugPrint("onStoryOpened: $story");
}
onStoryClosed()
onStoryClosed
method is invoked when the user closes the story and the full screen preview.
void onStoryClosed(StorifyMeStory story) {
debugPrint("onStoryClosed: $story");
}
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(StorifyMeStory story) {
debugPrint("onStoryShared: $story");
}
onStoryShopping()
onStoryShopping
method is invoked every time some cart manipulation is happening. Supported types:
Supported types:
- CART_UPDATED - Happens every time cart is changed
- CART_ITEM_ADDED - Happens when a product is added to cart
- CART_ITEM_REMOVED - Happens when a product is removed from the cart
- CHECKOUT - Happens when user clicks on Checkout button in cart
void onShopping(String type, String dataJson) {
debugPrint('onShopping, type: $type, data: $dataJson');
}
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(
StorifyMeStory? story) {
debugPrint('onStoryDeeplinkTriggered: $story');
return Future.value(
StorifyMeStoryDeeplinkTriggerCompletion.openStoryByDefault);
}