Ad mediation using MoPub

Supported versions of libraries and platforms:

YandexMobileAdsSDK

Minimum supported version: 2.15.4.

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

MoPubSDK

Minimum supported version: 5.12.1.

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

iOS

Minimum supported version: 8.0.

Adding adapters to an app

Note.

Before connecting an adapter, you need to integrate the Yandex Mobile Ads SDK. Otherwise, loading an ad will result in an error.

The YandexMobileAdsMoPubAdapters library has been adapted to work with the CocoaPods dependency management system and supports two integration methods: static and dynamic. Select the same integration method for the adapters that was used when connecting the YandexMobileAds SDK.

To connect the library, add the dependency to the project's Podfile:

pod 'YandexMobileAdsMoPubAdapters', '0.8.0'
If you don't use CocoaPods
  1. Download and add the adapters framework (YandexMobileAdsMoPubAdapters.framework) to the project.
  2. Make changes to the Build Settings file:

    In Framework Search Paths, add the path to the directory containing the framework.

Setting up mediation in MoPub

Get a Block ID in the Yandex Partner interface for each Ad Unit created in MoPub. Then set up mediation in the MoPub web interface:

Creating an Ad Unit

  1. In the Apps section, 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 YMABannerCustomEvent, YMAInterstitialCustomEvent, YMARewardedCustomEvent, or YMANativeCustomEvent.

    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 an order, go to the Orders section and click Create 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, noting the following settings:

    Network — Select Custom Native Network.

    Class — Specify YMABannerCustomEvent, YMAInterstitialCustomEvent, YMARewardedCustomEvent, or YMANativeCustomEvent.

    Data — Specify the desired parameters (see the “Custom event parameters” table).

  3. Select Start Immediately and the Line will start working immediately.

  4. Select the Ad Unit you created and click Next.
  5. Adjust Audience targeting and save your 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 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 native ads using the MoPub iOS 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 MPStaticNativeAdRendererSettings class. Set the UIView subclass as the renderingViewClass that will render elements of native ads. In the UIView subclass that is used to display native ads, implement the YMANativeCustomEventAdRendering protocol.

    MPStaticNativeAdRendererSettings *settings = [[MPStaticNativeAdRendererSettings alloc] init];
    settings.renderingViewClass = [NativeAdView class];
    Note.

    Methods of the nativeAgeLabel, nativeSponsoredLabel, and nativeWarningLabel protocols must return UIView objects that will be displayed if their text is not nil.

  3. When requesting ads via MPNativeAdRequest, add the Yandex Mobile Ads SDK configuration obtained using the YMANativeCustomEventAdRenderer class. Pass the settings created in the previous step as settings.

      MPNativeAdRendererConfiguration *commonConfig =
            [MPStaticNativeAdRenderer rendererConfigurationWithRendererSettings:settings];
      MPNativeAdRendererConfiguration *yandexConfig =
            [YMANativeCustomEventAdRenderer rendererConfigurationWithRendererSettings:settings];
      MPNativeAdRequest *adRequest = [MPNativeAdRequest requestWithAdUnitIdentifier:@"your_identifier"
                                                               rendererConfigurations:@[ commonConfig, yandexConfig ]];
    Note.

    Pass an object of the MPStaticNativeAdRendererSettings class to the [YMANativeCustomEventAdRenderer rendererConfigurationWithRendererSettings:] method.

You can download examples of using ads at the links.

Objective-C