> For the complete documentation index, see [llms.txt](https://ios-docs.adster.tech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ios-docs.adster.tech/multiple-ads/carousel-native-ad.md). Agents can also search and read this documentation through its [MCP server](https://ios-docs.adster.tech/~gitbook/mcp).

# Carousel Native Ad

To receive multiple Native Ads, conform to the `MediationAdDelegate` protocol. Once the ad is loaded, you can populate your native ad view with the ad's data.

AdSter native and custom native carousel items support video. Configure each child ad's optional `videoController` and attach its SDK media view; see [Native Ad video controls](https://ios-docs.adster.tech/ad-types/native-ad). Set `scaleMode = .aspectFit` to show the whole video and retain a listener per item when using custom controls. Keep automatic visibility handling enabled for scrolling, and destroy ads when permanently removed.

**Implementation:**

```swift
extension NativeAdManager: MediationAdDelegate {
    func onCarouselNativeAdLoaded(carouselNativeAd: AdsFramework.MediationCarouselNativeAd) {
        guard !carouselNativeAd.ads.isEmpty else {
            print("Carousel Native Ad request failed with reason no native ads")
            return
        }

        addCarouselNativeAdsToView(carouselNativeAd.ads)
    }

    func onAdFailedToLoad(error: AdError) {
        print("Native Ad request failed with reason \(error.description)")
    }
    
    func onAdRevenuePaid(revenue: Double, adUnitId: String, network: String, currency: String, precisionType: AdsFramework.PrecisionType) {
        print("Revenue: \(revenue) \(currency), adUnitId: \(adUnitId), network: \(network), precision: \(precisionType)")
        
    }
}
```

**Example carousel rendering:**

```swift
private func addCarouselNativeAdsToView(_ nativeAds: [AdsFramework.MediationNativeAd]) {
    carouselStackView.arrangedSubviews.forEach { view in
        carouselStackView.removeArrangedSubview(view)
        view.removeFromSuperview()
    }

    for nativeAd in nativeAds {
        nativeAd.eventDelegate = self

        guard let nibObjects = Bundle.main.loadNibNamed("NativeView", owner: nil, options: nil),
              let adView = nibObjects.first as? MediationNativeAdView else {
            print("Could not load nib file for adView")
            continue
        }

        populateNativeAdView(adView, with: nativeAd)

        let slideView = UIView()
        slideView.translatesAutoresizingMaskIntoConstraints = false

        adView.translatesAutoresizingMaskIntoConstraints = false
        slideView.addSubview(adView)

        NSLayoutConstraint.activate([
            adView.leadingAnchor.constraint(equalTo: slideView.leadingAnchor),
            adView.trailingAnchor.constraint(equalTo: slideView.trailingAnchor),
            adView.topAnchor.constraint(equalTo: slideView.topAnchor),
            adView.bottomAnchor.constraint(equalTo: slideView.bottomAnchor),

            slideView.widthAnchor.constraint(equalTo: carouselScrollView.frameLayoutGuide.widthAnchor),
            slideView.heightAnchor.constraint(equalTo: carouselScrollView.frameLayoutGuide.heightAnchor)
        ])

        carouselStackView.addArrangedSubview(slideView)
    }

    pageControl.numberOfPages = nativeAds.count
    pageControl.currentPage = 0
}
```

**Helper method:**

```swift
private func populateNativeAdView(
    _ adView: MediationNativeAdView,
    with nativeAd: AdsFramework.MediationNativeAd
) {
    (adView.bodyView as? UILabel)?.text = nativeAd.body
    (adView.headlineView as? UILabel)?.text = nativeAd.headline
    (adView.ctaView as? UIButton)?.setTitle(nativeAd.callToAction, for: .normal)
    (adView.ctaView as? UIButton)?.isUserInteractionEnabled = false

    if let mediaView = nativeAd.mediaView {
        addMediaViewToParentView(childView: mediaView, parentView: adView.mediaView)
    }

    adView.setNativeAd(nativeAd: nativeAd)
}
```

**Tracking Events:**

To track impression and click events for Native Ads, conform to `MediationNativeAdEventDelegate`:

```swift
extension NativeAdManager: MediationNativeAdEventDelegate {
    func recordNativeClick() {
        print("Native ad clicked")
    }
    
    func recordNativeImpression() {
        print("Native ad impression recorded")
    }
}
```

{% hint style="info" %}
Carousel Native Ads return multiple native ads in `carouselNativeAd.ads`. \
Each item is a `MediationNativeAd`, so create one `MediationNativeAdView` for each ad, populate it with the ad data, call `setNativeAd(nativeAd:)`, and assign `eventDelegate` for click and impression tracking.
{% endhint %}
