Rewarded Video

Integrate Rewarded Video ads

This guide shows you how to integrate rewarded video ads of RTBSDK into your app.

Create RTBRewardedVideoAd Instance

Create an instance of RTBRewardedVideoAd:

val rewardedVideo = RTBRewardedVideoAd(this)

Listen to Callbacks

Through the use of RTBRewardedVideoDelegate, you can listen to the different callbacks.

rewardedVideo.delegate = this

Request Ad

To load a rewarded video ad, you will need to pass an instance of RTBRewardedVideoRequestConfiguration with placementID and the bundleId. Please contact our support for getting the needed IDs.

val configuration = RTBRewardedVideoRequestConfiguration(placementId, bundleId)
configuration.sellerId = "<SELLERID>" // Optional
rewardedVideo.load(configuration)

You will be notified about the loading success/failure through the RTBRewardedVideoDelegate .

The video is not muted by default, to change this please set configuration.muteOnStart to true.

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.

configuration.userTargeting = RTBUserTargeting(userID = "<USER_ID>", gender = RTBGender.MALE, keywords = listOf("keyword1", "keyword2"), yearOfBirth = 1990)
// 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:

rewardedVideo?.show(this)

The currency of bidFloor and priceCPM parameters is USD.

Complete Code Example

class MainActivity : AppCompatActivity(), RTBRewardedVideoDelegate {

    private var rewardedVideo: RTBRewardedVideoAd? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        rewardedVideo = RTBRewardedVideoAd(this)

        // Set the interstitial delegate to listen to events
        rewardedVideo?.delegate = this

        // Request a fullscreen ad using the placement ID and bundle ID
        val configuration = RTBRewardedVideoRequestConfiguration(placementId, bundleId)
        configuration.sellerId = "<SELLERID>" // Optional
        rewardedVideo.load(configuration)
    }

    // RTBRewardedVideoDelegate implementation:
    override fun rewardedVideoAdDidReceiveAd(rewardedVideoAd: RTBRewardedVideoAd, bidInfo: RTBBidInfo, networkName: String) {
        // An ad has been loaded
        // Show the ad:
        rewardedVideo.show(this)
    }

    override fun rewardedVideoAdDidFailToReceiveAd(rewardedVideoAd: RTBRewardedVideoAd, errorMessage: String, networkName: String) {
        // Failed to load an ad
    }

    override fun rewardedVideoAdDidRecordClick(rewardedVideoAd: RTBRewardedVideoAd, networkName: String) {
        // The ad received a click
    }

    override fun rewardedVideoAdDidPauseForAd(rewardedVideoAd: RTBRewardedVideoAd, networkName: String) {
        // The app paused for displaying a fullscreen ad
    }

    override fun rewardedVideoAdDidResumeAfterAd(rewardedVideoAd: RTBRewardedVideoAd, networkName: String) {
        // The app resumed after dismissing a fullscreen ad
    }
    
    override fun rewardedVideoAdDidReceiveReward(rewardedVideoAd: RTBRewardedVideoAd, networkName: String) {
        // Reward received for watching the video ad
    }

}

Last updated