文档

支持

LevelPlay SDK - Unity

Impression-level revenue integration for Unity

Use the Impression Level Revenue (ILR) solution to track ad revenue at both device and impression levels, integrating with third-party analytics tools for deeper insights.
阅读时间2 分钟最后更新于 4 天前

Prerequisites

Ensure that you have correctly integrated the LevelPlay SDK 7.0.3+ 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 ImpressionData Listener

The LevelPlay SDK fires postbacks to inform you about the displayed ad. The ImpressionData listener 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 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){}

Integrate the ILR data

After you implement the ImpressionDataListener, 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 ImpressionDataReadyEvent(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 ImpressionDataReadyEvent(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); }}