This guide provides the implementation for sending Impression Level Revenue Data (ILRD) from TopOn to Tenjin. The integration works by listening for a specific callback from the TopOn SDK, onAdRevenuePaid(ATAdInfo adInfo), which fires every time an ad impression generates revenue. This ATAdInfo object, containing detailed revenue data, is then passed to the Tenjin SDK.
本指南提供了将广告展示层级收入数据(ILRD)从 TopOn 发送到 Tenjin 的实现方法。该集成通过监听 TopOn SDK 的一个特定回调 onAdRevenuePaid(ATAdInfo adInfo) 来工作,每当一次广告展示产生收益时,该回调便会触发。这个包含详细收益数据的 ATAdInfo 对象随后会被传递给 Tenjin SDK。
Step 1: Verify Project Dependencies 第 1 步:验证项目依赖 #
In your app-level build.gradle file, ensure you have included the necessary dependencies. 在您应用模块的 build.gradle 文件中,请确保已包含必要的依赖项。
- Latest TopOn SDK 最新的 TopOn SDK
- Ad Network Adapters: You must include the adapters for every ad network you intend to mediate through TopOn (e.g., AdMob, AppLovin, Unity Ads, Meta, etc.). 广告平台 Adapter: 您 必须 为每一个您希望通过 TopOn 进行聚合的广告平台添加其对应的 adapter(例如:AdMob, AppLovin, Unity Ads, Meta 等)。
// Example: app/build.gradle
dependencies {
// 1. TopOn (AnyThink) SDK Core
implementation ‘com.anythink.sdk:core:6.4.17’
// 2. Adapters for ALL supported 广告网络 所有支持的广告平台的 Adapter
implementation ‘com.anythink.sdk:adapter-admob:6.4.17’
implementation ‘com.anythink.sdk:adapter-applovin:6.4.17’
implementation ‘com.anythink.sdk:adapter-unityads:6.4.17’
implementation ‘com.anythink.sdk:adapter-meta:6.4.17’
// … add every other adapter you use 添加您使用的所有其他 adapter
}
Step 2: Initialize SDKs 初始化 SDK #
In your primary Activity’s onCreate method, initialize both Tenjin and TopOn. 在您的主 Activity 的 onCreate 方法中,初始化 Tenjin 和 TopOn 的 SDK。
import com.anythink.core.API 应用程序接口.ATSDK;
import com.tenjin.android.TenjinSDK;
// … other imports
public class YourMainActivity extends Activity {
private TenjinSDK tenjinInstance;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// … your other setup code
// 1. Initialize Tenjin 初始化 Tenjin
tenjinInstance = TenjinSDK.getInstance(this, “<Your Tenjin API 应用程序接口 Key>”);
// 2. Initialize TopOn 初始化 TopOn
ATSDK.init(getApplicationContext(), “<Your TopOn App ID>”, “<Your TopOn App Key>”);
// 3. Load your ads 加载您的广告
loadAllAdFormats();
}
// …
}
Step 3: Implement Revenue Tracking for EACH Ad Format 为每种广告格式实现收益追踪 #
You must implement the revenue listener for every ad format you use. If tracking is missing for even one format (e.g., Rewarded Video), all impressions from it will be missed by Tenjin. The correct method is to set an ATAdRevenueListener and call Tenjin’s eventAdImpressionTopOn() method from inside the onAdRevenuePaid() callback.
您必须为您使用的 每一种广告格式 实现收益监听器。如果任何一种格式(例如:激励视频)缺少追踪,其所有的广告展示都将被 Tenjin 遗漏。正确的方法是设置一个 ATAdRevenueListener,并在 onAdRevenuePaid() 回调内部调用 Tenjin 的 eventAdImpressionTopOn() 方法。
A. Banner Ads 横幅广告 (Banner)
private void loadBannerAd() {
ATBannerView mBannerView = new ATBannerView(this);
mBannerView.setPlacementId(“<Your_Banner_Placement_ID>”);
// … add the banner view to your layout …
// Set the revenue listener 设置收益监听
mBannerView.setAdRevenueListener(new ATAdRevenueListener() {
@Override
public void onAdRevenuePaid(ATAdInfo adInfo) {
// Send revenue data to Tenjin for every impression, including auto-refreshes
// 为每一次广告展示(包括自动刷新)向 Tenjin 发送收益数据
if (tenjinInstance != null) {
tenjinInstance.eventAdImpressionTopOn(adInfo);
}
}
});
mBannerView.loadAd();
}
B. Interstitial ads 插播广告 插屏广告 (Interstitial)
private void loadInterstitialAd() {
ATInterstitial mInterstitialAd = new ATInterstitial(this, “<Your_Interstitial_Placement_ID>”);
// Set the revenue listener
// 设置收益监听器
mInterstitialAd.setAdRevenueListener(new ATAdRevenueListener() {
@Override
public void onAdRevenuePaid(ATAdInfo adInfo) {
// Send revenue data to Tenjin
// 向 Tenjin 发送收益数据
if (tenjinInstance != null) {
tenjinInstance.eventAdImpressionTopOn(adInfo);
}
}
});
mInterstitialAd.load();
}
C. Rewarded Video Ads 激励视频广告 (Rewarded Video)
private void loadRewardedVideoAd() {
ATRewardVideoAd mRewardVideoAd = new ATRewardVideoAd(this, “<Your_Rewarded_Placement_ID>”);
// Set the revenue listener
// 设置收益监听器
mRewardVideoAd.setAdRevenueListener(new ATAdRevenueListener() {
@Override
public void onAdRevenuePaid(ATAdInfo adInfo) {
// Send revenue data to Tenjin
// 向 Tenjin 发送收益数据
if (tenjinInstance != null) {
tenjinInstance.eventAdImpressionTopOn(adInfo);
}
}
});
mRewardVideoAd.load();
}
D. Native and Splash Ads 原生广告 (Native) 和开屏广告 (Splash)
You must follow the exact same pattern for any other ad formats you use, such as Native Ads (ATNativeAd) and Splash Ads (ATSplashAd). Each ad object needs its own ATAdRevenueListener. 对于您使用的任何其他广告格式,例如原生广告(ATNativeAd)和开屏广告(ATSplashAd),您都必须遵循 完全相同的模式。每个广告对象都需要有自己的 ATAdRevenueListener。
Step 4: Resolve SDK Delegate Conflicts 解决 SDK 代理冲突 #
If you use another service (like Firebase, GameAnalytics, etc.) that also tracks TopOn ad revenue, you might have a conflict. Only one listener can be set. 如果您使用其他也需要追踪 TopOn 广告收益的服务(例如 Firebase, GameAnalytics 等),可能会遇到冲突。一个事件只能设置一个监听器。
- Symptom: Impressions appear correctly in one service but are missing in Tenjin. 症状: 广告展示数据在某个服务中显示正常,但在 Tenjin 中却有缺失。
- 解决方案: Do not set multiple listeners. Instead, find where your other service receives the ATAdInfo object from the onAdRevenuePaid callback. In that same place, add the call to Tenjin to ensure both services receive the data. 解决方案: 不要设置多个监听器。相反,找到您的其他服务接收 onAdRevenuePaid 回调中 ATAdInfo 对象的位置。在同一个地方,添加对 Tenjin 的调用,以确保两个服务都能收到数据。
// Example of resolving a listener conflict
// 解决监听器冲突的示例
public void onAdRevenuePaid(ATAdInfo adInfo) {
// 1. Call for your other service
// 1. 为您的其他服务发起调用
callMyOtherAnalyticsService(adInfo);
// 2. [CRITICAL] Add the call to Tenjin in the same place
// 2. [关键] 在同一个地方添加对 Tenjin 的调用
if (tenjinInstance != null) {
tenjinInstance.eventAdImpressionTopOn(adInfo);
}
}