Rewarded Video
This guide shows how to integrate rewarded video ads of RTBSDK into your app.
This guide shows you how to integrate rewarded video ads of RTBSDK into your app.
Create RTBRewardedVideoAd Instance
Create an instance of RTBRewardedVideoAd:
let rewardedVideoAd = RTBRewardedVideoAd()
Listen to Callbacks
Through the use of RTBRewardedVideoAdDelegate
, you can listen to the different callbacks. Of course, your class must conform to its delegate methods (see the complete example below).
rewardedVideoAd.delegate = self
Request Ad
To load a rewarded video ad, you will need to pass an instance of RTBRewardedVideoRequestConfiguration
with placementID
and the iTunesAppId
. Please contact our support for getting the needed IDs.
let configuration = RTBRewardedVideoRequestConfiguration(placementId: <PLACEMENT_ID>, iTunesAppId: "<ITUNES_APP_ID>")
configuration.sellerId = "<SELLERID>"
configuration.bidFloor = <BID_FLOOR>
configuration.muteOnStart = true
rewardedVideoAd.load(configuration: configuration)
You will be notified about the loading success/failure through the RTBRewardedVideoAdDelegate
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 = RTBRewardedVideoRequestConfiguration(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
Show Ad
After the ad gets loaded, it can be presented by calling:
rewardedVideoAd.show(viewController: self)
The currency of
bidFloor
andpriceCPM
parameters is USD.
Complete Code Example
import RTBSDK
class ViewController: UIViewController {
let rewardedVideoAd = RTBRewardedVideoAd()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// [Important] Set rewarded video ad delegate to listen to the callbacks
rewardedVideoAd.delegate = self
// Prepare request configurations
let configuration = RTBRewardedVideoRequestConfiguration(placementId: <PLACEMENT_ID>, iTunesAppId: "<ITUNES_APP_ID>")
configuration.sellerId = "<SELLERID>"
configuration.bidFloor = <BID_FLOOR>
configuration.muteOnStart = true
// Request a rewarded video ad using the placement ID and itunes app ID
rewardedVideoAd.load(configuration: configuration)
}
}
extension ViewController: RTBRewardedVideoAdDelegate {
func rewardedVideoAdDidReceiveAd(_ rewardedVideoAd: RTBSDK.RTBRewardedVideoAd, bidInfo: RTBSDK.RTBBidInfo, networkName: String) {
// A rewarded video ad has been loaded
rewardedVideoAd.show(viewController: self)
}
func rewardedVideoAd(_ rewardedVideoAd: RTBSDK.RTBRewardedVideoAd, didFailToReceiveAd errorMessage: String, networkName: String) {
// Failed to load a rewarded video ad
}
func rewardedVideoAdDidRecordClick(_ rewardedVideoAd: RTBSDK.RTBRewardedVideoAd, networkName: String) {
// The rewarded video ad received a click
}
func rewardedVideoAdDidPauseForAd(_ rewardedVideoAd: RTBSDK.RTBRewardedVideoAd, networkName: String) {
// The app paused for displaying a rewarded video ad
}
func rewardedVideoAdDidResumeAfterAd(_ rewardedVideoAd: RTBSDK.RTBRewardedVideoAd, networkName: String) {
// The app resumed after dismissing a rewarded video ad
}
func rewardedVideoAdDidReceiveReward(_ rewardedVideoAd: RTBSDK.RTBRewardedVideoAd, networkName: String) {
// The has earned a reward
}
}
Last updated