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 SliderAdLoader class to load the ad slider.

  2. Create an AdRequest with the ad unit ID and NativeAdOptions for additional parameters.

  3. Call loadAd(with:options:completion:) to load the ad.

  4. If the ad loads successfully, use the SliderAd object to display it.

  5. If loading fails, handle the error.

let adLoader = SliderAdLoader()
let request = AdRequest(adUnitID: "<AdUnitID>")
let options = NativeAdOptions()

do {
    let sliderAd = try await adLoader.loadAd(with: request, options: options)
    // Display the ad
} catch {
    // Load error
}
let adLoader = SliderAdLoader()
let request = AdRequest(adUnitID: "<AdUnitID>")
let options = NativeAdOptions()

adLoader.loadAd(with: request, options: options) { [weak self] result in
    switch result {
    case .success(let sliderAd):
        // Display the ad
        break
    case .failure:
        break
    }
}

Rendering a native ad slider

After the slider loads, you must render all of its components.

A successfully loaded slider contains one or more related native ads. Ads in the slider must be shown inside a single shared container; otherwise impressions will not be counted.

This approach lets you build the slider layout yourself and place ad components relative to each other. The ad can include both required and optional components. See the full list in Native ad assets.

Tip

For each ad in the slider, we recommend using a layout that includes the full set of possible components. In practice, that tends to improve conversions.

Call bind(with:) on the SliderAd object, passing a container for the slider.

Each ad in the slider is laid out using one of the layout options for standard native ads.

adLoader.loadAd(with: request, options: options) { [weak self] result in
    guard case .success(let sliderAd) = result else { return }

    sliderAd.delegate = self

    // Create a container for the slider; replace NativeAdView with your subclass
    let sliderAdView = NativeAdView()

    do {
        try sliderAd.bind(with: sliderAdView)
    } catch {
        // Check the error message and fix the issue
        return
    }

    for subAd in sliderAd.ads {
        subAd.delegate = self

        // Create an ad view for each ad; replace NativeAdView with your subclass
        let subAdView = NativeAdView()

        do {
            try subAd.bind(with: subAdView)
        } catch {
            return
        }

        // Add the ad to the container and position it
        sliderAdView.addSubview(subAdView)
    }
}