Skip to main content

VelocityAds

setUserId()

fun setUserId(userId: String?)
ParameterTypeRequiredDescription
userIdString?NoUser identifier
Call before initSDK() for best performance.

initSDK()

fun initSDK(
    context: Context,
    initRequest: VelocityAdsInitRequest,
    listener: VelocityAdsInitListener
)
ParameterTypeRequiredDescription
contextContextYesApplication context
initRequestVelocityAdsInitRequestYesBuilt via VelocityAdsInitRequest.Builder
listenerVelocityAdsInitListenerYesReceives init success or failure

Utility Methods

MethodDescription
isInitialized(): BooleanReturns true if the SDK completed initialization successfully
getSdkVersion(): StringReturns the SDK version string
setPluginInfo(type, version)Sets plugin metadata for cross-platform wrapper tracking. Call before initSDK()
setDoNotSell(flag: Boolean)Sets the CCPA “Do Not Sell” preference
setConsent(flag: Boolean)Sets the GDPR consent preference

VelocityNativeAd

The core ad object. Create one instance per ad placement, then call loadAd().
val nativeAd = VelocityNativeAd(adRequest)

loadAd() — Raw data

fun loadAd(listener: VelocityNativeAdListener)
Loads an ad and delivers raw creative data. Call registerViewForInteraction() inside onAdLoaded.

loadAd() — Compose card

fun loadAd(listener: VelocityNativeAdComposeListener)
The adRequest must be a VelocityNativeAdViewRequest. Delivers a @Composable lambda on success.

loadAd() — View card

fun loadAd(context: Context, listener: VelocityNativeAdViewListener)
The adRequest must be a VelocityNativeAdViewRequest. Delivers a ready-to-display android.view.View on success.

registerViewForInteraction()

fun registerViewForInteraction(
    adView: View,
    clickableViews: List<View>
)
ParameterTypeRequiredDescription
adViewViewYesRoot view — used for impression visibility detection
clickableViewsList<View>YesViews that trigger onAdClicked when tapped

unregisterViewForInteraction()

fun unregisterViewForInteraction()
Removes all click and impression listeners previously registered.

destroyAd()

fun destroyAd()
Releases all SDK-internal state. Call in onDestroy() for every loaded ad.

Models

VelocityNativeAdRequest

VelocityNativeAdRequest.Builder()
    .withPrompt("user query")                // Optional
    .withAIResponse("ai response")           // Optional
    .withConversationHistory(history)        // Optional
    .withAdditionalContext("travel, summer") // Optional
    .withAdUnitId("my-unit-id")              // Optional
    .build()

VelocityNativeAdViewRequest

Extends VelocityNativeAdRequest with size and theming for rendered ad formats.
VelocityNativeAdViewRequest.Builder(VelocityAdViewSize.M)
    .withPrompt("user query")
    .withAdConfiguration(AdConfiguration())  // Optional
    .build()

NativeAd (ad creative data)

Accessed via VelocityNativeAd.data after a successful load.
FieldTypeDescription
adIdStringUnique ad load identifier
titleStringAd headline
descriptionStringAd body text
callToActionStringCTA button text
advertiserNameStringAdvertiser/brand name
sponsoredLabelStringSponsorship label
badgeLabelStringBadge text (e.g. “ad”)
advertiserIconUrlStringAdvertiser logo/icon URL
largeImageUrlString?Main ad image URL (optional)
squareImageUrlString?Square ad image URL (optional)
clickUrlStringURL opened on ad click
impressionUrlStringImpression tracking URL

VelocityAdViewSize

enum class VelocityAdViewSize(val heightDp: Int) {
    S(50),   // Small
    M(100),  // Medium
    L(300)   // Large
}

AdConfiguration

data class AdConfiguration(
    val colorScheme: AdColorScheme? = null,
    val adTypography: AdTypography? = null,
    val darkTheme: Boolean? = null   // null = follow system
)

Listeners

VelocityAdsInitListener

interface VelocityAdsInitListener {
    fun onInitSuccess()
    fun onInitFailure(error: VelocityAdsError)
}
Both methods are always invoked on the main thread.

VelocityAdsInitRequest.Builder

VelocityAdsInitRequest.Builder(appKey: String)
    .withDebug(debug: Boolean)  // optional, defaults to false
    .build()

VelocityNativeAdListener

interface VelocityNativeAdListener {
    fun onAdLoaded(nativeAd: VelocityNativeAd)
    fun onAdFailedToLoad(nativeAd: VelocityNativeAd, error: VelocityAdsError)
    fun onAdImpression(nativeAd: VelocityNativeAd)
    fun onAdClicked(nativeAd: VelocityNativeAd)
}
MethodDescription
onAdLoadedMain thread. Ad loaded — nativeAd.data is populated. Call registerViewForInteraction here
onAdFailedToLoadAd request failed. nativeAd.data is not accessible
onAdImpressionFired once when the registered adView is ≥ 50% visible on screen
onAdClickedFired each time the user taps a registered clickable view

VelocityNativeAdComposeListener

interface VelocityNativeAdComposeListener {
    fun onAdLoaded(nativeAd: VelocityNativeAd, adContent: @Composable () -> Unit)
    fun onAdFailedToLoad(nativeAd: VelocityNativeAd, error: VelocityAdsError)
    fun onAdImpression(nativeAd: VelocityNativeAd)
    fun onAdClicked(nativeAd: VelocityNativeAd)
}

VelocityNativeAdViewListener

interface VelocityNativeAdViewListener {
    fun onAdLoaded(nativeAd: VelocityNativeAd, nativeAdView: View)
    fun onAdFailedToLoad(nativeAd: VelocityNativeAd, error: VelocityAdsError)
    fun onAdImpression(nativeAd: VelocityNativeAd)
    fun onAdClicked(nativeAd: VelocityNativeAd)
}

Error Codes

VelocityAdsError

data class VelocityAdsError(val code: Int, val message: String)

VelocityAdsErrorCode

CodeConstantMeaning
1000INVALID_URLMalformed URL
1001NETWORK_ERRORNetwork request failed
1002JSON_PARSE_ERRORResponse JSON could not be parsed
1003INVALID_RESPONSEResponse structure is invalid
1004EMPTY_RESPONSE_BODYServer returned an empty body
1005SERVER_ERROR_FIELDServer returned an error field
1006HTTP_FAILUREHTTP status code indicates failure
2000INVALID_APP_KEYappKey is empty or blank
2001SDK_NOT_INITIALIZEDloadAd called before initSDK
2002SDK_INITIALIZATION_IN_PROGRESSinitSDK called while already initializing
2003LOAD_ALREADY_IN_PROGRESSloadAd called while already loading
2004LOAD_SERVICE_UNAVAILABLEInternal bidder service not available
2005INVALID_AD_RESPONSEAd response is missing required data
2006NO_FILLNo ad available for the given context
2007INTERNAL_ERRORUnexpected internal SDK error
2008INVALID_AD_REQUESTWrong request type passed to a load method
2009WATERFALL_LOAD_FAILEDWaterfall load failed