---
metadata:
  - name: generator
    content: Diplodoc Platform v5.57.3
alternate:
  - https://boost.yandex.com/doc/en/ad-monetization/dev/android/slider.md
  - https://boost.yandex.com/doc/ru/ad-monetization/dev/android/slider.md
  - href: en/ad-monetization/dev/android/slider.md
    type: text/markdown
    title: Markdown version
  - href: llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://boost.yandex.com/doc/en/llms.txt

# Ad slider

<!-- source: en/ad-monetization/dev/_includes/native-ads.md -->
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.
<!-- endsource: en/ad-monetization/dev/_includes/native-ads.md -->

<!-- source: en/ad-monetization/dev/_includes/native-ads.md -->
Ad rendering is performed with native platform tools, which enhances ad performance and quality.
<!-- endsource: en/ad-monetization/dev/_includes/native-ads.md -->

<!-- source: en/ad-monetization/dev/_includes/native-ads.md -->
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.
<!-- endsource: en/ad-monetization/dev/_includes/native-ads.md -->

## Prerequisite {#pre}

<!-- source: en/ad-monetization/dev/_includes/pre-android.md -->
1. Follow the SDK integration steps described under [Quick start](https://boost.yandex.com/doc/en/ad-monetization/dev/android/quick-start.md).
2. First, you need to [initialize](https://boost.yandex.com/doc/en/ad-monetization/dev/android/quick-start.md#init) the advertising SDK.
3. Make sure you have the [latest Yandex Mobile Ads SDK version](https://boost.yandex.com/doc/en/ad-monetization/dev/android/changelog-android.md). If you're using mediation, update to the most recent [single build version](https://boost.yandex.com/doc/en/ad-monetization/dev/android/changelog-android.md).
<!-- endsource: en/ad-monetization/dev/_includes/pre-android.md -->

## Implementation {#implement}

Key steps for integrating native ads (slider):

* Create and configure the `SliderAdLoader` ad loader.
* Register the ad loader event listener: `SliderAdLoadListener`.
* Load the ad.
* Render the loaded ad.

## Specifics of native ad integration {#features}

1. All calls to Yandex Mobile Ads SDK methods must be made from the main thread.

2. If the `onAdFailedToLoad()` callback returns an error, don't try to load a new ad again. If there's no other option, limit the number of ad load retries. This will help avoid constant unsuccessful requests and connection issues if there are limitations.

3. We recommend keeping a strong reference to the `SliderAd` ad object and its loader `SliderAdLoader` throughout the lifecycle of the screen hosting interaction with the ad.

4. Once the slider is loaded, you must render all its assets. You can get the list of assets available in the ad from the `SliderAd` object.

5. The slider contains a set of ads, each of which needs to be displayed.

6. Each ad within the slider contains a set of assets. You can get the list of available ad assets from the `NativeAd` advertising object. All required ad assets need to be rendered. You can find a description of ad assets on the [Native ad assets](https://boost.yandex.com/doc/en/ad-monetization/dev/android/components.md) page.

7. The size of the ad container should be based on the ad content.

8. Ads in the slider must be displayed within the same shared container: otherwise, ad impressions won't count.

9. Video ads usually yield the best results. To display video ads, the size of the ad container and the `MediaView` component must be at least 300 × 160 dp (density-independent pixels).

10. We recommend using a layout that includes all the possible components. In practical terms, such layouts result in higher conversion rates.

## Loading the slider {#load}

To load the native ad slider, create a `SliderAdLoader` object.

The ad request parameters are configured via the `AdRequest.Builder` class object. You can improve ad relevance by passing parameters such as the ad unit ID, image loading method, and other relevant data as request parameters.

To receive notifications about ad loading results, create a `SliderAdLoadListener` instance and pass it to the `loadSlider()` method.

To load the ad, call the `loadAd()` method.

The example below shows how to load native ads from Activity:

{% list tabs %}

- Kotlin
  ```kotlin
  class SliderNativeAdActivity : AppCompatActivity(R.layout.activity_slider_native_ad) {

      private val nativeAdView get() = binding.nativeAd.root

      private var sliderAdLoader: SliderAdLoader? = null

      private lateinit var binding: ActivityCustomNativeAdBinding

      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          binding = ActivityCustomNativeAdBinding.inflate(layoutInflater)
          setContentView(binding.root)

          sliderAdLoader = SliderAdLoader(this)
          sliderAdLoader?.loadSlider(
              // Methods in the AdRequest.Builder class can be used here to specify individual options settings.
              AdRequest.Builder("your-ad-unit-id").build(),
              object : SliderAdLoadListener {
                  override fun onSliderAdLoaded(p0: SliderAd) {
                      // The slider ad was loaded successfully. Now you can show loaded ads.
                  }

                  override fun onSliderAdFailedToLoad(p0: AdRequestError) {
                      // Ad failed to load with AdRequestError.
                      // Attempting to load a new ad from the onAdFailedToLoad() method is strongly discouraged.
                  }
              })
      }
  }
  ```
- Java
  ```java
  class CustomSliderNativeAdActivity extends AppCompatActivity {
      private NativeAdView mNativeAdView = mBinding.nativeAd.getRoot();

      @Nullable
      private SliderAdLoader mSliderAdLoader = null;

      private ActivityCustomNativeAdBinding mBinding;

      @Override
      public void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          mBinding = ActivityCustomNativeAdBinding.inflate(getLayoutInflater());
          setContentView(mBinding.getRoot());

          mSliderAdLoader = new SliderAdLoader(this);
          // Methods in the AdRequest.Builder class can be used here to specify individual options settings.
          mSliderAdLoader.loadSlider(
                  new AdRequest.Builder("your-ad-unit-id").build(),
                  new SliderAdLoadListener() {
                      @Override
                      public void onSliderAdLoaded(@NonNull SliderAd sliderAd) {
                          // The slider ad was loaded successfully. Now you can show loaded ads.
                      }

                      @Override
                      public void onSliderAdFailedToLoad(@NonNull final AdRequestError error) {
                          // Ad failed to load with AdRequestError.
                          // Attempting to load a new ad from the onAdFailedToLoad() method is strongly discouraged.
                      }
                  }
          );
      }
  }
  ```

{% endlist %}

## Rendering a native ad slider {#ad-view}

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 {#config}

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](https://boost.yandex.com/doc/en/ad-monetization/dev/android/components.md).

{% note 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.

{% endnote %}

Link the `SliderAd` object to the root `NativeAdView` object and link each ad in the slider to the child `NativeAdView` object.

Each ad in the slider is laid out using a standard native advertising [layout method](https://boost.yandex.com/doc/en/ad-monetization/dev/android/native.md#ad-view).

{% cut "Sample code" %}

   {% list tabs %}

   - Kotlin

     ```kotlin
     private fun showAd(sliderAd: SliderAd) {
         val sliderViewBinder = NativeAdViewBinder.Builder(sliderAdView).build()
         when (val sliderResult = sliderAd.bindSliderAd(sliderViewBinder)) {
             is AdBindingResult.Failure -> {
                 //log error
             }
             AdBindingResult.Success -> {
                 val nativeAds = sliderAd.nativeAds
                 for (nativeAd in nativeAds) {
                     val nativeAdView: NativeAdView =
                         mLayoutInflater.inflate(R.layout.widget_native_ad, sliderAdView, false)
                     val viewBinder = NativeAdViewBinder.Builder(nativeAdView)
                         .setAgeView(age)
                         .setBodyView(body)
                         .setCallToActionView(callToAction)
                         .setDomainView(domain)
                         .setFaviconView(favicon)
                         .setFeedbackView(feedback)
                         .setIconView(icon)
                         .setMediaView(media)
                         .setPriceView(price)
                         .setRatingView(rating)
                         .setReviewCountView(reviewCount)
                         .setSponsoredView(sponsored)
                         .setTitleView(title)
                         .setWarningView(warning)
                         .build()
                     nativeAd.bindNativeAd(viewBinder)
                     sliderAdView.addView(nativeAdView)
                 }
             }
         }
     }
     ```

   - Java

     ```java
     private void showAd(@NonNull final SliderAd sliderAd) {
         final NativeAdViewBinder sliderViewBinder = new NativeAdViewBinder.Builder(mSliderAdView).build();
         AdBindingResult sliderResult = sliderAd.bindSliderAd(sliderViewBinder);
         if (sliderResult instanceof AdBindingResult.Failure) {
             //log error
             return;
         }
         final List<NativeAd> nativeAds = sliderAd.getNativeAds();
         for (final NativeAd nativeAd : nativeAds) {
             final NativeAdView nativeAdView = mLayoutInflater.inflate(R.layout.widget_native_ad, mSliderAdView, false);
             final NativeAdViewBinder viewBinder = new NativeAdViewBinder.Builder(nativeAdView)
                     .setAgeView(age)
                     .setBodyView(body)
                     .setCallToActionView(callToAction)
                     .setDomainView(domain)
                     .setFaviconView(favicon)
                     .setFeedbackView(feedback)
                     .setIconView(icon)
                     .setMediaView(media)
                     .setPriceView(price)
                     .setRatingView(rating)
                     .setReviewCountView(reviewCount)
                     .setSponsoredView(sponsored)
                     .setTitleView(title)
                     .setWarningView(warning)
                     .build();
             nativeAd.bindNativeAd(viewBinder);
             mSliderAdView.addView(nativeAdView);
         }
     }

     ```

   {% endlist %}

{% endcut %}

## Testing the integration of the native ad slider {#test}

### Using demo ad units for ad testing {#demo-blocks}

We recommend using test ads to test your native ad slider integration and your app itself.

To guarantee that test ads are returned for every slider request, we created a special demo ad placement ID. designed to help you test your ad integration.

Demo adUnitId for the native ad slider: `demo-native-slider-yandex`.

{% note warning %}

Before publishing your app in the store, make sure to replace the demo placement ID with the real ID you obtained in the interface Boost.

{% endnote %}

<!-- Список всех доступных демонстрационных идентификаторов рекламного места доступен в разделе [Тестовые объявления](ссылка). -->

### Testing ad integration {#test-int}

You can check your native ad slider integration using the SDK's built-in analyzer.

The tool makes sure the slider is integrated properly and outputs a detailed report to the log.
To view the report, search the keyword `YandexAds` in [Logcat](https://developer.android.com/studio/command-line/logcat), a tool for debugging Android apps.

```bash
adb logcat -v brief '*:S YandexAds'
```

If the integration is successful, the following message is returned:
```bash
adb logcat -v brief '*:S YandexAds'
mobileads$ adb logcat -v brief '*:S YandexAds'
I/YandexAds(13719): [Integration] Slider native ad was integrated successfully
```

If you're having problems integrating your native ad slider, you'll get a detailed report on the issues and recommendations for how to fix them.
