Documentation

LevelPlay SDK - Android

Impression-level revenue integration for Android

Integrate the Impression Level Revenue (ILR) SDK API to capture real-time ad revenue data for each impression, enabling detailed monetization insights and seamless integration with third-party analytics platforms.
Read time 2 minutesLast updated a day ago

Prerequisites

Ensure that you have correctly integrated the LevelPlay SDK 9.5.0+ into your application. Refer to Integration checklists for Android.

Implement the LevelPlayImpressionDataListener

The LevelPlay SDK fires postbacks to inform you about the displayed ad. The LevelPlayImpressionDataListener is an optional listener that you can implement to receive impression data. This listener will provide you with information about all ad units, and you'll be able to identify the different ads by using the impression level revenue. To add the LevelPlayImpressionDataListener to your application, declare the listener before initializing the LevelPlay SDK to avoid any loss of information.
public static void addImpressionDataListener(LevelPlayImpressionDataListener listener)
The LevelPlay SDK will notify your listener of the success post-backs related to impression data:
public static void addImpressionDataListener(ImpressionDataListener listener){ /** Invoked when the ad was displayed successfully and the impression data was recorded **/ }

Set up the Impression Listener

Implement
LevelPlayImpressionDataListener
and set it on each ad object by calling
setImpressionDataListener()
. Attach it right after constructing the ad object and before loading or showing it, so the impression is not missed. Each listener receives impressions only for the instance it is attached to.
Java
import com.unity3d.mediation.impression.LevelPlayImpressionData;import com.unity3d.mediation.impression.LevelPlayImpressionDataListener;// InterstitialLevelPlayInterstitialAd interstitialAd = new LevelPlayInterstitialAd("adUnitId");interstitialAd.setImpressionDataListener(new LevelPlayImpressionDataListener() { @Override public void onImpressionSuccess(LevelPlayImpressionData impressionData) { Log.d(TAG, "Interstitial onImpressionSuccess: " + impressionData); }});// RewardedLevelPlayRewardedAd rewardedAd = new LevelPlayRewardedAd("adUnitId");rewardedAd.setImpressionDataListener(new LevelPlayImpressionDataListener() { @Override public void onImpressionSuccess(LevelPlayImpressionData impressionData) { Log.d(TAG, "Rewarded onImpressionSuccess: " + impressionData); }});// BannerLevelPlayBannerAdView bannerAdView = new LevelPlayBannerAdView(this, "adUnitId");bannerAdView.setImpressionDataListener(new LevelPlayImpressionDataListener() { @Override public void onImpressionSuccess(LevelPlayImpressionData impressionData) { Log.d(TAG, "Banner onImpressionSuccess: " + impressionData); }});
Kotlin
import com.unity3d.mediation.impression.LevelPlayImpressionDataimport com.unity3d.mediation.impression.LevelPlayImpressionDataListener// Interstitialval interstitialAd = LevelPlayInterstitialAd("adUnitId")interstitialAd.setImpressionDataListener(object : LevelPlayImpressionDataListener { override fun onImpressionSuccess(impressionData: LevelPlayImpressionData) { Log.d(TAG, "Interstitial onImpressionSuccess: $impressionData") }})// Rewardedval rewardedAd = LevelPlayRewardedAd("adUnitId")rewardedAd.setImpressionDataListener(object : LevelPlayImpressionDataListener { override fun onImpressionSuccess(impressionData: LevelPlayImpressionData) { Log.d(TAG, "Rewarded onImpressionSuccess: $impressionData") }})// Bannerval bannerAdView = LevelPlayBannerAdView(this, "adUnitId")bannerAdView.setImpressionDataListener(object : LevelPlayImpressionDataListener { override fun onImpressionSuccess(impressionData: LevelPlayImpressionData) { Log.d(TAG, "Banner onImpressionSuccess: $impressionData") }})

Remove Impression Data Listener

To stop receiving impression data for an ad object, pass
null
to
setImpressionDataListener()
.
Java
interstitialAd.setImpressionDataListener(null);rewardedAd.setImpressionDataListener(null);bannerAdView.setImpressionDataListener(null);
Kotlin
interstitialAd.setImpressionDataListener(null)rewardedAd.setImpressionDataListener(null)bannerAdView.setImpressionDataListener(null)
Note
As of the LevelPlay SDK 7.1.0 release, setImpressionDataListener is deprecated and replaced with addImpressionDataListener.

Integrate the ILR data

After you implement the LevelPlayImpressionDataListener, you can send the impression data to your own proprietary BI tools and DWH or integrate it with third-party tools.
Note
The returned data might include null values. Add protections before assigning the data to avoid potential crashes.
You can refer to each field separately or get all information by using the allData method:
public void onImpressionSuccess (LevelPlayImpressionData impressionData){ Double revenue = impressionData.getRevenue(); String adNetwork = impressionData.getAdNetwork(); JSONObject allData = impressionData.getAllData(); }
For the full list of available ILR data, including field description and types, refer to Impression Level Revenue SDK API. The following example shows how to integrate the Impression Level Revenue SDK API data with Google Analytics for Firebase. You can use it as-is or make any required changes to integrate with third-party reporting tools or your own proprietary optimization tools and databases.
Note
Ensure that the inside parameters aren't null.
/** Invoked when the ad was displayed successfully and the impression data was recorded **/ @Override public void onImpressionSuccess(LevelPlayImpressionData impressionData) { // The onImpressionSuccess will be reported when the rewarded video and interstitial ad is opened. // For banners, the impression is reported on load success. Log.d(TAG, "onImpressionSuccess" + impressionData); if (impressionData != null) { Bundle bundle = new Bundle(); bundle.putString(FirebaseAnalytics.Param.AD_PLATFORM, "LevelPlay"); bundle.putString(FirebaseAnalytics.Param.AD_SOURCE, impressionData.getAdNetwork()); bundle.putString(FirebaseAnalytics.Param.AD_FORMAT, impressionData.getAdFormat()); bundle.putString(FirebaseAnalytics.Param.AD_UNIT_NAME, impressionData.getInstanceName()); bundle.putString(FirebaseAnalytics.Param.CURRENCY, "USD"); bundle.putDouble(FirebaseAnalytics.Param.VALUE, java.util.Objects.requireNonNullElse(impressionData.getRevenue(), 0.0)); // Add protection for null values mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.AD_IMPRESSION, bundle); } }