Ad mediation using MoPub

Supported versions of libraries and platforms:

YandexMobileAdsSDK

Minimum supported version: 2.160.

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

AppMetricaSDK

Minimum supported version: 3.8.0.

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

MoPubSDK

Minimum supported version: 5.13.0.

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

Enable an adapter for MoPub mediation

Enable using Gradle

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

implementation 'com.yandex.android:mobileads:2.160'
implementation 'com.yandex.com.yandex.android:mobmetricalib:3.13.1'
implementation 'com.yandex.ads.adapter:mopub-mobileads:0.2.0'
implementation 'com.mopub:mopub-sdk:5.13.0@aar'
Note.

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

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

Setting up mediation in MoPub

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

Creating an Ad Unit

  1. In Apps, select your app and click New ad unit.

  2. Fill in Name, Device, and Format. Configure the Ad Unit settings and save the changes.

  3. Check that you received the Ad Unit ID.

Creating a Custom SDK Network

  1. Go to Networks and click New network.
  2. From the list of possible networks, select Custom SDK network.

Configuring the Custom SDK Network

  1. In Network name, enter a name for the network and click Next.

  2. At the App & Ad Unit setup stage, select your app and the new Ad Unit. Fill in the following fields:

    Custom event class — Specify com.mopub.mobileads.YandexBanner, com.mopub.mobileads.YandexInterstitial, com.mopub.mobileads.YandexRewarded, or com.mopub.nativeads.YandexNative.

    Custom Event Class data — Enter the custom event in JSON format, as shown in the Custom event parameters table.

Creating and configuring an Order

To create it, go to Orders and click Add a New Order. Then make the settings:

  1. Fill in Order Name and Advertiser. For example, you can enter "Yandex order" and "Yandex".
  2. Set up Line Item. In the Network field, select the Custom SDK Network type. Add the following code to the Class field:
    • com.mopub.mobileads.YandexBanner — For banner ads.
    • com.mopub.mobileads.YandexInterstitial — For interstitial ads.
    • com.mopub.mobileads.YandexRewarded — For rewarded ads.
    • com.mopub.nativeads.YandexNative — For native ads.

    In Data, specify the desired parameters (see the Custom event parameters table).

  3. Set up Ad Unit Targeting.

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 MoPub. It 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 MoPub. It 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 MoPub Android SDK

Banner ads
Follow the steps described in the MoPub documentation for banner ads.
Interstitial ads
Follow the steps described in the MoPub documentation for interstitial ads.
Rewarded ads
Follow the steps described in the MoPub documentation for rewarded ads.
Native ads
  1. Follow the steps described in the MoPub documentation for native ads.
  2. Create an object of the YandexViewBinder class that accepts an id set for required and optional views.
    Note.

    For the Media asset, pass the id for Yandex MediaView: com.yandex.mobile.ads.nativeads.MediaView.

  3. Create an object of the YandexNativeAdRenderer class that accepts the YandexViewBinder object as an argument.
  4. Register the created YandexNativeAdRenderer for the MoPubNative object.

    final YandexViewBinder yandexViewBinder = new YandexViewBinder.Builder(R.layout.widget_native_ad_yandex)
            .setAgeId(R.id.age)
            .setBodyId(R.id.body)
            .setCallToActionId(R.id.call_to_action)
            .setDomainId(R.id.domain)
            .setFaviconId(R.id.favicon)
            .setIconId(R.id.icon)
            .setMediaId(R.id.media)
            .setPriceId(R.id.price)
            .setRatingId(R.id.rating)
            .setReviewCountId(R.id.review_count)
            .setSponsoredId(R.id.sponsored)
            .setTitleId(R.id.title)
            .setWarningId(R.id.warning)
            .build();
    
    moPubNative.registerAdRenderer(new YandexNativeAdRenderer(yandexViewBinder));

You can download examples of using ads at the links.