Native Ads

This guide shows how to integrate native ads of RTBSDK into your app.

circle-info

Native ads are only supported starting versions 1.4.x of the RTB SDK

Create RTBNativeAdLoader

First, create an instance of RTBNativeAdLoaderarrow-up-right and set the delegate using an instance conforming to RTBNativeAdLoaderDelegatearrow-up-right.

var nativeAdLoader: RTBNativeAdLoader? = RTBNativeAdLoader()
nativeAdLoader?.delegate = self

Request Ad

To load an ad, you will need to pass an instance of RTBNativeAdRequestConfigurationarrow-up-right with placementID and the bundleId. Please get in touch with our supportenvelope to get the needed IDs.

let requestConfiguration = RTBNativeAdRequestConfiguration(placementId: <PLACEMENT_ID>, iTunesAppId: "<ITUNES_APP_ID>")
nativeAdLoader?.load(configuration: requestConfiguration)

Request Ad (from background thread)

You can load a native ad from the background thread. To do so, use the other load API load(configuration: RTBNativeAdRequestConfiguration) passing the userAgent string and request configuration.

let requestConfiguration = RTBNativeAdRequestConfiguration(placementId: <PLACEMENT_ID>, iTunesAppId: "<ITUNES_APP_ID>")
nativeAdLoader?.load(configuration: requestConfiguration, 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 RTBUserTargetingarrow-up-right is optional.

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

Retrieve Native Ad Assets

Once the ad is loaded and the method nativeAdDidReceiveAd is called, you can get the needed native ad assets and assemble your view.

(Optional) Use InteractionDelegate

If you are interested in native ad interaction events like clicks, you can pass optional RTBNativeAdInteractionDelegatearrow-up-right to native ad instance

Track Native Ad

To ensure impression reporting and click handling are handled, call trackImpression method on native adarrow-up-right instance, passing the view used for rendering it.

Complete Code Example

Last updated