Impression-level revenue integration for Unity
Use the Impression Level Revenue (ILR) solution to track ad revenue data for each impression, integrating with third-party analytics platforms.
Read time 2 minutesLast updated a month ago
Prerequisites
Ensure that you have correctly integrated the LevelPlay SDK 9.5.0+ into your application. Refer to Unity Package integration.
For more information about the Impression Level Revenue (ILR) SDK feature and pre-requisites, refer to Impression-level revenue server-side API.
Implement the Impression Event
The LevelPlay SDK fires postbacks to inform you about the displayed ad. The event is an optional event that you can subscribe to on each ad object 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.
OnAdImpressionDataReadyTo add the ImpressionData listener to your application, ensure that you declare the listener before initializing the LevelPlay SDK to avoid any loss of information.
The LevelPlay SDK will trigger a callback on a background thread to notify your listener of successful impression data post-backs:
// This event is triggered on a background thread, not the Unity main thread.LevelPlay.OnImpressionDataReady += ImpressionDataReadyEvent;private void ImpressionDataReadyEvent(LevelPlayImpressionData impressionData){}
Set up the impression event
Subscribe to on each ad object. Subscribe right after constructing the ad object and before loading or showing it, so the impression is not missed. Each event delivers impressions only for the ad instance it belongs to.
OnAdImpressionDataReadyLevelPlayInterstitialAd interstitialAd = new LevelPlayInterstitialAd("adUnitId");interstitialAd.OnAdImpressionDataReady += OnInterstitialImpressionDataReady;void OnInterstitialImpressionDataReady(LevelPlayImpressionData impressionData){ Debug.Log($"Interstitial OnAdImpressionDataReady: {impressionData}");}LevelPlayRewardedAd rewardedAd = new LevelPlayRewardedAd("adUnitId");rewardedAd.OnAdImpressionDataReady += OnRewardedImpressionDataReady;void OnRewardedImpressionDataReady(LevelPlayImpressionData impressionData){ Debug.Log($"Rewarded OnAdImpressionDataReady: {impressionData}");}LevelPlayBannerAd bannerAd = new LevelPlayBannerAd("adUnitId");bannerAd.OnAdImpressionDataReady += OnBannerImpressionDataReady;void OnBannerImpressionDataReady(LevelPlayImpressionData impressionData){ Debug.Log($"Banner OnAdImpressionDataReady: {impressionData}");}
Remove the Impression Event
To stop receiving impression data for an ad object, unsubscribe with .
-=interstitialAd.OnAdImpressionDataReady -= OnInterstitialImpressionDataReady;rewardedAd.OnAdImpressionDataReady -= OnRewardedImpressionDataReady;bannerAd.OnAdImpressionDataReady -= OnBannerImpressionDataReady;
Integrate the ILR data
After you subscribe to the impression event, you can send the impression data to your own proprietary BI tools and DWH or integrate it with third-party tools.
You can refer to each field separately or get all information by using the allData method:
private void OnInterstitialImpressionDataReady(LevelPlayImpressionData impressionData){ string allData = impressionData.AllData; string adNetwork = impressionData.AdNetwork; double? revenue = impressionData.Revenue;}
For the full list of available ILR data, including field description and types, refer to Impression-level revenue server-side API.
The following example details 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.
private void OnInterstitialImpressionDataReady(LevelPlayImpressionData impressionData) { Debug.Log("unity-script: ImpressionDataReadyEvent impressionData = " + impressionData); if (impressionData != null) { Firebase.Analytics.Parameter[] AdParameters = { new Firebase.Analytics.Parameter("ad_platform", "LevelPlay"), new Firebase.Analytics.Parameter("ad_source", impressionData.AdNetwork), new Firebase.Analytics.Parameter("ad_format", impressionData.AdFormat), new Firebase.Analytics.Parameter("ad_unit_name", impressionData.InstanceName), new Firebase.Analytics.Parameter("currency", "USD"), new Firebase.Analytics.Parameter("value", impressionData.Revenue ?? 0) // Add protection for null values }; Firebase.Analytics.FirebaseAnalytics.LogEvent("custom_ad_impression", AdParameters); }}