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.getInstance().setEventListener(new StorifyMeEventListener() {
@Override
public void onLoad(List<StoryWithSeen> stories) {
HiLog.info(TAG, "onLoad() " + stories.toString());
}
@Override
public void onFail(StorifyMeError error) {
HiLog.info(TAG, "onFail() " + error.getMessage());
}
@Override
public void onStoryOpened(StoryWithSeen story, int index) {
HiLog.info(TAG, "onStoryOpened() " + story.toString() + " : index: " + index);
}
@Override
public void onStoryClosed(StoryWithSeen story) {
HiLog.info(TAG, "onStoryClosed() " + story.toString());
}
@Override
public void onAction(String type, Object slide, String action) {
HiLog.info(TAG, "onAction() - type: " + type + " - slide: " + slide.toString() + " - action: " + action);
}
@Override
public void onEvent(String event, Map<String, Object> data) {
HiLog.info(TAG, "onEvent() - event: " + event + " - data: " + data.toString());
}
});
onLoad()
onLoad
method is invoked when the widget loads successfully.
StorifyMe.getInstance().setEventListener(new StorifyMeEventListener() {
@Override
public void onLoad(List<StoryWithSeen> stories) {
HiLog.info(TAG, "onLoad() " + stories.toString());
}
});
onFail()
onFail
method is invoked when the widget loading fails. Use this event to for example hide the widget, or re-try loading.
StorifyMe.getInstance().setEventListener(new StorifyMeEventListener() {
@Override
public void onFail(StorifyMeError error) {
HiLog.info(TAG, "onFail() " + error.getMessage());
}
});
onStoryOpened()
onStoryOpened
method is invoked any time a user opens a story.
StorifyMe.getInstance().setEventListener(new StorifyMeEventListener() {
@Override
public void onStoryOpened(StoryWithSeen story, int index) {
HiLog.info(TAG, "onStoryOpened() " + story.toString() + " : index: " + index);
}
});
onStoryClosed()
onStoryClosed
method is invoked when the user closes the story and the full screen preview.
StorifyMe.getInstance().setEventListener(new StorifyMeEventListener() {
@Override
public void onStoryClosed(StoryWithSeen story) {
HiLog.info(TAG, "onStoryClosed() " + story.toString());
}
});
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.getInstance().setEventListener(new StorifyMeEventListener() {
@Override
public void onAction(String type, Object slide, String action) {
HiLog.info(TAG, "onAction() - type: " + type + " - slide: " + slide.toString() + " - action: " + action);
}
});
onEvent()
onEvent
method is invoked every time some analytics event 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.getInstance().setEventListener(new StorifyMeEventListener() {
@Override
public void onEvent(String event, Map<String, Object> data) {
HiLog.info(TAG, "onEvent() - event: " + event + " - data: " + data.toString());
}
});
onStoryShared()
onStoryShared
method is invoked when the user shares the story.
StorifyMe.getInstance().setEventListener(new StorifyMeEventListener() {
@Override
public void onStoryShared(StoryWithSeen story) {
HiLog.info(TAG, "onStoryShared() " + story.toString());
}
});