A StorytellerDelegate
has methods for managing Storyteller
Story events. It is used as global object for handling all events when opening a story player with and without the StorytellerRowView
or StorytellerGridView
. Please see the dedicated StorytellerListViewDelegate for handling events related to rows and grids.
You can implement these optional methods when responding to the StorytellerDelegate
protocol:
The onUserActivityOccurred(type: Activity.EventType, data: UserActivityData)
method is called when an analytics event is triggered. See the dedicated Analytics page for more information on analytic events.
The getAdsForList(stories: [ClientStory], onComplete: @escaping ([ClientAd]) -> Void, onError: @escaping (Error) -> Void)
method is called when the tenant is configured to request ads from the containing app and the S(DK requires ad data from the containing app. For more information on how to supply ads to the Storyteller SDK, see the dedicated Ads page.
The userNavigatedToApp(url: String)
method is called when a user presses action button on a Page which should direct the user to a specific place within the integrating app. For more information on deeplinking, see the dedicated Deeplinking page.
class DelegateObject : StorytellerDelegate {
func onUserActivityOccurred(type: Activity.EventType, data: UserActivityData) {
// Actions to handle analytics data
}
func getAdsForList(stories: [ClientStory?], onComplete: @escaping ([ClientAd]) -> Void, onError: @escaping (Error) -> Void) {
// Request ads from your ads provider then pass them to the SDK via the `onComplete` callback
}
func userNavigatedToApp(url: String) {
// The user navigated to app by pressing action button on a page which should redirect to a location within the integrating app. The url describes where in the integrating app the user should be directed
}
}
DelegateObject should be assigned to Storyteller's shared instance delegate.
let delegate = DelegateObject()
Storyteller.sharedInstance.delegate = delegate
The callback onUserActivityOccurred
provides analytics events and corresponding data triggered internally by the SDK. This information can be used in your app.
The following parameters are passed to the callback method:
type
- type of event that occurred, as a UserActivity.EventType
enumdata
- an object containing data about the event which occurredExample:
...
func onUserActivityOccurred(type: UserActivity.EventType, data: UserActivityData) {
if type == .OpenedStory {
// Retrieve the story id value
let openedStoryId = data.storyId
// Retrieve the story title value
let openedStoryTitle = data.storyTitle
// Report retrieved values from your app
}
}
For a detailed discussion of all the relevant events and properties please see the dedicated Analytics page.
By implementing getAdsForList
, you can provide custom ad data for the SDK to render. This is only applicable when the ad configuration is set to Integrating App
in the CMS. Ad data can be obtained asynchronously, and should be provided using the onComplete
closure parameter.
Example:
...
func getAdsForList(stories: [ClientStory], onComplete: @escaping ([ClientAd]) -> Void, onError: @escaping (Error) -> Void) {
// Action to get some ads
let ads = getMyAds()
// Provide the ads to the SDK
onComplete(ads)
}
For a detailed discussion of all the relevant considerations, please see the dedicated Ads page.
The callback userNavigatedToApp
is called when a user swipes up on a Page which has its link type set to In App
. In this case, your app will be passed a swipe up URL which has been entered in the Storyteller CMS and your app is then responsible for parsing this URL and following it to the correct location within your app.
Example:
func userNavigatedToApp(url: String) {
// parse the url and navigate to the destination
}