# Android – AdMob

Source: https://tenjin.com/docs/android-admob/

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:


1. 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](<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).

2. Turn on the setting for impression-level ad revenue in your AdMob account:

1. Sign in to your AdMob account at [https://admob.google.com](<https://admob.google.com>).

2. Click Settings in the sidebar.

3. Click the Account tab.

4. In the Account controls section, turn on the toggle on “Impression-level ad revenue” and click Save.

3. 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 ` setOnPaidEventListener ` method, so you can send impression level revenue data to 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);
    }
}
```


or pass the ad impression data on ` eventAdImpressionAdMob ` method manually.


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)
}
```


The JSON body should follow the format below:


| Parameter | Required? | Example |
| --- | --- | --- |
| ad_unit_id | No | ca-app-pub-3940256099942544%2F2934735716 |
| currency_code | No | USD |
| response_id | No | CKak5t_oovcCFRPJdwodJXQNRw |
| value_micros | Yes | 0.0001 |
| mediation_adapter_class_name | No | GADMAdapterGoogleAdMobAds |
| precision_type | No | Unknown |


reference: [https://developers.google.com/admob/android/impression-level-ad-revenue#implementing_a_paid_event_handler](<https://developers.google.com/admob/android/impression-level-ad-revenue#implementing_a_paid_event_handler>)
