@capacitor-community/admob
v8.1.0
Published
A native plugin for AdMob
Maintainers
Readme
Maintainers
| Maintainer | GitHub | Social | Sponsoring Company | | ------------------- | ------------------------------------------------ | ----------------------------------------------- | ---------------------------------------------- | | Masahiko Sakakibara | rdlabo | @rdlabo | RELATION DESIGN LABO, GENERAL INC. ASSOCIATION | | Saninn Salas Diaz | Saninn Salas Diaz | @SaninnSalas | |
Maintenance Status: Actively Maintained
Contributors ✨
Made with contributors-img.
Demo
Screenshots
| | Banner | Interstitial | Reward | App Open |
| :---------- | :----------------------------------: | :----------------------------------------: | :----------------------------------: | :---------------------------------: |
| iOS |
|
|
|
|
| Android |
|
|
|
|
Installation
If you use Capacitor 7:
% npm install --save @capacitor-community/admob@7
% npx cap updateGoogle 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):
playServicesAdsVersionversion ofcom.google.android.gms:play-services-ads(default:25.4.+)androidxCoreKTXVersion: version ofandroidx.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.
Example
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.
Note: The order in which they are combined with other methods is as follows.
- AdMob.initialize
- AdMob.requestConsentInfo
- AdMob.showConsentForm (If consent form required ) 3/ AdMob.showBanner
Show App Open Ad
import {
AdMob,
AppOpenAdPluginEvents,
AppOpenAdOptions,
AdLoadInfo,
} 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);
});
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 });
}
}Show Banner
import {
AdMob,
BannerAdOptions,
BannerAdSize,
BannerAdPosition,
BannerAdPluginEvents,
AdMobBannerSize,
} 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
},
);
const options: BannerAdOptions = {
adId: 'YOUR ADID',
adSize: BannerAdSize.BANNER,
position: BannerAdPosition.BOTTOM_CENTER,
margin: 0,
// isTesting: true
// npa: true
};
AdMob.showBanner(options);
}Impression-level ad revenue
Full-screen ad formats emit revenue data through their AdImpression event. Banners use the separate AdPaid event.
import {
AdMob,
AdMobRevenueData,
BannerAdPluginEvents,
InterstitialAdPluginEvents,
} from '@capacitor-community/admob';
AdMob.addListener(
InterstitialAdPluginEvents.AdImpression,
(data: AdMobRevenueData) => {
console.log(data);
},
);
AdMob.addListener(BannerAdPluginEvents.AdPaid, (data: AdMobRevenueData) => {
console.log(data);
});Show Interstitial
import {
AdMob,
AdOptions,
AdLoadInfo,
InterstitialAdPluginEvents,
} from '@capacitor-community/admob';
export async function interstitial(): Promise<void> {
AdMob.addListener(InterstitialAdPluginEvents.Loaded, (info: AdLoadInfo) => {
// Subscribe prepared interstitial
});
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();
}Show RewardVideo
import {
AdMob,
RewardAdOptions,
AdLoadInfo,
RewardAdPluginEvents,
AdMobRewardItem,
} from '@capacitor-community/admob';
export async function rewardVideo(): Promise<void> {
AdMob.addListener(RewardAdPluginEvents.Loaded, (info: AdLoadInfo) => {
// Subscribe prepared rewardVideo
});
AdMob.addListener(
RewardAdPluginEvents.Rewarded,
(rewardItem: AdMobRewardItem) => {
// Subscribe user rewarded
console.log(rewardItem);
},
);
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();
// 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();
}Show Rewarded Interstitial
import { AdMob, RewardInterstitialAdOptions } from '@capacitor-community/admob';
export async function rewardInterstitial(): Promise<void> {
const options: RewardInterstitialAdOptions = {
adId: 'YOUR ADID',
};
const { adUnitId } = await AdMob.prepareRewardInterstitialAd(options);
await AdMob.showRewardInterstitialAd({ adId: adUnitId });
}Server-side Verification Notice
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
initialize(...)trackingAuthorizationStatus()requestTrackingAuthorization()setApplicationMuted(...)setApplicationVolume(...)loadAppOpen(...)showAppOpen(...)isAppOpenLoaded(...)addListener(AppOpenAdPluginEvents.Loaded, ...)addListener(AppOpenAdPluginEvents.FailedToLoad, ...)addListener(AppOpenAdPluginEvents.Opened, ...)addListener(AppOpenAdPluginEvents.Closed, ...)addListener(AppOpenAdPluginEvents.FailedToShow, ...)addListener(AppOpenAdPluginEvents.AdImpression, ...)showBanner(...)hideBanner()resumeBanner()removeBanner()addListener(BannerAdPluginEvents.SizeChanged, ...)addListener(BannerAdPluginEvents.Loaded, ...)addListener(BannerAdPluginEvents.FailedToLoad, ...)addListener(BannerAdPluginEvents.Opened, ...)addListener(BannerAdPluginEvents.Closed, ...)addListener(BannerAdPluginEvents.AdImpression, ...)addListener(BannerAdPluginEvents.AdPaid, ...)requestConsentInfo(...)showPrivacyOptionsForm()showConsentForm()resetConsentInfo()prepareInterstitial(...)showInterstitial(...)addListener(InterstitialAdPluginEvents.FailedToLoad, ...)addListener(InterstitialAdPluginEvents.Loaded, ...)addListener(InterstitialAdPluginEvents.Dismissed, ...)addListener(InterstitialAdPluginEvents.FailedToShow, ...)addListener(InterstitialAdPluginEvents.Showed, ...)addListener(InterstitialAdPluginEvents.AdImpression, ...)prepareRewardVideoAd(...)showRewardVideoAd(...)addListener(RewardAdPluginEvents.FailedToLoad, ...)addListener(RewardAdPluginEvents.Loaded, ...)addListener(RewardAdPluginEvents.Rewarded, ...)addListener(RewardAdPluginEvents.Dismissed, ...)addListener(RewardAdPluginEvents.FailedToShow, ...)addListener(RewardAdPluginEvents.Showed, ...)addListener(RewardAdPluginEvents.AdImpression, ...)prepareRewardInterstitialAd(...)showRewardInterstitialAd(...)addListener(RewardInterstitialAdPluginEvents.FailedToLoad, ...)addListener(RewardInterstitialAdPluginEvents.Loaded, ...)addListener(RewardInterstitialAdPluginEvents.Rewarded, ...)addListener(RewardInterstitialAdPluginEvents.Dismissed, ...)addListener(RewardInterstitialAdPluginEvents.FailedToShow, ...)addListener(RewardInterstitialAdPluginEvents.Showed, ...)addListener(RewardInterstitialAdPluginEvents.AdImpression, ...)- Interfaces
- Type Aliases
- Enums
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
