Listener Usage
By implementing and providing ChartboostMediationFullscreenAdListener
and ChartboostMediationBannerAdViewListener
interfaces to the Chartboost Mediation objects, you can get notifications about the success, failure, and other lifecycle events of Mediation Ads.
winningBidInfo
of the onAdCached()
callback. The load identifier has been moved into the onAdCached()
callback.ChartboostMediationAdException
.ChartboostMediationFullscreenAdListener π
You can implement the ChartboostMediationFullscreenAdListener
interface to receive notifications about interstitial and rewarded ads loading, displaying, and closing.
-
val chartboostMediationFullscreenAdListener = object : ChartboostMediationFullscreenAdListener { override fun onAdCached(placementName: String, loadId: String, winningBidInfo: Map<String, String>, error: ChartboostMediationAdException?) { error?.let { Log.d(TAG, "Ad cache failed for placement: $placementName " + "reason: ${it.message}") } ?: run { // Show the ad if it's ready Log.d(TAG, "Ad cached for placement: $placementName") } } override fun onAdShown(placementName: String, error: ChartboostMediationAdException?) { error?.let { Log.d(TAG, "Ad show failed for placement: $placementName " + "reason: ${it.message}") } ?: run { Log.d(TAG, "Ad shown for placement: $placementName") } } override fun onAdClicked(placementName: String) { Log.d(TAG, "Ad clicked for placement: $placementName") } override fun onAdClosed(placementName: String, error: ChartboostMediationAdException?) { error?.let { Log.d(TAG, "Ad closed and there was an error for placement: $placementName " + "reason: ${it.message}") } ?: run { Log.d(TAG, "Ad closed for placement: $placementName") } } override fun onAdImpressionRecorded(placementName: String) { Log.d(TAG, "Ad recorded impression for placement: $placementName") } override fun onAdRewarded(placementName: String) { Log.d(TAG, "Ad rewarded user for placement: $placementName") } }
-
ChartboostMediationFullscreenAdListener chartboostMediationFullscreenAdListener = new ChartboostMediationFullscreenAdListener() { @Override public void onAdCached(@NonNull String placementName, @NonNull String loadId, @NonNull Map<String, String> winningBidInfo, @Nullable ChartboostMediationAdException error) { if (error != null) { Log.d(TAG, "Ad cache failed for placement: " + placementName + " reason: " + error.getMessage()); } else { // Show the ad if it's ready Log.d(TAG, "Ad cached for placement: " + placementName); } } @Override public void onAdShown(@NonNull String placementName, @Nullable ChartboostMediationAdException error) { if (error != null) { Log.d(TAG, "Ad show failed for placement: " + placementName + " reason: " + error.getMessage()); } else { Log.d(TAG, "Ad shown for placement: " + placementName); } } @Override public void onAdClicked(@NonNull String placementName) { Log.d(TAG, "Ad clicked for placement: " + placementName); } @Override public void onAdClosed(@NonNull String placementName, @Nullable ChartboostMediationAdException error) { if (error != null) { Log.d(TAG, "Ad closed with error for placement: " + placementName + " reason: " + error.getMessage()); } else { Log.d(TAG, "Ad closed for placement: " + placementName); } } @Override public void onAdImpressionRecorded(@NonNull String placementName) { Log.d(TAG, "Ad recorded impression for placement: " + placementName); } @Override public void onAdRewarded(@NonNull String placementName) { Log.d(TAG, "Ad rewarded user for placement: " + placementName); } };
ChartboostMediationBannerAdViewListener π
You can implement the ChartboostMediationBannerAdViewListener
interface to receive notifications about banner ads loading, displaying, and closing.
Starting with version 3.0.0, the ChartboostMediationBannerAdViewListener
no longer has the didShow
and didClose
callbacks. In addition, the didReceiveWinningBid
callback is only called when the placement has auto-refresh disabled.
-
val chartboostMediationBannerAdViewListener = object : ChartboostMediationBannerAdViewListener { override fun onAdCached( placementName: String, loadId: String, winningBidInfo: HashMap<String, String>, error: ChartboostMediationAdException? ) { error?.let { Log.d(TAG, "Ad cache failed for placement: $placementName " + "reason: ${it.message}" ) } ?: run { // Show the ad if it's ready Log.d(TAG, "Ad cached for placement: $placementName with loadId $loadId and winningBidInfo $winningBidInfo") } } override fun onAdClicked(placementName: String) { Log.d(TAG, "Ad clicked for placement: $placementName") } override fun onAdImpressionRecorded(placementName: String) { Log.d(TAG, "Ad impression recorded for placement: $placementName") } }
-
ChartboostMediationBannerAdViewListener chartboostMediationBannerAdViewListener = new ChartboostMediationBannerAdViewListener() { @Override public void onAdCached(@NonNull String placementName, @NonNull String loadId, @NonNull Map<String, String> winningBidInfo, @Nullable ChartboostMediationAdException error) { if (error != null) { Log.d(TAG, "Ad cache failed for placement: " + placementName + " reason: " + error.getMessage()); } else { // Banners should automatically show if they are on screen Log.d(TAG, "Ad cached for placement: " + placementName + " with loadId " + loadId + " and winningBidInfo " + winningBidInfo); } } @Override public void onAdClicked(@NonNull String placementName) { Log.d(TAG, "Ad clicked for placement: " + placementName); } @Override public void onAdImpressionRecorded(@NonNull String placementName) { Log.d(TAG, "Ad impression recorded for placement: " + placementName); } };
Note Not all partner SDKs support the
onAdClicked
andonAdRewarded
callbacks.