Skip to content

StorytellerModule#

The StorytellerModule module is a protocol you can adopt to handle fetching ads and recording user activity events from Storyteller. It contains the following methods:

Methods#

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

Example:

func onUserActivityOccurred(type: StorytellerUserActivity.EventType, data: StorytellerUserActivityData) {
    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.

Ads#

By implementing getAd and getBottomBannerAd, 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 using async/await, and should be returned directly or throw an error if no ad is available.

getAd#

The getAd method is called when the SDK needs a fullscreen ad:

func getAd(for adRequestInfo: StorytellerAdRequestInfo) async throws -> StorytellerAd {
    // Action to get an ad
    if let ad = await getMyAd() {
        // Provide the ad to the SDK
        return ad
    } else {
        // Throw an error indicating there is no ad
        throw YourError()
    }
}

Bottom Banner Ads#

The getBottomBannerAd method is called when the SDK needs a bottom banner ad (displayed at the bottom of clips). The maxHeight parameter indicates the maximum allowed banner height for the current layout:

func getBottomBannerAd(for adRequestInfo: StorytellerAdRequestInfo, maxHeight: CGFloat) async throws -> StorytellerAd {
    // Action to get a bottom banner ad
    if let ad = await getMyBottomBannerAd() {
        // Provide the ad to the SDK
        return ad
    } else {
        // Throw an error indicating there is no ad
        throw YourError()
    }
}

For a detailed discussion of all the relevant considerations, please see the dedicated Ads page.

Technical Consideration#

Because the StorytellerDelegate also conforms to StorytellerModule, the way our SDK works is as following:

  • whenever ads are requested, each module has a chance to fetch modules, in the order they appear in the modules array. If a module throws an error, the next one will be queried. Lastly the delegate is requested to provide an ad. If all fail to return an ad, no ad is shown.
  • whenever onUserActivityOccurred is called, all modules will process the event, in the same order, and lastly the delegate will do the same.