# Native Ad

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

**Implementation:**

```swift
extension NativeAdManager: MediationAdDelegate {
    func onNativeAdLoaded(nativeAd: AdsFramework.MediationNativeAd) {
        nativeAd.eventDelegate = self
        guard let nibObjects = Bundle.main.loadNibNamed("NativeView", owner: nil, options: nil),
              let adView = nibObjects.first as? MediationNativeAdView else {
            printLog("Could not load nib file for adView")
            return
        }
        (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)
        viewBanner.addSubview(adView)
    }

    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)")
        
    }
}
```

**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")
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ios-docs.adster.tech/ad-types/native-ad.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
