Rewarded Ads
Rewarded ads let you give in-app items for interacting with video ads, playable ads, or surveys. Google's rewarded guides for Android and iOS explain the format.
Treat rewarded ads as a reward flow, not as another non-rewarded interstitial. Call this after initialize and consent. Grant the reward only from the returned result or the Rewarded event, not from Dismissed.
Rewarded video
Use a rewarded ad for a dedicated reward flow.
import {
AdLoadInfo,
AdMob,
AdMobRevenueData,
AdMobRewardItem,
RewardAdOptions,
RewardAdPluginEvents,
} from '@capacitor-community/admob';
await AdMob.addListener(RewardAdPluginEvents.Loaded, (info: AdLoadInfo) => {
console.log('Rewarded ad loaded', info.adUnitId);
});
await AdMob.addListener(RewardAdPluginEvents.FailedToLoad, console.error);
await AdMob.addListener(RewardAdPluginEvents.Rewarded, (reward: AdMobRewardItem) => {
console.log('Reward earned', reward.amount, reward.type);
});
await AdMob.addListener(RewardAdPluginEvents.AdImpression, (data: AdMobRevenueData) => {
console.log(data);
});
const options: RewardAdOptions = {
adId: 'YOUR_AD_UNIT_ID',
// isTesting: true,
// npa: true,
// immersiveMode: true,
// ssv: {
// userId: 'USER_ID',
// customData: JSON.stringify({ placement: 'bonus' }),
// },
};
await AdMob.prepareRewardVideoAd(options);
const rewardItem = await AdMob.showRewardVideoAd();
// Grant the reward once, using this result or the Rewarded event — not both.
console.log(rewardItem);
When no adId is passed to showRewardVideoAd(), the most recently prepared ad is shown.
Prepare more than one ad
await AdMob.prepareRewardVideoAd({ adId: 'ca-app-pub-xxx/reward-1' });
await AdMob.prepareRewardVideoAd({ adId: 'ca-app-pub-xxx/reward-2' });
const reward = await AdMob.showRewardVideoAd({ adId: 'ca-app-pub-xxx/reward-1' });
Rewarded interstitial
Rewarded interstitial ads are incentivized full-screen ads that appear during natural app transitions. Unlike rewarded video, the user does not opt in first. Google's rewarded interstitial guides for Android and iOS explain the format.
Use a rewarded interstitial when the rewarded experience belongs at a natural transition in the app.
import {
AdMob,
AdMobRewardInterstitialItem,
RewardInterstitialAdOptions,
RewardInterstitialAdPluginEvents,
} from '@capacitor-community/admob';
await AdMob.addListener(RewardInterstitialAdPluginEvents.FailedToLoad, console.error);
const options: RewardInterstitialAdOptions = {
adId: 'YOUR_AD_UNIT_ID',
};
const { adUnitId } = await AdMob.prepareRewardInterstitialAd(options);
const rewardItem: AdMobRewardInterstitialItem = await AdMob.showRewardInterstitialAd({
adId: adUnitId,
});
console.log(rewardItem);
Request fields are defined on RewardAdOptions and RewardInterstitialAdOptions. See Testing for isTesting.
Server-side verification
Server-side verification (SSV) lets your backend confirm that a reward was earned. See Google's SSV documentation. Callbacks fire only for production ads; test ads do not invoke your SSV endpoint.
For local validation of the ssv payload, you can send a mock request after RewardAdPluginEvents.Rewarded. Replace ENVIRONMENT_IS_DEVELOPMENT with your own development flag:
const userId = 'USER_ID';
const customData = JSON.stringify({ placement: 'bonus' });
await AdMob.addListener(RewardAdPluginEvents.Rewarded, async () => {
if (!ENVIRONMENT_IS_DEVELOPMENT) {
return;
}
try {
const params = new URLSearchParams({
ad_network: 'TEST',
ad_unit: 'TEST',
custom_data: customData,
reward_amount: 'TEST',
reward_item: 'TEST',
timestamp: 'TEST',
transaction_id: 'TEST',
user_id: userId,
signature: 'TEST',
key_id: 'TEST',
});
await fetch(`https://your-staging-ssv-endpoint?${params.toString()}`);
} catch (err) {
console.error(err);
}
});