StorytellerDelegate

A StorytellerDelegate has methods for managing Storyteller story events.

How To Use

You can implement these optional methods when responding to the StorytellerDelegate protocol:

  • onUserActivityOccurred(type: Activity.EventType, data: UserActivityData) - Called when an analytics event is triggered
  • getAdsForList(stories: [ClientStory], onComplete: @escaping ([ClientAd]) -> Void, onError: @escaping (Error) -> Void) - Called when the tenant is configured to request ads from the containing app and the SDK requires ad data from the containing app
  • configureSwipeUpWebView(configuration: inout WKWebViewConfiguration) - provides configuration for WebView presented on swipe up
  • userSwipedUpToApp(swipeUpUrl: String) - Called when a user swipes up on a page which should direct the user to a specific place within the integrating app
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 configureSwipeUpWebView(configuration: inout WKWebViewConfiguration) {
        // configure WebView by for example injecting javascript scripts on page loading
    }

    func userSwipedUpToApp(swipeUpUrl: String) {
        // The user swiped up on a page which should redirect to a location within the integrating app. The swipeUpUrl 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

Analytics

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 enum
  • data - an object containing data about the event which occurred

Example:

    ...
    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.

Client Ads

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.

Configure WebView after swipe up

By implementing configureSwipeUpWebView you can provide configuration for the SDK to inject into WebView presented after swipe up. If you allow user navigation on presented page in WebView then remember that scripts attached to configuration will be injected to all loaded pages in webView.

Example:

    func configureSwipeUpWebView(configuration: inout WKWebViewConfiguration) {
        // configure WebView by for example injecting javascript scripts on page loading
    }

Swiping Up To The Integrating App

The callback userSwipedUpToApp 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 userSwipedUpToApp(swipeUpUrl: String) {
        // parse the swipeUpUrl and navigate to the destination
    }
PREVIOUS
Forward Arrow