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 running:
StorifyMe.instance.eventListener = object : StorifyMeEventListener() {
override fun onLoad(stories: List<StoryWithSeen>) {
Log.d(TAG, "onLoad() ${stories.joinToString()}")
}
override fun onFail(error: StorifyMeError) {
Log.d(TAG, "onFail() ${error.message}")
}
override fun onStoryOpened(story: StoryWithSeen, index: Int) {
Log.d(TAG, "onStoryOpened() $story : index: $index")
}
override fun onStoryClosed(story: StoryWithSeen) {
Log.d(TAG, "onStoryClosed() $story")
}
override fun onAction(type: String, slide: Any, action: String) {
Log.d(TAG, "onAction() - type: $type - slide: $slide - action: $action")
}
override fun onEvent(event: String, data: Map<String, Any>) {
Log.d(TAG, "onEvent() - event: $event - data: $data")
}
override fun onStoryShared(story: StoryWithSeen) {
Log.d(TAG, "onStoryShared() $story")
}
override fun onStoryDeeplinkTriggered(
story: StoryWithSeen,
completion: (StorifyMeStoryDeeplinkTriggerCompletion) -> Unit
) {
if (checkSomeCondition) {
// Don't launch story viewer
completion(StorifyMeStoryDeeplinkTriggerCompletion.IGNORE_PRESENTING_STORY)
} else {
// Continue with default behaviour
completion(StorifyMeStoryDeeplinkTriggerCompletion.OPEN_STORY_BY_DEFAULT)
}
}
}
onLoad()
onLoad
method is invoked when the widget loads successfully.
StorifyMe.instance.eventListener = object : StorifyMeEventListener() {
override fun onLoad(stories: List<StoryWithSeen>) {
Log.d(TAG, "onLoad() ${stories.joinToString()}")
}
}
onFail()
onFail
method is invoked when the widget loading fails. Use this even to for example hide the widget, or re-try loading.
StorifyMe.instance.eventListener = object : StorifyMeEventListener() {
override fun onFail(error: StorifyMeError) {
Log.d(TAG, "onFail() ${error.message}")
}
}
onStoryOpened()
onStoryOpened
method is invoked any time a user opens a story.
StorifyMe.instance.eventListener = object : StorifyMeEventListener() {
override fun onStoryOpened(story: StoryWithSeen, index: Int) {
Log.d(TAG, "onStoryOpened() $story : index: $index")
}
}
onStoryClosed()
onStoryClosed
method is invoked when the user closes the story and the full screen preview.
StorifyMe.instance.eventListener = object : StorifyMeEventListener() {
override fun onStoryClosed(story: StoryWithSeen) {
Log.d(TAG, "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.
StorifyMe.instance.eventListener = object : StorifyMeEventListener() {
override fun onAction(type: String, slide: Any, action: String) {
Log.d(TAG, "onAction() - type: $type - slide: $slide - action: $action")
}
}
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.
StorifyMe.instance.eventListener = object : StorifyMeEventListener() {
override fun onEvent(event: String, data: Map<String, Any>) {
Log.d(TAG, "onEvent() - event: $event - data: $data")
}
}
onStoryShared()
onStoryShared
method is invoked when the user shares the story.
StorifyMe.instance.eventListener = object : StorifyMeEventListener() {
override fun onStoryShared(story: StoryWithSeen) {
Log.d(TAG, "onStoryShared() $story")
}
}
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.
StorifyMe.instance.eventListener = object : StorifyMeEventListener() {
override fun onStoryDeeplinkTriggered(
story: StoryWithSeen,
completion: (StorifyMeStoryDeeplinkTriggerCompletion) -> Unit
) {
if (checkSomeCondition) {
// Don't launch story viewer
completion(StorifyMeStoryDeeplinkTriggerCompletion.IGNORE_PRESENTING_STORY)
} else {
// Continue with default behavior
completion(StorifyMeStoryDeeplinkTriggerCompletion.OPEN_STORY_BY_DEFAULT)
}
}
}