Ad mediation using AdMob
This is an archived version of the documentation. Actual documentation for all platforms can be found here.
Supported versions of libraries and platforms:
Minimum supported version: 5.10.0.
Maximum supported version: 6.0.0 (up to but not including).
Minimum supported version: 22.1.0.
Maximum supported version: 22.2.0 (up to but not including).
Supported ad formats
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:5.10.0' implementation 'com.yandex.ads.adapter:admob-mobileads:5.10.0.0' implementation 'com.google.android.gms:play-services-ads:22.1.0'
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 issue an adUnitId 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
Go to your app section.
In Ad units, choose Add ad unit.
Select the appropriate ad format (the example shows the Rewarded format) and click Select.
Specify a name and configure the Ad Unit settings, then click Create Ad Unit.
Make sure that you received the Ad Unit ID, then click Done.
Setting up mediation
Go to Mediation and click Create Mediation Group.
Select the ad format and app platform for the Ad Unit you created.
Specify the name of the mediation group to create and continue to adding the Ad Unit.
Select your app and the created Ad Unit, and add it.
The added Ad Unit should appear in the Ad Units section. Go to adding a custom event (the Add Custom Event button).
Specify a name, configure eCPM, and click Continue.
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.
Save the changes.
Parameter | Required | Type | Description | Example |
---|---|---|---|---|
adUnitId | Yes | string | The adUnitId issued in the Yandex Partner interface | {"adUnitId": "R-M-XXXXXX"} |
openLinksInApp | No | boolean | Defines how web links will be opened:
| {"adUnitId": "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 | {"adUnitId": "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 | {"adUnitId": "R-M-XXXXXX", "adWidth": 300, "adHeight": 50} |
Parameter | Required | Type | Description | Example |
---|---|---|---|---|
adUnitId | Yes | string | The adUnitId issued in the Yandex Partner interface | {"adUnitId": "R-M-XXXXXX"} |
openLinksInApp | No | boolean | Defines how web links will be opened:
| {"adUnitId": "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 | {"adUnitId": "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 | {"adUnitId": "R-M-XXXXXX", "adWidth": 300, "adHeight": 50} |
Requesting and displaying ads using the Google Mobile Ads Android SDK
- Follow the steps described in the AdMob documentation for native ads.
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 forAGE
,SPONSORED
, andWARNING
. Other IDs are optional.Use the
customEventExtrasBundle
method to pass theYandexNative.class
and theBundle
object (from the previous step) to theAdLoader
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());
Follow the steps described in the AdMob documentation for adaptive banner ads.
Don't pass the adWidth
and adHeight
custom event parameters. In this case, the size specified in AdMob will be used.
You can download examples of using ads at the links.