Ad mediation using AdMob

Supported versions of libraries and platforms:

YandexMobileAdsSDK

Minimum supported version: 2.112.

Maximum supported version: 3.0 (up to but not including).

AppMetricaSDK

Minimum supported version: 3.6.4.

Maximum supported version: 4.0.0 (up to but not including).

GoogleMobileAdsSDK

Minimum supported version: 18.3.0.

Maximum supported version: 18.4.0 (up to but not including).

Enabling an adapter for AdMob mediation

Enable using Gradle

Add the following dependencies to the build.gradle file at the application level:

implementation 'com.yandex.android:mobileads:2.112'
implementation 'com.yandex.android:mobmetricalib:3.8.0'
implementation 'com.yandex.ads.adapter:admob-mobileads:0.2.0'
implementation 'com.google.android.gms:play-services-ads:18.3.0@aar'
Note.

If your project uses proguard, you must add the following lines in the proguard.cfg file:

-keep class com.admob.mobileads.** {
    *;
}

Setting up mediation in AdMob

You need to get a Block ID in the Yandex Partner interface for each Ad Unit created in AdMob. Then you need to set up mediation in the AdMob web interface:

Creating an Ad Unit

  1. Go to your app section.

  2. In Ad units, choose Add ad unit.

  3. Select the appropriate ad format (the example shows the Rewarded format) and click Select.

  4. Specify a name and configure the Ad Unit settings, then click Create Ad Unit.

  5. Make sure that you received the Ad Unit ID, then click Done.

Setting up mediation

  1. Go to Mediation and click Create Mediation Group.

  2. Select the ad format and app platform for the Ad Unit you created.

  3. Specify the name of the mediation group to create and continue to adding the Ad Unit.

  4. Select your app and the created Ad Unit, and add it.

  5. The added Ad Unit should appear in the Ad Units section. Go to adding a custom event (the Add Custom Event button).

  6. Specify a name, configure eCPM, and click Continue.

  7. Add a custom event and fill in the following fields:

    Class Name — Specify com.admob.mobileads.YandexBanner, com.admob.mobileads.YandexInterstitial, com.admob.mobileads.YandexRewarded, or com.admob.mobileads.YandexNative.

    Parameter — Enter the custom event in JSON format, as shown in the Custom event parameters table.

  8. Save the changes.

Custom event parameters
Parameter Required Type Description Example
blockID Yes string The Block ID issued in the Yandex Partner interface {"blockID": "R-M-XXXXXX"}
openLinksInApp No boolean

Defines how web links will be opened:

  • true — Web links open in the app.
  • false or omitted — Web links open in the browser.
{"blockID": "R-M-XXXXXX", "openLinksInApp": true}
adWidth No number Width of the banner. Can be used for passing a size that isn't supported by AdMob. Must match the banner size chosen in the Yandex Partner interface {"blockID": "R-M-XXXXXX", "adWidth": 300, "adHeight": 50}
adHeight No number Height of the banner. Can be used for passing a size that isn't supported by AdMob. Must match the banner size chosen in the Yandex Partner interface {"blockID": "R-M-XXXXXX", "adWidth": 300, "adHeight": 50}

Requesting and displaying ads using the Google Mobile Ads Android SDK

Banner ads
Follow the steps described in the AdMob documentation for banner ads.
Interstitial ads
Follow the steps described in the AdMob documentation for interstitial ads.
Rewarded ads
Follow the steps described in the AdMob documentation for rewarded ads.
Native ads
  1. Follow the steps described in the AdMob documentation for native ads.
  2. Create an object of the Bundle class. Add a key-value pair to it: set a constant from the YandexNativeAdAsset class as the key and the ID of the corresponding view as the value.

    Note.

    You must pass to the Bundle the view IDs for AGE, SPONSORED, and WARNING. Other IDs are optional.

  3. Use the customEventExtrasBundle method to pass the YandexNative.class and the Bundle object (from the previous step) to the AdLoader request.

    final Bundle extras = new Bundle();
    extras.putInt(YandexNativeAdAsset.AGE, R.id.age);
    extras.putInt(YandexNativeAdAsset.DOMAIN, R.id.domain);
    extras.putInt(YandexNativeAdAsset.FAVICON, R.id.favicon);
    extras.putInt(YandexNativeAdAsset.FEEDBACK, R.id.feedback);
    extras.putInt(YandexNativeAdAsset.RATING, R.id.domain);
    extras.putInt(YandexNativeAdAsset.REVIEW_COUNT, R.id.review_count);
    extras.putInt(YandexNativeAdAsset.SPONSORED, R.id.sponsored);
    extras.putInt(YandexNativeAdAsset.WARNING, R.id.warning);
    
    adLoader.loadAd(new AdRequest.Builder()
            .addCustomEventExtrasBundle(YandexNative.class, extras)
            .build());

You can download examples of using ads at the links.