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.
읽는 시간 2분최근 업데이트: 하루 전
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. TheOnAdImpressionDataReady// 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 toOnAdImpressionDataReadyLevelPlayInterstitialAd 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:
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){ string allData = impressionData.AllData; string adNetwork = impressionData.AdNetwork; double? revenue = impressionData.Revenue;}
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); }}