Listener Usage

By implementing and providing HeliumFullscreenAdListener and HeliumBannerAdListerner interfaces to the Chartboost Mediation objects, you can get notifications about the success, failure, and other lifecycle events of Mediation Ads.

πŸ“˜

Note: 4.0.0 Update

  • As of 4.0.0, all listeners have combined the winning bid callback and the cache callback. The winning bid info is now found in winningBidInfo of the onAdCached() callback. The load identifier has been moved into the onAdCached() callback.
  • We have also clarified issues into an exception: ChartboostMediationAdException.

HeliumFullscreenAdListener

You can implement the HeliumFullscreenAdListener interface to receive notifications about interstitial and rewarded ads loading, displaying, and closing.

val heliumFullscreenAdListener = object : HeliumFullscreenAdListener {
    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")
    }
}

HeliumFullscreenAdListener heliumFullscreenAdListener = new HeliumFullscreenAdListener() {
    @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);
    }
};

HeliumBannerAdListener

You can implement the HeliumBannerAdListener interface to receive notifications about banner ads loading, displaying, and closing.

Starting with version 3.0.0, the HeliumBannerAdListener no longer has the didShow and didClose callbacks. In addition, the didReceiveWinningBid callback is only called when the placement has auto-refresh disabled.

val heliumBannerAdListener = object : HeliumBannerAdListener {
    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")
    }
}

HeliumBannerAdListener heliumBannerAdListener = new HeliumBannerAdListener() {

    @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 and onAdRewarded callbacks.