Skip to content

Early Access SDK

Str4tos edited this page Aug 21, 2024 · 14 revisions

Note

Please note that the new CAS 4.0.0-beta1 version is available as an early release and may have issues.

Integration

In addition to the lines described in the Add Maven repositories section, please add the beta maven repository to your settings.gradle file.

pluginManagement {  
    repositories {  
        ...  
        maven {  
            name = "CASBetaRepo"  
            url = "https://repsy.io/mvn/cleveradssolutions/beta"  
        }  
    }
}

dependencyResolutionManagement {  
    repositories {  
        ...
        maven {  
            name = "CASBetaRepo"  
            url = "https://repsy.io/mvn/cleveradssolutions/beta"  
            content { it.includeGroup("com.cleveradssolutions") }  
        }
    }
}

Note

pluginManagement.repositories can also be defined in the root-level build.gradle file within buildscript.repositories.

Continue with Plugin integration, using the beta version:

plugins {
    id("com.cleveradssolutions.gradle-plugin") version "4.0.0-beta1"
}

cas {
    ...
}

Changes

Coming soon...

AdError

  • The AdError.message provides more detailed error information. There can be multiple detailed messages for a single error code.
  • All error code constants moved from AdError to AdErrorCode.
  • New errors have been added: AdErrorCode.TIMEOUT and AdErrorCode.NOT_INITIALIZED.

OnAdImpressionListener (new)

A functional interface for listening to ad impression events.

val impressionListener = OnAdImpressionListener { ad: AdContent ->  
    // Called when an ad impression occurs.  
}

AdContent (new)

The deprecated AdImpression (AdStatusHandler) has been replaced by the new AdContent data structure, which contains information about the loaded/displayed ad. You can access AdContent using OnAdImpressionListenerScreenAdContentCallback, or NativeAdContentCallback.

  • format: AdFormat - Gets the format of the ad that is shown. See new AdFormat enum.
  • sourceName: String - Gets the display name of the mediated network that purchased the impression.
  • sourceId: Int - Gets the ID of the mediated network that purchased the impression. See new AdSourceId constants.
  • sourceUnitId: String - Gets the Ad Unit ID from the mediated network that purchased the impression.
  • creativeId: String? - Gets the Creative ID associated with the ad, if available. May be null. You can use this ID to report creative issues to the Ad review team.
  • revenue: Double - Gets the revenue generated from the impression, in USD. The revenue value may be either estimated or exact, depending on the precision specified by revenuePrecision.
  • revenuePrecision: Int - Gets the precision type of the revenue field. See new AdRevenuePrecision constants.
  • impressionDepth: Int - Gets the total number of impressions across all ad formats for the current user, across all sessions.
  • revenueTotal: Double - Gets the accumulated value of user ad revenue in USD from all ad format impressions.

Native Ad (new)

Read more about new Native Ad format implementation.

ScreenAdContentCallback (new)

A abstract class for handling events related to screen ad content.

val screenCallback = object : ScreenAdContentCallback(){  
    override fun onAdLoaded(ad: AdContent) {  
        // Called when the ad content has been successfully loaded.  
    }  
    override fun onAdFailedToLoad(format: AdFormat, error: AdError) {  
        // Called when the ad content fails to load.  
    }  
    override fun onAdFailedToShow(format: AdFormat, error: AdError) {  
        // Called when the ad content fails to show.  
    }  
    override fun onAdShowed(ad: AdContent) {  
        // Called when the ad content is successfully shown.  
    }  
    override fun onAdClicked(ad: AdContent) {  
        // Called when the ad content is clicked by the user.  
    }  
    override fun onAdDismissed(ad: AdContent) {  
        // Called when the ad content is dismissed.  
    }  
}

App Open Ad

The App Open Ad format has been newly implemented in the com.cleveradssolutions.sdk.screen.CASAppOpen class.

In most cases, a casId is the same as your application package name. Use demo as the casId to receive a demo ad for testing your implementation.

import com.cleveradssolutions.sdk.screen.CASAppOpen
...

val casId = if (BuildConfig.DEBUG) "demo" else BuildConfig.APPLICATION_ID
val appOpenAd = CASAppOpen(this, casId)

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    // Optionally, you can register listeners.
    appOpenAd.contentCallback = screenCallback
    appOpenAd.onImpressionListener = impressionListener
}

override fun onResume() {  
    super.onResume()  
    if (appOpenAd.isLoaded) {
        appOpenAd.show(this)
    } else {
        appOpenAd.load()
    }
}

override fun onDestroy() {
    appOpenAd.destroy()
    super.onDestroy()  
}

Note

Note that you must keep a reference to the ad object throughout its use. The ad object may be freed from memory if it is no longer in use, and in that case, callbacks will not be triggered.