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:
funconUserActivityOccurred(type:StorytellerUserActivity.EventType,data:StorytellerUserActivityData){iftype==.OpenedStory{// Retrieve the story id valueletopenedStoryId=data.storyId// Retrieve the story title valueletopenedStoryTitle=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 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.
When building ad CTAs, StorytellerAdAction supports StorytellerActionType.web, StorytellerActionType.inApp, StorytellerActionType.externalApp, and StorytellerActionType.store.
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:
Host-provided GAM or AdMob modules that know the exact ad unit only when starting a provider request can adopt StorytellerAdRequestTrackingModule. Set adSource to .gam or .admob so the SDK emits paid operational events. The protocol extends StorytellerModule with request-aware full-screen and bottom-banner methods:
Await onAdRequested immediately before each concrete provider load. Call it once for each native or banner attempt, including fallback attempts, invoke it serially, and do not retain it after the method returns. The SDK uses each reported value for Google AdRequested events and correlates the final attempt with load, failure, and paid events.
Set the same value on the returned StorytellerAd.adUnitId so rendered Ad lifecycle events retain it. The optional slot identifies the active full-screen request; modules that support cancelling their underlying load should honor its cancellation state. SDK-provided GAM and AdMob modules adopt this capability automatically.
For a detailed discussion of all the relevant considerations, please see the dedicated Ads page.
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.
{"slug": "storyteller-module", "page_title": "Build Storyteller Modules", "page_url": "StorytellerModule/", "canonical_url": "/ios/StorytellerModule/", "markdown": "# StorytellerModule\n\nThe StorytellerModule module is a protocol you can adopt to handle fetching ads and recording user activity events from Storyteller.\n\n## Properties\n\n### adSource\n\n`adSource: StorytellerAdSource?` identifies the ad source for ads provided by your module.\n\n- Use `.custom(\"myNetwork\")` for a custom integrating-app source.\n- Use `.gam` for Google Ad Manager and `.admob` for Google AdMob.\n- The SDK-provided VAST module uses `.custom(\"vast\")`.\n- `.storyteller` is reserved for Storyteller First Party ads.\n- Return `nil` when no source should be attached.\n\nThis value is attached to ad analytics payloads when available.\n\nIf not implemented, the default value is `nil`.\n\nThe SDK-provided `StorytellerGAMModule`, `StorytellerAdMobModule`, and `StorytellerVASTModule` set this value automatically.\n\nSee how the Showcase app registers modules in [`AppDelegate.setupStoryteller`](https://github.com/getstoryteller/storyteller-showcase-ios/blob/11.6.1/main/ShowcaseApp/ShowcaseApp.swift#L95).\n\n## Methods\n\n### Analytics\n\nThe callback `onUserActivityOccurred` provides analytics events and corresponding data triggered internally by the SDK. This information can be used in your app.\n\nThe following parameters are passed to the callback method:\n\n- `type` - type of event that occurred, as a `StorytellerUserActivity.EventType` enum\n- `data` - an object containing data about the event which occurred\n\nExample:\n\n<!-- storyteller-swift-example: id=storytellermodule-01 target=sdk-ios context=declarations -->\n\n```swift\nfunc onUserActivityOccurred(type: StorytellerUserActivity.EventType, data: StorytellerUserActivityData) {\n if type == .OpenedStory {\n // Retrieve the story id value\n let openedStoryId = data.storyId\n // Retrieve the story title value\n let openedStoryTitle = data.storyTitle\n\n // Report retrieved values from your app\n }\n}\n```\n\nFor a detailed discussion of all the relevant events and properties please see the dedicated [Analytics](Analytics.md) page.\n\n### Ads\n\nBy 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.\n\nWhen building ad CTAs, `StorytellerAdAction` supports `StorytellerActionType.web`, `StorytellerActionType.inApp`, `StorytellerActionType.externalApp`, and `StorytellerActionType.store`.\n\n#### getAd\n\nThe `getAd` method is called when the SDK needs a fullscreen ad:\n\n<!-- storyteller-swift-example: id=storytellermodule-02 target=sdk-ios context=declarations -->\n\n```swift\nfinal class CustomAdsModule: StorytellerModule {\n enum AdLoadingError: Error {\n case unavailable\n }\n\n let loadAd: () async -> StorytellerAd?\n\n init(loadAd: @escaping () async -> StorytellerAd?) {\n self.loadAd = loadAd\n }\n\n func getAd(for adRequestInfo: StorytellerAdRequestInfo) async throws -> StorytellerAd {\n guard let ad = await loadAd() else {\n throw AdLoadingError.unavailable\n }\n return ad\n }\n}\n```\n\n#### Bottom Banner Ads\n\nThe `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:\n\n<!-- storyteller-swift-example: id=storytellermodule-03 target=sdk-ios context=declarations -->\n\n```swift\nfinal class CustomBannerAdsModule: StorytellerModule {\n enum AdLoadingError: Error {\n case unavailable\n }\n\n let loadBannerAd: (CGFloat) async -> StorytellerAd?\n\n init(loadBannerAd: @escaping (CGFloat) async -> StorytellerAd?) {\n self.loadBannerAd = loadBannerAd\n }\n\n func getBottomBannerAd(for adRequestInfo: StorytellerAdRequestInfo, maxHeight: CGFloat) async throws -> StorytellerAd {\n guard let ad = await loadBannerAd(maxHeight) else {\n throw AdLoadingError.unavailable\n }\n return ad\n }\n}\n```\n\n#### Request-aware ad modules\n\nHost-provided GAM or AdMob modules that know the exact ad unit only when starting a provider request can adopt `StorytellerAdRequestTrackingModule`. Set `adSource` to `.gam` or `.admob` so the SDK emits paid operational events. The protocol extends `StorytellerModule` with request-aware full-screen and bottom-banner methods:\n\n- `getAdWithRequestTracking(for:slot:onAdRequested:)`\n- `getBottomBannerAdWithRequestTracking(for:maxHeight:onAdRequested:)`\n\nAwait `onAdRequested` immediately before each concrete provider load. Call it once for each native or banner attempt, including fallback attempts, invoke it serially, and do not retain it after the method returns. The SDK uses each reported value for Google `AdRequested` events and correlates the final attempt with load, failure, and paid events.\n\nSet the same value on the returned `StorytellerAd.adUnitId` so rendered Ad lifecycle events retain it. The optional `slot` identifies the active full-screen request; modules that support cancelling their underlying load should honor its cancellation state. SDK-provided GAM and AdMob modules adopt this capability automatically.\n\nFor a detailed discussion of all the relevant considerations, please see the dedicated [Ads](Ads.md) page.\n\n## Technical Consideration\n\nBecause the `StorytellerDelegate` also conforms to `StorytellerModule`, the way our SDK works is as following:\n\n- 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.\n- whenever `onUserActivityOccurred` is called, all modules will process the event, in the same order, and lastly the delegate will do the same.\n", "copy_markdown_include_header": false, "base_path": "", "ai_dir": "ai", "missing_payload_behavior": "empty"}