Skip to main content

Rewarded ads

RewardedAd and RewardedInterstitialAd grant a reward when the user finishes the ad. Use rewarded ads for an explicit opt-in ("Watch a video for 50 coins"); rewarded interstitials show at transition points without an opt-in.

Both have the full-screen lifecycle from full-screen ads plus three members:

MemberDescription
rewardThe AdmobReward configured in the AdMob UI: type and amount.
onUserEarnedRewardCalled with the reward when the user earned it.
setServerSideVerificationOptions(options)Data AdMob forwards to your server-side verification callback.

Grant the reward​

import { Admob, RewardedAd } from 'nitro-ui-admob'

const ad = await RewardedAd.load(Admob.testAdUnitId('rewarded'))
showOffer(`Watch a video for ${ad.reward.amount} ${ad.reward.type}`)

ad.onUserEarnedReward = (reward) => grant(reward.amount, reward.type)
ad.show()

Server-side verification​

To verify rewards on your server, set the verification options before show():

ad.setServerSideVerificationOptions({ userId: 'user-42', customData: 'level-3' })
ad.show()

Both fields of AdmobServerSideVerificationOptions are optional. AdMob forwards them to the SSV callback URL configured for the ad unit in the AdMob console.

Rewarded interstitial​

import { Admob, RewardedInterstitialAd } from 'nitro-ui-admob'

const ad = await RewardedInterstitialAd.load(Admob.testAdUnitId('rewardedInterstitial'), {
keywords: ['games'],
})
ad.setServerSideVerificationOptions({ userId: 'user-42' })
ad.onUserEarnedReward = (reward) => grant(reward.amount, reward.type)
ad.show()

Like every callback, onUserEarnedReward is cleared once the ad is dismissed or fails to show.