init

fun init(adUnit: (StorytellerAdRequestInfo) -> String, templateIds: StorytellerCustomNativeTemplateIds? = null, keyValuePairs: () -> Map<String, String> = { emptyMap() }, bottomBannerAdUnit: (StorytellerAdRequestInfo) -> String?? = null)

Initializes the Storyteller GAM module with the necessary configuration for ad requests.

This method sets up the GAM module with dynamic ad unit resolution, custom native template IDs, and client-specific key-value pairs for ad targeting. For detailed examples and setup, see the Storyteller Ads Documentation.

Parameters

adUnit

A lambda function that accepts a StorytellerAdRequestInfo object and returns the appropriate ad unit ID (String) for the current ad request context. This allows for flexible ad unit determination, for instance, using different ad units for Stories versus Clips, or based on other criteria within StorytellerAdRequestInfo. Example: { storytellerAdRequestInfo -> when (storytellerAdRequestInfo) { is StorytellerAdRequestInfo.StoriesAdRequestInfo -> "/your/stories/ad_unit_id" else -> "/your/clips/ad_unit_id" } }

templateIds

An optional CustomNativeTemplateIds object. This should be provided if you are using Custom Native Ads configured with the Storyteller Delivery team. It holds the template IDs for Stories and Clips ads. If you only use one type (e.g., only Stories), you only need to supply the relevant ID. Example: CustomNativeTemplateIds(stories = "12345", clips = "67890")

keyValuePairs

A lambda function that returns a Map of String to String. These are custom key-value pairs that will be passed to the Google Ad Manager SDK for ad targeting. The Storyteller GAM SDK includes a default set of KVPs; these client-provided pairs will be merged with the default ones. Note that the SDK does not inherit KVPs set elsewhere in your application. Example: { mapOf("targetingKey" to "targetingValue") }

bottomBannerAdUnit

An optional lambda function for bottom banner ads in clips. This is separate from the main ad unit to allow different targeting for bottom banner placements. If not provided, bottom banner ads will not be requested. Only 300x50 and 320x50 ad sizes are supported. Example: { adRequestInfo -> "/your/bottom_banner/ad_unit_id" }