Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/admob-plus/admob-plus/llms.txt

Use this file to discover all available pages before exploring further.

import { RewardedAd } from 'admob-plus-cordova'

const rewarded = new RewardedAd({
  adUnitId: 'ca-app-pub-xxx/yyy'
})

await rewarded.load()
await rewarded.show()
RewardedAd displays full-screen ads that reward users for watching video ads. Users can earn in-app rewards like coins, extra lives, or power-ups.

Constructor

options
RewardedAdOptions
required
Configuration options for the rewarded ad

Methods

load()

Loads the rewarded ad. Must be called before showing the ad.
await rewarded.load()
Returns: Promise<void>

show()

Displays the rewarded ad. The ad must be loaded first.
if (await rewarded.isLoaded()) {
  await rewarded.show()
}
Returns: Promise<void>

isLoaded()

Checks if the rewarded ad is loaded and ready to show.
const loaded = await rewarded.isLoaded()
if (loaded) {
  await rewarded.show()
}
Returns: Promise<boolean> - True if the ad is loaded, false otherwise

on()

Registers an event listener for ad events.
const unsubscribe = rewarded.on('reward', (event) => {
  console.log('User earned reward:', event.reward)
})

// Later, to remove the listener:
unsubscribe()
eventName
string
required
Name of the event to listen for. Common events:
  • load - Ad has loaded
  • loadfail - Ad failed to load
  • show - Ad is showing
  • showfail - Ad failed to show
  • dismiss - User dismissed the ad
  • reward - User earned a reward
  • impression - Ad impression recorded
callback
function
required
Function to call when the event occurs
Returns: () => void - Function to remove the event listener

Properties

id
string
The unique identifier for this ad instance
adUnitId
string
The AdMob ad unit ID

Examples

Basic Usage

const rewarded = new RewardedAd({
  adUnitId: 'ca-app-pub-xxx/yyy'
})

await rewarded.load()
await rewarded.show()

With Reward Handling

const rewarded = new RewardedAd({
  adUnitId: 'ca-app-pub-xxx/yyy'
})

rewarded.on('reward', (event) => {
  const { reward } = event
  console.log(`User earned ${reward.amount} ${reward.type}`)
  // Grant the user their reward
  grantCoins(reward.amount)
})

rewarded.on('dismiss', () => {
  console.log('User dismissed the ad')
  // Load the next ad
  rewarded.load()
})

await rewarded.load()
await rewarded.show()

With Server-Side Verification

const rewarded = new RewardedAd({
  adUnitId: 'ca-app-pub-xxx/yyy',
  serverSideVerification: {
    userId: 'user123',
    customData: 'level5_reward'
  }
})

rewarded.on('reward', (event) => {
  // Your server will receive a callback from Google
  // to verify this reward before you grant it
  console.log('Reward event received, awaiting server verification')
})

await rewarded.load()
await rewarded.show()

Complete Flow with Error Handling

const rewarded = new RewardedAd({
  adUnitId: 'ca-app-pub-xxx/yyy'
})

rewarded.on('load', () => {
  console.log('Rewarded ad loaded')
})

rewarded.on('loadfail', (event) => {
  console.error('Failed to load rewarded ad', event.error)
})

rewarded.on('show', () => {
  console.log('Rewarded ad is showing')
})

rewarded.on('showfail', (event) => {
  console.error('Failed to show rewarded ad', event.error)
})

rewarded.on('reward', (event) => {
  const { reward } = event
  console.log(`Rewarding user: ${reward.amount} ${reward.type}`)
  grantReward(reward)
})

rewarded.on('dismiss', () => {
  console.log('User closed the ad')
  rewarded.load() // Preload the next ad
})

try {
  await rewarded.load()
  
  // Show ad when user clicks "Watch Ad" button
  if (await rewarded.isLoaded()) {
    await rewarded.show()
  }
} catch (error) {
  console.error('Error with rewarded ad:', error)
}

Preload Strategy

const rewarded = new RewardedAd({
  adUnitId: 'ca-app-pub-xxx/yyy'
})

// Preload on app start
await rewarded.load()

// Later, when user wants to watch
function showRewardedAd() {
  rewarded.on('dismiss', async () => {
    // Immediately load the next ad after dismissal
    await rewarded.load()
  })
  
  rewarded.on('reward', (event) => {
    grantReward(event.reward)
  })
  
  if (await rewarded.isLoaded()) {
    await rewarded.show()
  } else {
    console.log('Ad not ready, loading now...')
    await rewarded.load()
    await rewarded.show()
  }
}