# (Beta) Hybrid Native Ads

{% hint style="warning" %}
This feature is currently in beta and only supported from version 1.9.0.
{% endhint %}

The RTBHybridNativeAdLoader allows you to create an ad request that can return either a native ad or a banner. It can be treated as a combination of [Native Ads](https://aatkit.gitbook.io/rtbsdk-ios-integration/formats/native-ads) and [Manually Rendered Banner](https://aatkit.gitbook.io/rtbsdk-ios-integration/formats/advanced/separate-loading-and-rendering-of-banner-ads). See the guide below showing how to integrate hybrid native ads into your app.

## Create RTBHybridNativeAdLoader <a href="#create-rtbhybridnativeadloader" id="create-rtbhybridnativeadloader"></a>

To make a hybrid request, first create an instance of `RTBHybridNativeAdLoader`.

```swift
var loader = RTBHybridNativeAdLoader()
loader.delegate = self
```

### Listen to Callbacks

Through the use of `RTBHybridNativeAdLoadDelegate`, you can listen to the different callbacks. Of course, your class must conform to its delegate methods

```swift
loader.delegate = self
```

## Request Ad

To load an ad, you will need to pass an instance of `RTBHybridNativeAdRequestConfiguration` with `placementId`and `iTunesAppId`. Please contact our [support](mailto:support@gravite.net) to get the needed IDs.

```swift
 let configuration = RTBHybridNativeAdRequestConfiguration(placementId: <PLACEMENT_ID>, iTunesAppId: <ITUNES_APP_ID>)
configuration.sellerId = <SELLERID> // Optional
loader.load(configuration: configuration, userAgent: <USER_AGENT>)
```

**Optional - set user targeting**

You can pass user targeting data to each request, allowing ads to be more relevant to your audience. Each field in [RTBUserTargeting](https://ios-sdk-rtb.gravite.net/references/documentation/rtbsdk/rtbusertargeting) is optional.

```swift
let configuration = RTBHybridNativeAdRequestConfiguration(placementId: <PLACEMENT_ID>, iTunesAppId: <ITUNES_APP_ID>)
configuration.userTargeting = RTBUserTargeting(userId: "<USER_ID>", gender: .male, yearOfBirth: 1999, keywords: ["keyword1", "keyword2"])
// yearOfBirth must be a 4-digit number, otherwise, it will be ignored
```

## Handle ad response

As the request can return either banner or native ad, different flows need to be implemented for rendering the ad depending on the callback\\

```swift
extension ViewController: RTBHybridNativeAdLoadDelegate {
    func hybridNativeAdDidReceiveNativeAd(_ nativeAdLoader: RTBSDK.RTBHybridNativeAdLoader, nativeAd: RTBSDK.RTBNativeAd, bidInfo: RTBSDK.RTBBidInfo, networkName: String) {
        // render as native ad
    }

    func hybridNativeAdDidReceiveBannerAd(_ nativeAdLoader: RTBSDK.RTBHybridNativeAdLoader, bannerBid: RTBSDK.RTBBannerBid, networkName: String) {
        // render as banner
    }

    func hybridNativeAdDidFailToReceiveAd(_ nativeAdLoader: RTBSDK.RTBHybridNativeAdLoader, errorMessage: String, networkName: String) {
        //handle failure
    }
}
```

## Handling native ad response

If native ad is received, you can get the needed native ad assets to assemble your view. From now, the flow is just like with rendering [classic native ads](https://aatkit.gitbook.io/rtbsdk-ios-integration/formats/native-ads#retrieve-native-a-d-assets).

## Handling banner response <a href="#handling-banner-response" id="handling-banner-response"></a>

If a banner response is received, you can use the received `RTBBannerBid` to obtain banner view from `RTBBannerAdProvider`, just like with "[Separate Loading and Rendering of Banner Ads](https://aatkit.gitbook.io/rtbsdk-ios-integration/formats/advanced/separate-loading-and-rendering-of-banner-ads#get-loaded-banner-view)" type of integration.
