The Tenjin SDK can listen to AdMob impression level revenue data and send revenue events to Tenjin. This integration will send revenue related for each ad impression served from AdMob. Here are the steps to integrate:
- Add the latest version of AdMob SDK to your app-level build.gradle file: https://developers.google.com/admob/android/quick-start#import_the_mobile_ads_sdk
<aside> 💡
Please ensure you have the latest AdMob Android SDK installed (>= 20.5.0).
</aside>
- Turn on the setting for impression-level ad revenue in your AdMob account:
- Sign in to your AdMob account at https://admob.google.com.
- 点击 Settings in the sidebar.
- 点击 Account 标签
- In the Account controls section, next to “Impression-level ad revenue” click to edit.
- Click the toggle to turn on this setting.
- 点击 保存'Save'。.
- Integrate AdMob SDK in your app by following the sample code below. Create an AdRequest object in your activity and load it into the AdView object. Then set the
setOnPaidEventListenermethod, so you can send impression level revenue data to Tenjin SDK.
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);
}
}
or pass the ad impression data on eventAdImpressionAdMob method manually.
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)
}
The JSON body should follow the format below:
| Parameter | Required? | Example |
|---|---|---|
| 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 |