Skip to content

Repository files navigation


AdMob

@capacitor-community/admob

Capacitor community plugin for native AdMob.

Read the full documentation


Maintainers

Maintainer GitHub Social
Masahiko Sakakibara rdlabo @rdlabo
Saninn Salas Diaz Saninn Salas Diaz @SaninnSalas

Maintenance Status: Actively Maintained

Contributors ✨

Made with contributors-img.

Demo

Demo code is here.

Screenshots

Banner Interstitial Reward App Open
iOS
Android

Installation

If you use Capacitor 7:

% npm install --save @capacitor-community/admob@7
% npx cap update

Google Mobile Ads SDK compatibility

To preserve behavior for users of the current major version, this plugin continues to use Google Mobile Ads SDK APIs that are deprecated but still supported. Replacing those APIs can change banner sizing and age-restricted treatment behavior, so that migration is deferred until the next major release.

Migration to the GMA Next-Gen SDK for Android is also deferred until the next major release because it requires breaking changes to SDK initialization, ad requests, and mediation integration.

Android continues to use GMA SDK (Legacy) 25.4.x. On iOS, both Swift Package Manager and CocoaPods are fixed to GMA SDK 13.6.0 until CocoaPods support is removed in the next major release.

Android configuration

In file android/app/src/main/AndroidManifest.xml, add the following XML elements under <manifest><application> :

<meta-data
 android:name="com.google.android.gms.ads.APPLICATION_ID"
 android:value="@string/admob_app_id"/>

In file android/app/src/main/res/values/strings.xml add the following lines :

<string name="admob_app_id">[APP_ID]</string>

Don't forget to replace [APP_ID] by your AdMob application Id.

Variables

This plugin will use the following project variables (defined in your app's variables.gradle file):

  • playServicesAdsVersion version of com.google.android.gms:play-services-ads (default: 25.4.+)
  • androidxCoreKTXVersion: version of androidx.core:core-ktx (default: 1.15.0)

iOS configuration

Add the following in the ios/App/App/info.plist file inside of the outermost <dict>:

<key>GADIsAdManagerApp</key>
<true/>
<key>GADApplicationIdentifier</key>
<string>[APP_ID]</string>
<key>SKAdNetworkItems</key>
<array>
  <dict>
    <key>SKAdNetworkIdentifier</key>
    <string>cstr6suwn9.skadnetwork</string>
  </dict>
</array>
<key>NSUserTrackingUsageDescription</key>
<string>[Why you use NSUserTracking. ex: This identifier will be used to deliver personalized ads to you.]</string>

Don't forget to replace [APP_ID] by your AdMob application Id.

Tutorial

Complete the common initialization and consent setup once before loading ads. Then follow the tutorial for each ad format you use.

Common setup

Initialize AdMob

import { AdMob, AdmobConsentStatus } from '@capacitor-community/admob';

export async function initialize(): Promise<void> {
  await AdMob.initialize();

  const [trackingInfo, consentInfo] = await Promise.all([
    AdMob.trackingAuthorizationStatus(),
    AdMob.requestConsentInfo(),
  ]);

  if (trackingInfo.status === 'notDetermined') {
    /**
     * If you want to explain TrackingAuthorization before showing the iOS dialog,
     * you can show the modal here.
     * ex)
     * const modal = await this.modalCtrl.create({
     *   component: RequestTrackingPage,
     * });
     * await modal.present();
     * await modal.onDidDismiss();  // Wait for close modal
     **/

    await AdMob.requestTrackingAuthorization();
  }

  const authorizationStatus = await AdMob.trackingAuthorizationStatus();
  if (
    authorizationStatus.status === 'authorized' &&
    consentInfo.isConsentFormAvailable &&
    consentInfo.status === AdmobConsentStatus.REQUIRED
  ) {
    await AdMob.showConsentForm();
  }
}

Send an array of device Ids in testingDevices to use production like ads on your specified devices -> https://developers.google.com/admob/android/test-ads#enable_test_devices

User Message Platform (UMP)

To use UMP, you must create your GDPR messages.

You may need to setup IDFA messages, it will work along with GDPR messages and will show when users are not in EEA and UK.

Example of how to use UMP.

import { AdMob } from '@capacitor-community/admob';

private canShowAds: boolean | null = null;

async showConsent() {
  let consentInfo = await AdMob.requestConsentInfo();
  if (!consentInfo.canRequestAds) {
    consentInfo = await AdMob.showConsentForm();
    this.canShowAds = consentInfo.canRequestAds;
  }
}

To let users manage their privacy options at any time, show the privacy options form.

import { AdMob } from '@capacitor-community/admob';

showPrivacyOptionsForm() {
    AdMob.showPrivacyOptionsForm();
}

If you testing on real device, you have to set debugGeography and add your device ID to testDeviceIdentifiers. You can find your device ID with logcat (Android) or XCode (iOS).

import { AdMob, AdmobConsentDebugGeography } from '@capacitor-community/admob';

const consentInfo = await AdMob.requestConsentInfo({
  debugGeography: AdmobConsentDebugGeography.EEA,
  testDeviceIdentifiers: ['YOUR_DEVICE_ID'],
});

Note: When testing, if you choose not consent (Manage -> Confirm Choices). The ads may not load/show. Even on testing enviroment. This is normal. It will work on Production so don't worry.

Before requesting an ad, complete these steps in order:

  1. Call AdMob.initialize().
  2. Call AdMob.requestConsentInfo().
  3. If required, call AdMob.showConsentForm().
  4. Load or show the ad format you need.

Choose by advertising goal

Register event listeners before loading or showing an ad so that the first lifecycle and impression events are not missed.

Goal Ad format
Monetize an app-open experience App Open
Keep an ad visible alongside app content Banner
Show a full-screen ad at a natural break without granting a reward Interstitial
Offer a dedicated rewarded experience Rewarded
Offer a reward at a natural transition Rewarded Interstitial

Monetize an app-open experience

Use an App Open ad when the app starts or returns to the foreground.

import {
  AdMob,
  AppOpenAdPluginEvents,
  AppOpenAdOptions,
  AdLoadInfo,
  AdMobRevenueData,
} from '@capacitor-community/admob';

export async function showAppOpenAd(): Promise<void> {
  // listen to events
  AdMob.addListener(AppOpenAdPluginEvents.Loaded, (info: AdLoadInfo) => {
    console.log('App Open Ad loaded', info.adUnitId);
  });
  AdMob.addListener(AppOpenAdPluginEvents.FailedToLoad, (error) => {
    console.log('Failed to load App Open Ad', error);
  });
  AdMob.addListener(AppOpenAdPluginEvents.Opened, () => {
    console.log('App Open Ad open');
  });
  AdMob.addListener(AppOpenAdPluginEvents.Closed, () => {
    console.log('App Open Ad close');
  });
  AdMob.addListener(AppOpenAdPluginEvents.FailedToShow, (error) => {
    console.log('Failed to show App Open Ad', error);
  });
  AdMob.addListener(
    AppOpenAdPluginEvents.AdImpression,
    (data: AdMobRevenueData) => {
      // Forward impression-level revenue to your analytics provider.
      console.log(data);
    },
  );

  const options: AppOpenAdOptions = {
    adId: 'YOUR_AD_UNIT_ID',
  };
  const { adUnitId } = await AdMob.loadAppOpen(options);
  const { value } = await AdMob.isAppOpenLoaded({ adId: adUnitId });
  if (value) {
    await AdMob.showAppOpen({ adId: adUnitId });
  }
}

Keep an ad visible alongside app content

Use a Banner ad when the ad should remain visible without replacing the current screen.

import {
  AdMob,
  BannerAdOptions,
  BannerAdSize,
  BannerAdPosition,
  BannerAdPluginEvents,
  AdMobBannerSize,
  AdMobRevenueData,
} from '@capacitor-community/admob';

export async function banner(): Promise<void> {
  AdMob.addListener(BannerAdPluginEvents.Loaded, () => {
    // Subscribe Banner Event Listener
  });

  AdMob.addListener(
    BannerAdPluginEvents.SizeChanged,
    (size: AdMobBannerSize) => {
      // Subscribe Change Banner Size
    },
  );

  AdMob.addListener(
    BannerAdPluginEvents.AdPaid,
    (data: AdMobRevenueData) => {
      // Forward impression-level revenue to your analytics provider.
      console.log(data);
    },
  );

  const options: BannerAdOptions = {
    adId: 'YOUR ADID',
    adSize: BannerAdSize.BANNER,
    position: BannerAdPosition.BOTTOM_CENTER,
    margin: 0,
    // isTesting: true
    // npa: true
  };
  AdMob.showBanner(options);
}

Show a full-screen ad without a reward

Use an Interstitial ad at a natural break when the user should not receive an in-app reward.

import {
  AdMob,
  AdOptions,
  AdLoadInfo,
  AdMobRevenueData,
  InterstitialAdPluginEvents,
} from '@capacitor-community/admob';

export async function interstitial(): Promise<void> {
  AdMob.addListener(InterstitialAdPluginEvents.Loaded, (info: AdLoadInfo) => {
    // Subscribe prepared interstitial
  });

  AdMob.addListener(
    InterstitialAdPluginEvents.AdImpression,
    (data: AdMobRevenueData) => {
      // Forward impression-level revenue to your analytics provider.
      console.log(data);
    },
  );

  const options: AdOptions = {
    adId: 'YOUR ADID',
    // isTesting: true
    // npa: true
    // immersiveMode: true
  };
  await AdMob.prepareInterstitial(options);
  await AdMob.showInterstitial();

  // You can also prepare multiple interstitials and show a specific one by passing its adId:
  await AdMob.prepareInterstitial({ adId: 'ca-app-pub-xxx/interstitial-1' });
  await AdMob.prepareInterstitial({ adId: 'ca-app-pub-xxx/interstitial-2' });

  // Show a specific prepared ad
  await AdMob.showInterstitial({ adId: 'ca-app-pub-xxx/interstitial-1' });

  // Or omit adId to show the most recently prepared one (default behavior)
  await AdMob.showInterstitial();
}

Grant a reward after an ad experience

Treat rewarded ads as a reward flow, not as another non-rewarded interstitial placement. Grant the reward only from the rewarded result or event.

Rewarded video

Use a Rewarded ad for a dedicated reward flow.

import {
  AdMob,
  RewardAdOptions,
  AdLoadInfo,
  RewardAdPluginEvents,
  AdMobRevenueData,
} from '@capacitor-community/admob';

export async function rewardVideo(): Promise<void> {
  AdMob.addListener(RewardAdPluginEvents.Loaded, (info: AdLoadInfo) => {
    // Subscribe prepared rewardVideo
  });

  AdMob.addListener(
    RewardAdPluginEvents.AdImpression,
    (data: AdMobRevenueData) => {
      // Forward impression-level revenue to your analytics provider.
      console.log(data);
    },
  );

  const options: RewardAdOptions = {
    adId: 'YOUR ADID',
    // isTesting: true
    // npa: true
    // immersiveMode: true
    // ssv: {
    //   userId: "A user ID to send to your SSV"
    //   customData: JSON.stringify({ ...MyCustomData })
    //}
  };
  await AdMob.prepareRewardVideoAd(options);
  const rewardItem = await AdMob.showRewardVideoAd();
  // Grant the reward once, using this result.
  console.log(rewardItem);

  // You can also prepare multiple reward ads and show a specific one by passing its adId:
  await AdMob.prepareRewardVideoAd({ adId: 'ca-app-pub-xxx/reward-1' });
  await AdMob.prepareRewardVideoAd({ adId: 'ca-app-pub-xxx/reward-2' });

  // Show a specific prepared ad
  const reward = await AdMob.showRewardVideoAd({ adId: 'ca-app-pub-xxx/reward-1' });

  // Or omit adId to show the most recently prepared one (default behavior)
  const reward2 = await AdMob.showRewardVideoAd();
}
Rewarded interstitial

Use a Rewarded Interstitial ad when the rewarded experience belongs at a natural transition in the app.

import {
  AdMob,
  AdMobRewardInterstitialItem,
  AdMobRevenueData,
  RewardInterstitialAdOptions,
  RewardInterstitialAdPluginEvents,
} from '@capacitor-community/admob';

export async function rewardInterstitial(): Promise<void> {
  AdMob.addListener(
    RewardInterstitialAdPluginEvents.AdImpression,
    (data: AdMobRevenueData) => {
      // Forward impression-level revenue to your analytics provider.
      console.log(data);
    },
  );

  const options: RewardInterstitialAdOptions = {
    adId: 'YOUR ADID',
  };
  const { adUnitId } = await AdMob.prepareRewardInterstitialAd(options);
  const rewardItem: AdMobRewardInterstitialItem =
    await AdMob.showRewardInterstitialAd({ adId: adUnitId });
  // Grant the reward once, using this result.
  console.log(rewardItem);
}
Server-side verification

SSV callbacks are only fired on Production Adverts, therefore test Ads will not fire off your SSV callback.

For E2E tests or just for validating the data in your RewardAdOptions work as expected, you can add a custom GET request to your mock endpoint after the RewardAdPluginEvents.Rewarded similar to this:

AdMob.addListener(RewardAdPluginEvents.Rewarded, async () => {
  // ...
  if (ENVIRONMENT_IS_DEVELOPMENT) {
    try {
      const url =
        `https://your-staging-ssv-endpoint` +
        new URLSearchParams({
          ad_network: 'TEST',
          ad_unit: 'TEST',
          custom_data: customData, // <-- passed CustomData
          reward_amount: 'TEST',
          reward_item: 'TEST',
          timestamp: 'TEST',
          transaction_id: 'TEST',
          user_id: userId, // <-- Passed UserID
          signature: 'TEST',
          key_id: 'TEST',
        });
      await fetch(url);
    } catch (err) {
      console.error(err);
    }
  }
  // ...
});

Index

API

initialize(...)

initialize(options?: AdMobInitializationOptions | undefined) => Promise<void>

Initializes the Google Mobile Ads SDK.

Param Type Description
options AdMobInitializationOptions Optional SDK initialization settings.

Since: 1.1.2


trackingAuthorizationStatus()

trackingAuthorizationStatus() => Promise<TrackingAuthorizationStatusInterface>

Returns the current App Tracking Transparency authorization status on iOS 14 and later. Returns authorized on earlier iOS versions, Android, and web.

Returns: Promise<TrackingAuthorizationStatusInterface>

Since: 3.1.0


requestTrackingAuthorization()

requestTrackingAuthorization() => Promise<void>

Requests App Tracking Transparency authorization on iOS 14 and later. Resolves without taking action on earlier iOS versions, Android, and web.

Since: 5.2.0


setApplicationMuted(...)

setApplicationMuted(options: ApplicationMutedOptions) => Promise<void>

Reports whether the application audio is muted to the Google Mobile Ads SDK.

Param Type
options ApplicationMutedOptions

Since: 4.1.1


setApplicationVolume(...)

setApplicationVolume(options: ApplicationVolumeOptions) => Promise<void>

Reports the application audio volume to the Google Mobile Ads SDK.

Param Type
options ApplicationVolumeOptions

Since: 4.1.1


loadAppOpen(...)

loadAppOpen(options: AppOpenAdOptions) => Promise<AdLoadInfo>

Loads an App Open ad and returns the loaded ad unit ID.

Param Type
options AppOpenAdOptions

Returns: Promise<AdLoadInfo>


showAppOpen(...)

showAppOpen(options?: AdShowOptions | undefined) => Promise<void>

Shows a loaded App Open ad.

Param Type Description
options AdShowOptions Optional. Pass { adId } to show a specific prepared ad instead of the most recent one.

isAppOpenLoaded(...)

isAppOpenLoaded(options?: AdShowOptions | undefined) => Promise<{ value: boolean; }>

Checks whether an App Open ad is loaded.

Param Type Description
options AdShowOptions Optional. Pass an adId to check a specific prepared ad instead of the most recent one.

Returns: Promise<{ value: boolean; }>


addListener(AppOpenAdPluginEvents.Loaded, ...)

addListener(eventName: AppOpenAdPluginEvents.Loaded, listenerFunc: (info: AdLoadInfo) => void) => Promise<PluginListenerHandle>

Listens for App Open ad load events.

Param Type
eventName AppOpenAdPluginEvents.Loaded
listenerFunc (info: AdLoadInfo) => void

Returns: Promise<PluginListenerHandle>


addListener(AppOpenAdPluginEvents.FailedToLoad, ...)

addListener(eventName: AppOpenAdPluginEvents.FailedToLoad, listenerFunc: (error: AdMobError) => void) => Promise<PluginListenerHandle>

Listens for App Open ad load failures.

Param Type
eventName AppOpenAdPluginEvents.FailedToLoad
listenerFunc (error: AdMobError) => void

Returns: Promise<PluginListenerHandle>


addListener(AppOpenAdPluginEvents.Opened, ...)

addListener(eventName: AppOpenAdPluginEvents.Opened, listenerFunc: () => void) => Promise<PluginListenerHandle>

Listens for App Open ad opened events.

Param Type
eventName AppOpenAdPluginEvents.Opened
listenerFunc () => void

Returns: Promise<PluginListenerHandle>


addListener(AppOpenAdPluginEvents.Closed, ...)

addListener(eventName: AppOpenAdPluginEvents.Closed, listenerFunc: () => void) => Promise<PluginListenerHandle>

Listens for App Open ad closed events.

Param Type
eventName AppOpenAdPluginEvents.Closed
listenerFunc () => void

Returns: Promise<PluginListenerHandle>


addListener(AppOpenAdPluginEvents.FailedToShow, ...)

addListener(eventName: AppOpenAdPluginEvents.FailedToShow, listenerFunc: (error: AdMobError) => void) => Promise<PluginListenerHandle>

Listens for App Open ad show failures.

Param Type
eventName AppOpenAdPluginEvents.FailedToShow
listenerFunc (error: AdMobError) => void

Returns: Promise<PluginListenerHandle>


addListener(AppOpenAdPluginEvents.AdImpression, ...)

addListener(eventName: AppOpenAdPluginEvents.AdImpression, listenerFunc: (data: AdMobRevenueData) => void) => Promise<PluginListenerHandle>

Listens for App Open impression-level ad revenue events.

Param Type
eventName AppOpenAdPluginEvents.AdImpression
listenerFunc (data: AdMobRevenueData) => void

Returns: Promise<PluginListenerHandle>


showBanner(...)

showBanner(options: BannerAdOptions) => Promise<void>

Displays a banner ad.

Param Type Description
options BannerAdOptions AdOptions

Since: 1.1.2


hideBanner()

hideBanner() => Promise<void>

Hides the current banner without destroying it.

Since: 1.1.2


resumeBanner()

resumeBanner() => Promise<void>

Shows a previously hidden banner.

Since: 1.1.2


removeBanner()

removeBanner() => Promise<void>

Destroys the current banner and removes it from the screen.

Since: 1.1.2


addListener(BannerAdPluginEvents.SizeChanged, ...)

addListener(eventName: BannerAdPluginEvents.SizeChanged, listenerFunc: (info: AdMobBannerSize) => void) => Promise<PluginListenerHandle>

Listens for changes to the displayed banner dimensions.

Param Type Description
eventName BannerAdPluginEvents.SizeChanged bannerAdSizeChanged
listenerFunc (info: AdMobBannerSize) => void

Returns: Promise<PluginListenerHandle>

Since: 3.0.0


addListener(BannerAdPluginEvents.Loaded, ...)

addListener(eventName: BannerAdPluginEvents.Loaded, listenerFunc: () => void) => Promise<PluginListenerHandle>

Listens for banner ad load events.

Param Type Description
eventName BannerAdPluginEvents.Loaded bannerAdLoaded
listenerFunc () => void

Returns: Promise<PluginListenerHandle>

Since: 3.0.0


addListener(BannerAdPluginEvents.FailedToLoad, ...)

addListener(eventName: BannerAdPluginEvents.FailedToLoad, listenerFunc: (info: AdMobError) => void) => Promise<PluginListenerHandle>

Listens for banner ad load failures.

Param Type Description
eventName BannerAdPluginEvents.FailedToLoad bannerAdFailedToLoad
listenerFunc (info: AdMobError) => void

Returns: Promise<PluginListenerHandle>

Since: 3.0.0


addListener(BannerAdPluginEvents.Opened, ...)

addListener(eventName: BannerAdPluginEvents.Opened, listenerFunc: () => void) => Promise<PluginListenerHandle>

Listens for banner overlay opened events.

Param Type Description
eventName BannerAdPluginEvents.Opened bannerAdOpened
listenerFunc () => void

Returns: Promise<PluginListenerHandle>

Since: 3.0.0


addListener(BannerAdPluginEvents.Closed, ...)

addListener(eventName: BannerAdPluginEvents.Closed, listenerFunc: () => void) => Promise<PluginListenerHandle>

Listens for banner overlay closed events.

Param Type Description
eventName BannerAdPluginEvents.Closed bannerAdClosed
listenerFunc () => void

Returns: Promise<PluginListenerHandle>

Since: 3.0.0


addListener(BannerAdPluginEvents.AdImpression, ...)

addListener(eventName: BannerAdPluginEvents.AdImpression, listenerFunc: () => void) => Promise<PluginListenerHandle>

Listens for banner impression events.

Param Type Description
eventName BannerAdPluginEvents.AdImpression AdImpression
listenerFunc () => void

Returns: Promise<PluginListenerHandle>

Since: 3.0.0


addListener(BannerAdPluginEvents.AdPaid, ...)

addListener(eventName: BannerAdPluginEvents.AdPaid, listenerFunc: (data: AdMobRevenueData) => void) => Promise<PluginListenerHandle>

Listens for banner impression-level ad revenue events.

Param Type
eventName BannerAdPluginEvents.AdPaid
listenerFunc (data: AdMobRevenueData) => void

Returns: Promise<PluginListenerHandle>


requestConsentInfo(...)

requestConsentInfo(options?: AdmobConsentRequestOptions | undefined) => Promise<AdmobConsentInfo>

Request user consent information

Param Type Description
options AdmobConsentRequestOptions ConsentRequestOptions

Returns: Promise<AdmobConsentInfo>

Since: 5.0.0


showPrivacyOptionsForm()

showPrivacyOptionsForm() => Promise<void>

Shows a google privacy options form (rendered from your GDPR message config).

Since: 7.0.3


showConsentForm()

showConsentForm() => Promise<AdmobConsentInfo>

Shows a google user consent form (rendered from your GDPR message config).

Returns: Promise<AdmobConsentInfo>

Since: 5.0.0


resetConsentInfo()

resetConsentInfo() => Promise<void>

Resets the UMP SDK state. Call requestConsentInfo function again to allow user modify their consent

Since: 5.0.0


prepareInterstitial(...)

prepareInterstitial(options: AdOptions) => Promise<AdLoadInfo>

Loads an interstitial ad and returns the loaded ad unit ID.

Param Type Description
options AdOptions AdOptions

Returns: Promise<AdLoadInfo>

Since: 1.1.2


showInterstitial(...)

showInterstitial(options?: AdShowOptions | undefined) => Promise<void>

Shows a loaded interstitial ad.

Param Type Description
options AdShowOptions Optional. Pass { adId } to show a specific prepared ad instead of the most recent one.

Since: 1.1.2


addListener(InterstitialAdPluginEvents.FailedToLoad, ...)

addListener(eventName: InterstitialAdPluginEvents.FailedToLoad, listenerFunc: (error: AdMobError) => void) => Promise<PluginListenerHandle>

Listens for interstitial ad load failures.

Param Type
eventName InterstitialAdPluginEvents.FailedToLoad
listenerFunc (error: AdMobError) => void

Returns: Promise<PluginListenerHandle>


addListener(InterstitialAdPluginEvents.Loaded, ...)

addListener(eventName: InterstitialAdPluginEvents.Loaded, listenerFunc: (info: AdLoadInfo) => void) => Promise<PluginListenerHandle>

Listens for interstitial ad load events.

Param Type
eventName InterstitialAdPluginEvents.Loaded
listenerFunc (info: AdLoadInfo) => void

Returns: Promise<PluginListenerHandle>


addListener(InterstitialAdPluginEvents.Dismissed, ...)

addListener(eventName: InterstitialAdPluginEvents.Dismissed, listenerFunc: () => void) => Promise<PluginListenerHandle>

Listens for interstitial ad dismissed events.

Param Type
eventName InterstitialAdPluginEvents.Dismissed
listenerFunc () => void

Returns: Promise<PluginListenerHandle>


addListener(InterstitialAdPluginEvents.FailedToShow, ...)

addListener(eventName: InterstitialAdPluginEvents.FailedToShow, listenerFunc: (error: AdMobError) => void) => Promise<PluginListenerHandle>

Listens for interstitial ad show failures.

Param Type
eventName InterstitialAdPluginEvents.FailedToShow
listenerFunc (error: AdMobError) => void

Returns: Promise<PluginListenerHandle>


addListener(InterstitialAdPluginEvents.Showed, ...)

addListener(eventName: InterstitialAdPluginEvents.Showed, listenerFunc: () => void) => Promise<PluginListenerHandle>

Listens for interstitial ad shown events.

Param Type
eventName InterstitialAdPluginEvents.Showed
listenerFunc () => void

Returns: Promise<PluginListenerHandle>


addListener(InterstitialAdPluginEvents.AdImpression, ...)

addListener(eventName: InterstitialAdPluginEvents.AdImpression, listenerFunc: (data: AdMobRevenueData) => void) => Promise<PluginListenerHandle>

Listens for interstitial impression-level ad revenue events.

Param Type
eventName InterstitialAdPluginEvents.AdImpression
listenerFunc (data: AdMobRevenueData) => void

Returns: Promise<PluginListenerHandle>


prepareRewardVideoAd(...)

prepareRewardVideoAd(options: RewardAdOptions) => Promise<AdLoadInfo>

Loads a rewarded ad and returns the loaded ad unit ID.

Param Type Description
options RewardAdOptions RewardAdOptions

Returns: Promise<AdLoadInfo>

Since: 1.1.2


showRewardVideoAd(...)

showRewardVideoAd(options?: AdShowOptions | undefined) => Promise<AdMobRewardItem>

Shows a loaded rewarded ad and resolves when the user earns the reward.

Param Type Description
options AdShowOptions Optional. Pass { adId } to show a specific prepared ad instead of the most recent one.

Returns: Promise<AdMobRewardItem>

Since: 1.1.2


addListener(RewardAdPluginEvents.FailedToLoad, ...)

addListener(eventName: RewardAdPluginEvents.FailedToLoad, listenerFunc: (error: AdMobError) => void) => Promise<PluginListenerHandle>

Listens for rewarded ad load failures.

Param Type
eventName RewardAdPluginEvents.FailedToLoad
listenerFunc (error: AdMobError) => void

Returns: Promise<PluginListenerHandle>


addListener(RewardAdPluginEvents.Loaded, ...)

addListener(eventName: RewardAdPluginEvents.Loaded, listenerFunc: (info: AdLoadInfo) => void) => Promise<PluginListenerHandle>

Listens for rewarded ad load events.

Param Type
eventName RewardAdPluginEvents.Loaded
listenerFunc (info: AdLoadInfo) => void

Returns: Promise<PluginListenerHandle>


addListener(RewardAdPluginEvents.Rewarded, ...)

addListener(eventName: RewardAdPluginEvents.Rewarded, listenerFunc: (reward: AdMobRewardItem) => void) => Promise<PluginListenerHandle>

Listens for earned reward events.

Param Type
eventName RewardAdPluginEvents.Rewarded
listenerFunc (reward: AdMobRewardItem) => void

Returns: Promise<PluginListenerHandle>


addListener(RewardAdPluginEvents.Dismissed, ...)

addListener(eventName: RewardAdPluginEvents.Dismissed, listenerFunc: () => void) => Promise<PluginListenerHandle>

Listens for rewarded ad dismissed events.

Param Type
eventName RewardAdPluginEvents.Dismissed
listenerFunc () => void

Returns: Promise<PluginListenerHandle>


addListener(RewardAdPluginEvents.FailedToShow, ...)

addListener(eventName: RewardAdPluginEvents.FailedToShow, listenerFunc: (error: AdMobError) => void) => Promise<PluginListenerHandle>

Listens for rewarded ad show failures.

Param Type
eventName RewardAdPluginEvents.FailedToShow
listenerFunc (error: AdMobError) => void

Returns: Promise<PluginListenerHandle>


addListener(RewardAdPluginEvents.Showed, ...)

addListener(eventName: RewardAdPluginEvents.Showed, listenerFunc: () => void) => Promise<PluginListenerHandle>

Listens for rewarded ad shown events.

Param Type
eventName RewardAdPluginEvents.Showed
listenerFunc () => void

Returns: Promise<PluginListenerHandle>


addListener(RewardAdPluginEvents.AdImpression, ...)

addListener(eventName: RewardAdPluginEvents.AdImpression, listenerFunc: (data: AdMobRevenueData) => void) => Promise<PluginListenerHandle>

Listens for rewarded impression-level ad revenue events.

Param Type
eventName RewardAdPluginEvents.AdImpression
listenerFunc (data: AdMobRevenueData) => void

Returns: Promise<PluginListenerHandle>


prepareRewardInterstitialAd(...)

prepareRewardInterstitialAd(options: RewardInterstitialAdOptions) => Promise<AdLoadInfo>

Loads a rewarded interstitial ad and returns the loaded ad unit ID.

Param Type Description
options RewardInterstitialAdOptions RewardInterstitialAdOptions

Returns: Promise<AdLoadInfo>

Since: 1.1.2


showRewardInterstitialAd(...)

showRewardInterstitialAd(options?: AdShowOptions | undefined) => Promise<AdMobRewardInterstitialItem>

Shows a loaded rewarded interstitial ad and resolves when the user earns the reward.

Param Type Description
options AdShowOptions Optional. Pass { adId } to show a specific prepared ad instead of the most recent one.

Returns: Promise<AdMobRewardInterstitialItem>

Since: 1.1.2


addListener(RewardInterstitialAdPluginEvents.FailedToLoad, ...)

addListener(eventName: RewardInterstitialAdPluginEvents.FailedToLoad, listenerFunc: (error: AdMobError) => void) => Promise<PluginListenerHandle>

Listens for rewarded interstitial ad load failures.

Param Type
eventName RewardInterstitialAdPluginEvents.FailedToLoad
listenerFunc (error: AdMobError) => void

Returns: Promise<PluginListenerHandle>


addListener(RewardInterstitialAdPluginEvents.Loaded, ...)

addListener(eventName: RewardInterstitialAdPluginEvents.Loaded, listenerFunc: (info: AdLoadInfo) => void) => Promise<PluginListenerHandle>

Listens for rewarded interstitial ad load events.

Param Type
eventName RewardInterstitialAdPluginEvents.Loaded
listenerFunc (info: AdLoadInfo) => void

Returns: Promise<PluginListenerHandle>


addListener(RewardInterstitialAdPluginEvents.Rewarded, ...)

addListener(eventName: RewardInterstitialAdPluginEvents.Rewarded, listenerFunc: (reward: AdMobRewardInterstitialItem) => void) => Promise<PluginListenerHandle>

Listens for earned reward events.

Param Type
eventName RewardInterstitialAdPluginEvents.Rewarded
listenerFunc (reward: AdMobRewardInterstitialItem) => void

Returns: Promise<PluginListenerHandle>


addListener(RewardInterstitialAdPluginEvents.Dismissed, ...)

addListener(eventName: RewardInterstitialAdPluginEvents.Dismissed, listenerFunc: () => void) => Promise<PluginListenerHandle>

Listens for rewarded interstitial ad dismissed events.

Param Type
eventName RewardInterstitialAdPluginEvents.Dismissed
listenerFunc () => void

Returns: Promise<PluginListenerHandle>


addListener(RewardInterstitialAdPluginEvents.FailedToShow, ...)

addListener(eventName: RewardInterstitialAdPluginEvents.FailedToShow, listenerFunc: (error: AdMobError) => void) => Promise<PluginListenerHandle>

Listens for rewarded interstitial ad show failures.

Param Type
eventName RewardInterstitialAdPluginEvents.FailedToShow
listenerFunc (error: AdMobError) => void

Returns: Promise<PluginListenerHandle>


addListener(RewardInterstitialAdPluginEvents.Showed, ...)

addListener(eventName: RewardInterstitialAdPluginEvents.Showed, listenerFunc: () => void) => Promise<PluginListenerHandle>

Listens for rewarded interstitial ad shown events.

Param Type
eventName RewardInterstitialAdPluginEvents.Showed
listenerFunc () => void

Returns: Promise<PluginListenerHandle>


addListener(RewardInterstitialAdPluginEvents.AdImpression, ...)

addListener(eventName: RewardInterstitialAdPluginEvents.AdImpression, listenerFunc: (data: AdMobRevenueData) => void) => Promise<PluginListenerHandle>

Listens for rewarded interstitial impression-level ad revenue events.

Param Type
eventName RewardInterstitialAdPluginEvents.AdImpression
listenerFunc (data: AdMobRevenueData) => void

Returns: Promise<PluginListenerHandle>


Interfaces

AdMobInitializationOptions

Prop Type Description Default Since
testingDevices string[] Device IDs to register as test devices when {@link AdMobInitializationOptions.initializeForTesting} is true. Requests from registered devices receive test ads and do not generate invalid traffic. 1.2.0
initializeForTesting boolean Whether to register {@link AdMobInitializationOptions.testingDevices} as test devices. false 1.2.0
tagForChildDirectedTreatment boolean For purposes of the Children's Online Privacy Protection Act (COPPA), there is a setting called tagForChildDirectedTreatment. 3.1.0
tagForUnderAgeOfConsent boolean When using this feature, a Tag For Users under the Age of Consent in Europe (TFUA) parameter will be included in all future ad requests. 3.1.0
maxAdContentRating MaxAdContentRating The maximum ad content rating applied to all ad requests. Ads with a higher rating are excluded. 3.1.0

TrackingAuthorizationStatusInterface

The current iOS App Tracking Transparency authorization status.

Prop Type Description
status 'authorized' | 'denied' | 'notDetermined' | 'restricted' The authorization status reported by App Tracking Transparency.

ApplicationMutedOptions

Prop Type Description Since
muted boolean To inform the SDK that the app volume has been muted. Note: Video ads that are ineligible to be shown with muted audio are not returned for ad requests made, when the app volume is reported as muted or set to a value of 0. This may restrict a subset of the broader video ads pool from serving. 4.1.1

ApplicationVolumeOptions

Prop Type Description Since
volume 0 | 1 | 0.1 | 0.2 | 0.3 | 0.4 | 0.5 | 0.6 | 0.7 | 0.8 | 0.9 If your app has its own volume controls (such as custom music or sound effect volumes), disclosing app volume to the Google Mobile Ads SDK allows video ads to respect app volume settings. Use a supported value from 0.0 (silent) to 1.0 (full volume). 4.1.1

AdLoadInfo

Information returned after an ad loads successfully.

Prop Type Description
adUnitId string The ad unit ID of the loaded ad.

AppOpenAdOptions

Options for loading an App Open ad.

Prop Type Description
adId string The App Open ad unit ID to load.

AdShowOptions

Options for selecting a previously loaded ad to show or inspect.

Prop Type Description Since
adId string The ad unit ID of a previously prepared ad to target. If omitted, the operation targets the most recently prepared ad. 8.0.1

PluginListenerHandle

Prop Type
remove () => Promise<void>

AdMobError

An error returned by the Google Mobile Ads SDK.

Prop Type Description
code number Gets the error's code.
message string Gets the message describing the error.

AdMobRevenueData

Impression-level ad revenue data emitted by a paid event.

Prop Type Description
adUnitId string The ad unit ID associated with the paid event.
valueMicros number The ad value in micros, where 1,000,000 micros equals one currency unit.
currencyCode string The ISO 4217 currency code for valueMicros.
precision AdValuePrecision The precision of the reported ad value.
networkName string The mediation adapter class name that served the impression, or an empty string when unavailable.
impressionId string The response identifier associated with the impression, or an empty string when unavailable.

BannerAdOptions

Options for displaying a banner ad.

This interface extends AdOptions.

Prop Type Description Default Since
adSize BannerAdSize The banner size to display. ADAPTIVE_BANNER 3.0.0
position BannerAdPosition The position where the banner is displayed. TOP_CENTER 1.1.2
adId string The ad unit ID to load. 1.1.2
isTesting boolean Whether to request a test ad. false 1.1.2
margin number The banner margin in logical display units (dp on Android and points on iOS). For BOTTOM_CENTER, this is the bottom margin. For TOP_CENTER, this is the top margin. 0 1.1.2
npa boolean Whether to request non-personalized ads. false 1.2.0
immersiveMode boolean Whether to display a full-screen ad in immersive mode on Android. 7.0.3

AdMobBannerSize

The displayed banner dimensions in logical display units (dp on Android and points on iOS). A hidden, removed, or failed banner can report both dimensions as 0.

Prop Type Description
width number The displayed banner width.
height number The displayed banner height.

AdmobConsentInfo

Prop Type Description Since
status AdmobConsentStatus The consent status of the user. 5.0.0
isConsentFormAvailable boolean If true a consent form is available and vice versa. 5.0.0
canRequestAds boolean If true an ad can be shown. 7.0.3
privacyOptionsRequirementStatus PrivacyOptionsRequirementStatus Privacy options requirement status of the user. 7.0.3

AdmobConsentRequestOptions

Prop Type Description Default Since
debugGeography AdmobConsentDebugGeography Sets the debug geography to test the consent locally. 5.0.0
testDeviceIdentifiers string[] An array of test device IDs to allow. Note: On iOS, the ID may renew if you uninstall and reinstall the app. 5.0.0
tagForUnderAgeOfConsent boolean Set to true to provide the option for the user to accept being shown personalized ads. false 5.0.0

AdOptions

Common options for requesting an ad.

Prop Type Description Default Since
adId string The ad unit ID to load. 1.1.2
isTesting boolean Whether to request a test ad. false 1.1.2
margin number The banner margin in logical display units (dp on Android and points on iOS). For BOTTOM_CENTER, this is the bottom margin. For TOP_CENTER, this is the top margin. 0 1.1.2
npa boolean Whether to request non-personalized ads. false 1.2.0
immersiveMode boolean Whether to display a full-screen ad in immersive mode on Android. 7.0.3

RewardAdOptions

Options for loading a rewarded ad.

Prop Type Description Default Since
ssv AtLeastOne<{ /** * A user identifier passed to the SSV callback. / userId: string; /* * Custom data passed to the SSV callback. */ customData: string; }> Server-side verification options for the rewarded ad. Provide at least one of userId or customData.
adId string The ad unit ID to load. 1.1.2
isTesting boolean Whether to request a test ad. false 1.1.2
margin number The banner margin in logical display units (dp on Android and points on iOS). For BOTTOM_CENTER, this is the bottom margin. For TOP_CENTER, this is the top margin. 0 1.1.2
npa boolean Whether to request non-personalized ads. false 1.2.0
immersiveMode boolean Whether to display a full-screen ad in immersive mode on Android. 7.0.3

AdMobRewardItem

The reward earned by the user after viewing a rewarded ad.

Prop Type Description
type string The reward item type configured for the ad unit.
amount number The reward amount earned by the user.

RewardInterstitialAdOptions

Options for loading a rewarded interstitial ad.

Prop Type Description Default Since
ssv AtLeastOne<{ /** * A user identifier passed to the SSV callback. / userId: string; /* * Custom data passed to the SSV callback. */ customData: string; }> Server-side verification options for the rewarded interstitial ad. Provide at least one of userId or customData.
adId string The ad unit ID to load. 1.1.2
isTesting boolean Whether to request a test ad. false 1.1.2
margin number The banner margin in logical display units (dp on Android and points on iOS). For BOTTOM_CENTER, this is the bottom margin. For TOP_CENTER, this is the top margin. 0 1.1.2
npa boolean Whether to request non-personalized ads. false 1.2.0
immersiveMode boolean Whether to display a full-screen ad in immersive mode on Android. 7.0.3

AdMobRewardInterstitialItem

The reward earned by the user after viewing a rewarded interstitial ad.

Prop Type Description
type string The reward item type configured for the ad unit.
amount number The reward amount earned by the user.

Type Aliases

AtLeastOne

{[K in keyof T]: Pick<T, K>}[keyof T]

Pick

From T, pick a set of properties whose keys are in the union K

{ [P in K]: T[P]; }

Enums

MaxAdContentRating

Members Value Description
General 'General' Content suitable for general audiences, including families.
ParentalGuidance 'ParentalGuidance' Content suitable for most audiences with parental guidance.
Teen 'Teen' Content suitable for teen and older audiences.
MatureAudience 'MatureAudience' Content suitable only for mature audiences.

AppOpenAdPluginEvents

Members Value Description
Loaded 'appOpenAdLoaded' Emits when an App Open ad has loaded.
FailedToLoad 'appOpenAdFailedToLoad' Emits when an App Open ad fails to load.
Opened 'appOpenAdOpened' Emits when an App Open ad is shown.
Closed 'appOpenAdClosed' Emits when an App Open ad is dismissed.
FailedToShow 'appOpenAdFailedToShow' Emits when a loaded App Open ad fails to show.
AdImpression 'appOpenAdImpression' Emits impression-level ad revenue data when a paid event is recorded.

AdValuePrecision

Members Value Description
Unknown 0 The ad value precision is unknown.
Estimated 1 The ad value is estimated from aggregated data.
PublisherProvided 2 The ad value was provided by the publisher.
Precise 3 The ad value is the precise value paid for this ad.

BannerAdSize

Members Value Description
BANNER 'BANNER' Mobile Marketing Association (MMA) banner ad size (320x50 density-independent pixels).
FULL_BANNER 'FULL_BANNER' Interactive Advertising Bureau (IAB) full banner ad size (468x60 density-independent pixels).
LARGE_BANNER 'LARGE_BANNER' Large banner ad size (320x100 density-independent pixels).
MEDIUM_RECTANGLE 'MEDIUM_RECTANGLE' Interactive Advertising Bureau (IAB) medium rectangle ad size (300x250 density-independent pixels).
LEADERBOARD 'LEADERBOARD' Interactive Advertising Bureau (IAB) leaderboard ad size (728x90 density-independent pixels).
ADAPTIVE_BANNER 'ADAPTIVE_BANNER' A dynamically sized banner that is full-width and auto-height.
SMART_BANNER 'SMART_BANNER' A legacy smart banner sized to the screen width. Retained for compatibility; use ADAPTIVE_BANNER for new integrations.

BannerAdPosition

Members Value Description
TOP_CENTER 'TOP_CENTER' Positions the banner at the top center of the screen.
CENTER 'CENTER' Positions the banner at the center of the screen.
BOTTOM_CENTER 'BOTTOM_CENTER' Positions the banner at the bottom center of the screen.

BannerAdPluginEvents

Members Value Description
SizeChanged "bannerAdSizeChanged" Emits when the displayed banner size changes.
Loaded "bannerAdLoaded" Emits when a banner ad has loaded.
FailedToLoad "bannerAdFailedToLoad" Emits when a banner ad fails to load.
Opened "bannerAdOpened" Emits when a banner opens an overlay after the user taps it.
Closed "bannerAdClosed" Emits when the banner overlay is closed.
AdImpression "bannerAdImpression" Emits when an impression is recorded for the banner ad.
AdPaid "bannerAdPaid" Emits impression-level ad revenue data when a paid event is recorded.

AdmobConsentStatus

Members Value Description
NOT_REQUIRED 'NOT_REQUIRED' User consent not required.
OBTAINED 'OBTAINED' User consent already obtained.
REQUIRED 'REQUIRED' User consent required but not yet obtained.
UNKNOWN 'UNKNOWN' Unknown consent status, AdsConsent.requestInfoUpdate needs to be called to update it.

PrivacyOptionsRequirementStatus

Members Value Description
NOT_REQUIRED 'NOT_REQUIRED' Privacy options entry point is not required.
REQUIRED 'REQUIRED' Privacy options entry point is required.
UNKNOWN 'UNKNOWN' Privacy options requirement status is unknown.

AdmobConsentDebugGeography

Members Value Description
DISABLED 0 Debug geography disabled.
EEA 1 Geography appears as in EEA for debug devices.
NOT_EEA 2 Geography appears as not in EEA for debug devices.
US 3 Geography appears as in regulated US state for debug devices.
OTHER 4 Geography appears as OTHER state for debug devices.

InterstitialAdPluginEvents

Members Value Description
Loaded 'interstitialAdLoaded' Emits when an interstitial ad has loaded and is ready to show.
FailedToLoad 'interstitialAdFailedToLoad' Emits when an interstitial ad fails to load.
Showed 'interstitialAdShowed' Emits when an interstitial ad is shown.
FailedToShow 'interstitialAdFailedToShow' Emits when a loaded interstitial ad fails to show.
Dismissed 'interstitialAdDismissed' Emits when an interstitial ad is dismissed.
AdImpression 'interstitialAdImpression' Emits impression-level ad revenue data when a paid event is recorded.

RewardAdPluginEvents

Members Value Description
Loaded 'onRewardedVideoAdLoaded' Emits when a rewarded ad has loaded and is ready to show.
FailedToLoad 'onRewardedVideoAdFailedToLoad' Emits when a rewarded ad fails to load.
Showed 'onRewardedVideoAdShowed' Emits when a rewarded ad is shown.
FailedToShow 'onRewardedVideoAdFailedToShow' Emits when a loaded rewarded ad fails to show.
Dismissed 'onRewardedVideoAdDismissed' Emits when a rewarded ad is dismissed. This event does not indicate whether the user earned a reward. Listen for Rewarded separately before granting the reward.
Rewarded 'onRewardedVideoAdReward' Emits when the user earns the advertised reward.
AdImpression 'onRewardedVideoAdImpression' Emits impression-level ad revenue data when a paid event is recorded.

RewardInterstitialAdPluginEvents

Members Value Description
Loaded 'onRewardedInterstitialAdLoaded' Emits when a rewarded interstitial ad has loaded and is ready to show.
FailedToLoad 'onRewardedInterstitialAdFailedToLoad' Emits when a rewarded interstitial ad fails to load.
Showed 'onRewardedInterstitialAdShowed' Emits when a rewarded interstitial ad is shown.
FailedToShow 'onRewardedInterstitialAdFailedToShow' Emits when a loaded rewarded interstitial ad fails to show.
Dismissed 'onRewardedInterstitialAdDismissed' Emits when a rewarded interstitial ad is dismissed. This event does not indicate whether the user earned a reward. Listen for Rewarded separately before granting the reward.
Rewarded 'onRewardedInterstitialAdReward' Emits when the user earns the advertised reward.
AdImpression 'onRewardedInterstitialAdImpression' Emits impression-level ad revenue data when a paid event is recorded.

TROUBLE SHOOTING

If you have error:

[error] Error running update: Analyzing dependencies [!] CocoaPods could not find compatible versions for pod "Google-Mobile-Ads-SDK":

You should run pod repo update ;

License

Capacitor AdMob is MIT licensed.

About

Community plugin for using Google AdMob

Resources

Code of conduct

Contributing

Stars

294 stars

Watchers

17 watching

Forks

Releases

Packages

Used by

Contributors

Languages