Ad Content Callback - cleveradssolutions/CAS-Android Wiki

Through the use of AdCallback, you can listen for lifecycle events, such as when an ad is closed or the user leaves the app.

To register for ad events, set argument on show ad, that implements the AdCallback interface. Generally, the class that implements ads also acts as the listener class, in which case, the callback property can be set to this.

class MyActivity implements AdCallback {
  @Override
  void onShown(AdStatusHandler ad){
     // Executed when the ad is begin displayed.
     // AdStatusHandler is information of ad impression.

    if(ad.getPriceAccuracy() == PriceAccuracy.UNDISCLOSED) {
        Log.d(tag,"Begin impression " + ad.getAdType().name() + " ads with undisclosed cost from " + ad.getNetwork());
    } else {
        String accuracy = ad.getPriceAccuracy() == PriceAccuracy.FLOOR ? "a floor" : "an average";
        Log.d(tag, String.format("Begin impression %s ads with %s cost of %.4f CPM from %s.",
            ad.getAdType().name(), accuracy, ad.getCpm(), ad.getNetwork()));
    }
  }

  @Override
  void onShowFailed(String message){
    // Executed when the ad is failed to display.
  }

  @Override
  void onClicked(){
    // Executed when the user clicks on an ad.
  }

  @Override
  void onComplete(){
    // Executed when the Ad is completed.
    // Banner Ad does not use this callback.
  }

  @Override
  void onClosed(){
    // Executed when the ad is closed.
    // The Banner Ad cannot be displayed automatically after this callback for the current view.
    // If you decide to show the Banner Ad on this view then you need refresh view visibility.
  }
}

⚠️ Warning. When an error occurs during ad impression, executed the onShowFailed() only.
onClosed() in this case will not be executed, since the impression is not considered successful.

Impression Metadata

Property Name Type Description Examples
adType AdType The Placement Type for the impression. AdType.Banner
network String Demand Source name is the name of the mediation-side entity that purchased the impression. AdNetwork.VUNGLE
cpm Double The Cost Per Mille estimated impressions of the ad in USD. The value accuracy is returned in the priceAccuracy property. 1.55
priceAccuracy Int Accuracy of the CPM value. May return one of the following: 0 - FLOOR as minimum eCPMs;1 - BID is the exact and committed value per 1000 impressions;2 - UNDISCLOSED - When the demand source does not agree to disclose the payout of every impression. PriceAccuracy.FLOOR
versionInfo String Version of the mediation network SDK rendering the ad. "1.2.3"
identifier String Internal demand source name in CAS database. "Vungle33"

What’s Next?