Ad slider

Native advertising is a type of ad whose layout can be defined at the app level. This feature allows you to change the visual style of ads and their placement, in the context of the app design specifics.

Ad rendering is performed with native platform tools, which enhances ad performance and quality.

Native ads enhance the overall ad experience, so you can show more ads while keeping users engaged. In the long run, this allows you to maximize your advertising revenue.

Prerequisite

  1. Follow the SDK integration steps described under Quick start.
  2. First, you need to initialize the advertising SDK.
  3. Make sure you're using the latest version of the Yandex Mobile Ads SDK, and if you're using mediation, update to the most recent version of the unified build.

Loading the slider

  1. Create an instance of the NativeAdLoader class to receive ads in the slider.

  2. Create a configuration for the nativeAdRequestConfiguration request using the NativeAdRequestConfiguration class. In request parameters, you can pass ad unit ID, image loading method, age, gender attributes, and other data that can make impressions more relevant.

  3. Set a delegate for receiving ads that implements the NativeAdLoaderDelegate protocol.

  4. To track the ad loading process, implement the following methods of the NativeAdLoaderDelegate protocol: -nativeAdLoader:didFailLoadingWithError:, -nativeAdLoader:didLoadAd:.

  5. Send the loadAdWithRequestConfiguration: message to the loader to load the ads.

  6. If the ads are loaded, the following method is called:

    func nativeAdLoader(_ loader: NativeAdLoader, didLoad ad: NativeAd)
    
  7. If the ads failed to load, the following method is called:

    func nativeAdLoader(_ loader: NativeAdLoader, didFailLoadingWithError error: Error)
    
Sample generic ad request
// Creating a loader
adLoader = NativeAdLoader()
adLoader.delegate = self

// Creating a request configuration
let requestConfiguration = NativeAdRequestConfiguration(adUnitID: "<AdUnitID>")

// Passing the request configuration to the loader
adLoader.loadAd(with: requestConfiguration)

// Implementing delegate methods
// ...

func nativeAdLoader(_ loader: NativeAdLoader, didLoad ad: NativeAd) {
    // Render the ad
}

Rendering a native ad slider

Once the slider is loaded, you must render all its assets.

A successfully loaded slider contains one or more native ads having the same context. Ads in the slider must be displayed within the same shared container: otherwise, ad impressions won't count.

Manual setup for the layout of the native ads slider

When the template settings aren't enough to get what you're looking for, you can configure the layout for your native ad slider manually.

With this method, you can arrange the slider for your native ads by positioning ad components relative to each other. The ad may include both required and optional assets for display. For the full list, see Native ad assets.

Tip

For each ad in the slider, we recommend using a layout that includes a complete set of possible assets. In practical terms, such layouts result in higher conversion rates.

Call the bindAdToSliderView method and pass a container for the ad slider to it.

Each ad in the slider is laid out using a standard native advertising layout method.

    func nativeAdLoader(_ loader: NativeAdLoader, didLoad ad: NativeAd) {
        self.ad = ad
        ad.delegate = self
        // Checking for nested ads
        if ad.ads.count != 0 {
            // Creating a container for the slider; replace YMANativeAdView with your descendant of this class
            let sliderAdView = YMANativeAdView()

            // Calling the method bindAd(toSliderView: _) and passing the container to it
            do {
                try ad.bindAd(toSliderView: sliderAdView)
            } catch {
                // Checking the error message and fixing the issue
                return
            }

            for subAd in ad.ads {
                // Subscribing to the delegate
                subAd.delegate = self

                // Create an ad view for the ad 
                // Replace YMANativeAdView with your descendant of this class
                let subAdView = YMANativeAdView()

                // Calling the method bind(with: subAdView) for the ad
                do {
                    try subAd.bind(with: subAdView)
                } catch {
                    // Checking the error message and fixing the issue
                    return
                }

                // Adding the ad to the container
                sliderAdView.addSubview(subAdView)
                // Configuring the ad's placement in the container
            }

        } else {
            // Process as a regular native ad
        }
    }