기술 자료

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. The
OnAdImpressionDataReady
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.
To 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
OnAdImpressionDataReady
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.
참고
OnAdImpressionDataReady
is invoked on a background thread, not the Unity main thread.
LevelPlayInterstitialAd 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.
중요
The returned data might include null values. To avoid potential crashes, ensure that you add protections before assigning the data.
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.
중요
Ensure that the inside parameters aren't null.
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); }}