Tenjin SDK可以获取AdMob的广告展示层级收入数据,并将收入事件发送至Tenjin。这个集成将把每一次AdMob广告展示获得的收入数据发送给Tenjin。以下是集成步骤:
- 将最新版本的 AdMob SDK 添加至您应用级的 build.gradle 文件中: https://developers.google.com/admob/android/quick-start#import_the_mobile_ads_sdk
Please ensure you have the latest AdMob Android SDK installed (>= 20.5.0). - 在您的 AdMob 账户中开启“impression-level ad revenue(展示级广告收入)”相关设置。
- 请在https://admob.google.com登录你的 AdMob 账户:
- 侧边栏点击Settings
- Click the Account tab.
- In the Account controls section, turn on the toggle on “Impression-level ad revenue” and click Save.
- 请参照下方的示例代码,在您的应用中集成 AdMob SDK。
在您的 Activity 中创建一个 AdRequest 对象,并将其加载到 AdView 对象中。
随后设置
setOnPaidEventListener方法,以便您能将展示级收入数据发送至 Tenjin SDK。
Java
public class DemoActivity extends Activity {
private TenjinSDK tenjinInstance;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Initialize Tenjin
tenjinInstance = TenjinSDK.getInstance(this, "<Tenjin API Key>");
// Initialize AdMob
MobileAds.initialize(this, initializationStatus -> initAdMobBanner());
}
private void initAdMobBanner() {
AdView adView = findViewById(R.id.adView);
adView.setOnPaidEventListener(adValue -> {
tenjinInstance.eventAdImpressionAdMob(adValue, adView);
});
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
}
}或者,你可以手动在eventAdImpressionAdMob方法中传递广告展示数据。
Java
rewardedAd.onPaidEventListener = OnPaidEventListener { adValue ->
// Get the ad unit ID
val adUnitId = rewardedAd.adUnitId
val responseInfo = rewardedAd.responseInfo
// Extract the impression-level ad revenue data
val valueMicros = adValue.valueMicros
val currencyCode = adValue.currencyCode
val precisionType = adValue.precisionType
val json = JSONObject()
json.put("ad_unit_id", adUnitId)
json.put("currency_code", currencyCode)
json.put("response_id", responseInfo.responseId)
json.put("value_micros", valueMicros)
json.put("mediation_adapter_class_name", responseInfo.loadedAdapterResponseInfo.adapterClassName)
json.put("precision_type", precisionType)
instance.eventAdImpressionAdMob(json)
}
JSON body应遵循以下格式:
| 参数 | 必需? | 例子 |
|---|---|---|
| ad_unit_id | 否 | ca-app-pub-3940256099942544%2F2934735716 |
| currency_code | 否 | USD |
| response_id | 否 | CKak5t_oovcCFRPJdwodJXQNRw |
| value_micros | 是 | 0.0001 |
| mediation_adapter_class_name | 否 | GADMAdapterGoogleAdMobAds |
| precision_type | 否 | Unknown |