Native Ads
This guide shows how to integrate native ads of RTBSDK into your app.
Create RTBNativeAdLoader
First, create an instance of RTBNativeAdLoader and set the delegate using an instance conforming to RTBNativeAdLoaderDelegate.
var nativeAdLoader: RTBNativeAdLoader? = RTBNativeAdLoader()
nativeAdLoader?.delegate = selfRequest Ad
To load an ad, you will need to pass an instance of RTBNativeAdRequestConfiguration with placementID and the bundleId. Please get in touch with our support 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 RTBUserTargeting 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 ignoredRetrieve 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 RTBNativeAdInteractionDelegate to native ad instance
Track Native Ad
To ensure impression reporting and click handling are handled, call trackImpression method on native ad instance, passing the view used for rendering it.
Complete Code Example
Last updated