Ad slider

Native advertising is an ad type where the layout can be defined on the app side. This feature allows you to change the visual style of ads and their placement, considering the app design specifics.

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

Native ads enhance the ad experience. As a result, you can display more ads without losing user interest. This ensures maximum revenue from advertising in the long run.

Prerequisite

  1. Follow the SDK integration steps described in Quick start.
  2. Initialize your ad SDK in advance.
  3. Make sure you're running the latest Yandex Mobile Ads SDK version. If you're using mediation, make sure you're also running the latest version of the unified build.

Loading the slider

  1. Create an instance of the NativeAdLoader class to gets ads within the slider.

  2. Create a nativeAdRequestConfiguration using the NativeAdRequestConfiguration class. As the request parameters, you can use the ad unit ID, method for loading images, age, gender, and other data that might improve the quality of ad selection.

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

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

  5. To load the ad, send the loadAdWithRequestConfiguration: message to the loader.

  6. If the ad loaded, the following method is called:

    func nativeAdLoader(_ loader: NativeAdLoader, didLoad ad: NativeAd)
    
  7. If the ad didn't load, the following method is called:

    func nativeAdLoader(_ loader: NativeAdLoader, didFailLoadingWithError error: Error)
    
Example of a general 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 ad 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. Your ad may contain both mandatory and optional display assets. You can find their full list in Native ad assets.

Tip

For each ad in the slider, we recommend using a layout that includes a complete set of possible assets. Experience has shown that layouts with a complete set of assets are more clickable.

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
        }
    }