Kotlin SDK
See how easy it is to integrate high-performance ads into your Android app using our lightweight SDK.
Requirements
- Min SDK version 26
- Kotlin 1.9+
- kotlinx-coroutines 1.8.1+
Migration Guide
Migrating from 1.x to 2.x
AdResult.Success has been removed. Replace it with AdResult.Filled (for available ads) and AdResult.NoFill (for unavailable ads).
Getting started
1. Installation
To get started, you will need to set up a publisher account to get a
publisherToken and code.mavenCentral(). Ensure mavenCentral() is listed in your project’s repository configuration.
build.gradle.kts file or version catalog:
2. Initialize AdsProvider
First, create an instance ofAdsProvider using the Builder. This object should be scoped to a single conversation and ideally tied to a lifecycle-aware component, like a ViewModel.
3. Set up IFA (Identifier for Advertisers)
The SDK automatically reads and forwards the advertising identifier (GAID) with each ad request. TheAD_ID permission is automatically included via manifest merger from the SDK — no changes to your AndroidManifest.xml are required. No runtime prompt is required — this is an install-time permission.
If your app targets Android 13+ (API level 33+) and you have set
tools:node="remove" on the AD_ID permission anywhere in your manifest configuration, remove that override or the advertising identifier will not be accessible.4. Prepare messages
To provide context for ad targeting, your app’s chat messages must be represented in a way the SDK understands. You have two options: Option 1: Conform toMessageRepresentable
You can make your existing message data class conform to the MessageRepresentable interface. This involves overriding the required properties to map to your class’s fields.
AdsMessage Data Class
If you cannot or prefer not to modify your existing data class, you can map your message objects to the AdsMessage type provided by the SDK. AdsMessage already conforms to MessageRepresentable.
Updating Messages and Collecting Ads
Whenever your list of messages changes, pass the new list to theAdsProvider.
The adsProvider.ads property is a kotlinx.coroutines.flow.Flow that emits AdResult.
Collect this flow from a CoroutineScope to receive and display ads.
5. Show your first ad
Once you collected the ads Map in your ViewModel, you can use it in your Composable UI to display the ads. TheInlineAd composable is provided for this purpose. It takes an AdConfig object and handles the ad rendering.
For View support use InlineAdView.
API documentation
AdsProvider.Builder
Constructor Parameters
Application context
Your unique publisher token.
Unique identifier that remains the same for the user’s lifetime (used for retargeting and rewarded ads).
Unique ID of the conversation.
Placement codes enabled for the conversation. Example:
['inlineAd'].Builder Methods
Character object used in this conversation.
Publisher-provided identifier for the user cohort (for A/B testing).
Email address of the user.
If true, the ads generation will be disabled initially. Can be later enabled by calling
enable().Your application theme
Regulatory object used in this conversation.TCF (Transparency and Consent Framework) signals —
gdpr and gdprConsent — are handled automatically by the SDK if you have a TCF-compliant CMP (Consent Management Platform) integrated in your app. You do not need to set these manually.AdResult types
Filled
Ad is available.
Map of message IDs to ad configurations.
NoFill
Ad is not available.
The code indicating the reason why the ad was skipped.
Error
An error occurred.
The error that occurred.
InlineAdView view & InlineAd composable properties
AdConfig object you will receive from the AdsProvider when observing the ads flow.
Callback with ad events. All possible types are described below.
AdEvent types
viewed
The user has viewed the ad.
Bid id.
Generated ad content.
Message ID.
Format.
clicked
The user has clicked the ad.
Bid id.
Generated ad content.
Message id.
Click URL.
Format.
renderStarted
Triggered before the first token is received.
Bid id.
renderCompleted
Triggered after the last token is received.
Bid id.
error
Triggered when an error occurs.
Error message.
Error code.
videoStarted
Triggered when the video playback starts.
Bid id.
videoCompleted
Triggered when the video playback finishes.
Bid id.
rewardGranted
Triggered when the user receives a reward.
Bid id.
Generic
Any other event.
Key-value pairs of any other possible event
Guides
Lifecycle Management
It is crucial to release the resources used by the SDK. Call theclose() method when the AdsProvider is no longer needed.
Example ViewModel Setup
Here is a simplified example of how to integrate theAdsProvider into an Android ViewModel. For a complete, working implementation, please see the example module in SDK repository.