Callbacks for handling the SDK processes
In order to handle the events of the Appodeal SDK lifecycle, you can implement the AppodealRequestCallbacks interface which includes the information about ad waterfalls with ad units, ads requesting process, and impressions.
Using these callbacks, you can optimize your app logic according to the signals from Appodeal SDK and get more information about what ad network has provided the ad, its settings, and the processes of ad waterfall.
Callbacks implementation:
Appodeal.setRequestCallbacks(new AppodealRequestCallbacks() { @Override public void onWaterfallStart(String adType) { } @Override public void onWaterfallFinish(String adType, double loadedECPM, boolean fill) { } @Override public void onRequestStart(String adType, String networkName, String adUnitName, double predictedEcpm) { } @Override public void onRequestFinish(String adType, String networkName, String adUnitName, double loadedEcpm, boolean fill) { } @Override public void onImpression(String adType, String networkName, String adUnitName, double loadedEcpm) { } @Override public void onClick(String adType, String networkName, String adUnitName, double loadedEcpm) { } });
All callbacks are called on the main thread.
Callbacks Description
Callback | Description | Usage |
---|---|---|
onWaterfallStart(String adType) | Called when the ad waterfall request starts.
| Used to track the starting moment of requesting ads in the ad waterfall. |
onWaterfallFinish(adType: String, loadedEcpm: Double, fill: Boolean) | Called every time the ad waterfall request has finished.
| Used to track when the ad waterfall has finished the process of requesting and providing get the information about the ad that was served. |
onRequestStart(adType: String, networkName: String?, adUnitName: String?, predictedEcpm: Double) | Called when the ad block request starts.
| Used to track events for requesting each ad block in the ad waterfall providing information about each requested block. |
onRequestFinish(adType: String, networkName: String?, adUnitName: String?, loadedEcpm: Double, fill: Boolean) | Called when the ad block request has finished.
| Used to get the response when the request for an ad block has finished providing the request result. |
onImpression(adType: String, networkName: String?, adUnitName: String?, loadedEcpm: Double) | Called every time an ad starts showing.
| Used to track the show event providing all the information about the ad creative that was shown. |
onClick(adType: String, networkName: String?, adUnitName: String?, loadedEcpm: Double) | Called when there was a click on an ad.
| Used to handle the click event when an ad was clicked providing all the information about the ad that was clicked. |
Use case
As an example, if you want to log an impression data to your analytics, you can use already prepared log methods from the Appodeal SDK as in the section below:
@Override public void onImpression(String adType, String networkName, String adUnitName, double loadedEcpm) { Map<String, Object> params = new HashMap<>(); params.put("ad_type", adType); params.put("network_name", networkName); params.put("ad_unit_name", adUnitName); params.put("loaded_ecpm", loadedEcpm); Appodeal.logEvent("appodeal_sdk_test_event", params); }
In case if you are using your own analytics in the project, please find the example below:
@Override public void onImpression(String adType, String networkName, String adUnitName, double loadedEcpm) { // Appsflyer Map<String, String> customParams = new HashMap<>(); customParams.put(Scheme.AD_UNIT, adUnitName); customParams.put(Scheme.AD_TYPE, adType); customParams.put(Scheme.ECPM_PAYLOAD, String.valueOf(loadedEcpm)); String monetizationNetwork = networkName.toString().isEmpty() ? networkName : "unspecified"; // Actually recording a single impression AppsFlyerAdRevenue.logAdRevenue( monetizationNetwork, Currency.getInstance("USD"), customParams ); // Adjust AdjustAdRevenue adRevenue = new AdjustAdRevenue("Appodeal") adRevenue.setRevenue(loadedEcpm/1000, "USD"); adRevenue.setAdRevenueNetwork(networkName); adRevenue.setAdRevenueUnit(adUnitName); Adjust.trackAdRevenue(adRevenue); // Firebase Bundle bundle = new Bundle(); bundle.putString(FirebaseAnalytics.Param.SOURCE, networkName); bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, adType); bundle.putString(FirebaseAnalytics.Param.VALUE, String.valueOf(loadedEcpm/1000)); bundle.putString(FirebaseAnalytics.Param.CURRENCY, "USD"); mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle); }