Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/capacitor-community/admob
Community plugin for using Google AdMob
https://github.com/capacitor-community/admob
Last synced: 5 days ago
JSON representation
Community plugin for using Google AdMob
- Host: GitHub
- URL: https://github.com/capacitor-community/admob
- Owner: capacitor-community
- License: mit
- Created: 2020-06-23T15:50:44.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-06-27T17:13:31.000Z (6 months ago)
- Last Synced: 2024-10-29T20:57:27.010Z (about 1 month ago)
- Language: Java
- Homepage:
- Size: 8.51 MB
- Stars: 218
- Watchers: 18
- Forks: 68
- Open Issues: 49
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
- awesome-capacitorjs - @capacitor-community/admob - Community plugin for using Google AdMob. (Plugins / Community Plugins)
- awesome-capacitor - Admob - A native plugin for AdMob. (Community plugins)
README
AdMob
@capacitor-community/admob
Capacitor community plugin for native AdMob.## Maintainers
| Maintainer | GitHub | Social | Sponsoring Company |
| ------------------- | ------------------------------------------------ | ----------------------------------------------- | ---------------------------------------------- |
| Masahiko Sakakibara | [rdlabo](https://github.com/rdlabo) | [@rdlabo](https://twitter.com/rdlabo) | RELATION DESIGN LABO, GENERAL INC. ASSOCIATION |
| Saninn Salas Diaz | [Saninn Salas Diaz](https://github.com/distante) | [@SaninnSalas](https://twitter.com/SaninnSalas) | |Maintenance Status: Actively Maintained
## Contributors ✨
Made with [contributors-img](https://contrib.rocks).
## Demo
[Demo code is here.](https://github.com/capacitor-community/admob/tree/master/demo)
### Screenshots
| | Banner | Interstitial | Reward |
| :---------- | :----------------------------------: | :----------------------------------------: | :----------------------------------: |
| **iOS** | ![](demo/screenshots/ios_banner.png) | ![](demo/screenshots/ios_interstitial.png) | ![](demo/screenshots/ios_reward.png) |
| **Android** | ![](demo/screenshots/md_banner.png) | ![](demo/screenshots/md_interstitial.png) | ![](demo/screenshots/md_reward.png) |## Installation
If you use capacitor 6 and ios with Swift Package Manager:
```bash
% npm install --save @capacitor-community/admob@next
```If you use capacitor 5:
```
% npm install --save @capacitor-community/[email protected]
% npx cap update
```If you use capacitor 4:
```
% npm install --save @capacitor-community/[email protected]
% npx cap update
```capacitor 3:
```
% npm install --save @capacitor-community/[email protected]
% npx cap update
```### Android configuration
In file `android/app/src/main/AndroidManifest.xml`, add the following XML elements under `` :
```xml
```
In file `android/app/src/main/res/values/strings.xml` add the following lines :
```xml
[APP_ID]
```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: `22.0.0`)
- `androidxCoreKTXVersion`: version of `androidx.core:core-ktx` (default: `1.10.0`)### iOS configuration
Add the following in the `ios/App/App/info.plist` file inside of the outermost ``:
```xml
GADIsAdManagerAppGADApplicationIdentifier
[APP_ID]
SKAdNetworkItems
SKAdNetworkIdentifier
cstr6suwn9.skadnetwork
NSUserTrackingUsageDescription
[Why you use NSUserTracking. ex: This identifier will be used to deliver personalized ads to you.]
```Don't forget to replace `[APP_ID]` by your AdMob application Id.
## Example
### Initialize AdMob
```ts
import { AdMob } from '@capacitor-community/admob';export async function initialize(): Promise {
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)
Later this year, Google will require all publishers serving ads to EEA and UK users to use a Google-certified Consent Management Platform (CMP)
Currently we just support Google's consent management solution.
To use UMP, you must [create your GDPR messages](https://support.google.com/admob/answer/10113207?hl=en&ref_topic=10105230&sjid=6731900490614517032-AP)
You may need to [setup IDFA messages](https://support.google.com/admob/answer/10115027?hl=en), it will work along with GDPR messages and will show when users are not in EEA and UK.
Example of how to use UMP
```ts
import { AdMob, AdmobConsentStatus, AdmobConsentDebugGeography } from '@capacitor-community/admob';async showConsent() {
const consentInfo = await AdMob.requestConsentInfo();if (consentInfo.isConsentFormAvailable && consentInfo.status === AdmobConsentStatus.REQUIRED) {
const {status} = await AdMob.showConsentForm();
}
}
```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).
```ts
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.
1. AdMob.initialize
2. AdMob.requestConsentInfo
3. AdMob.showConsentForm (If consent form required )
3/ AdMob.showBanner### Show Banner
```ts
import {
AdMob,
BannerAdOptions,
BannerAdSize,
BannerAdPosition,
BannerAdPluginEvents,
AdMobBannerSize,
} from '@capacitor-community/admob';export async function banner(): Promise {
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);
}
```### Show Interstitial
```ts
import {
AdMob,
AdOptions,
AdLoadInfo,
InterstitialAdPluginEvents,
} from '@capacitor-community/admob';export async function interstitial(): Promise {
AdMob.addListener(InterstitialAdPluginEvents.Loaded, (info: AdLoadInfo) => {
// Subscribe prepared interstitial
});const options: AdOptions = {
adId: 'YOUR ADID',
// isTesting: true
// npa: true
};
await AdMob.prepareInterstitial(options);
await AdMob.showInterstitial();
}
```### Show RewardVideo
```ts
import {
AdMob,
RewardAdOptions,
AdLoadInfo,
RewardAdPluginEvents,
AdMobRewardItem,
} from '@capacitor-community/admob';export async function rewardVideo(): Promise {
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
// ssv: {
// userId: "A user ID to send to your SSV"
// customData: JSON.stringify({ ...MyCustomData })
//}
};
await AdMob.prepareRewardVideoAd(options);
const rewardItem = await AdMob.showRewardVideoAd();
}
```## 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:```ts
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(...)`](#initialize)
* [`trackingAuthorizationStatus()`](#trackingauthorizationstatus)
* [`requestTrackingAuthorization()`](#requesttrackingauthorization)
* [`setApplicationMuted(...)`](#setapplicationmuted)
* [`setApplicationVolume(...)`](#setapplicationvolume)
* [`showBanner(...)`](#showbanner)
* [`hideBanner()`](#hidebanner)
* [`resumeBanner()`](#resumebanner)
* [`removeBanner()`](#removebanner)
* [`addListener(BannerAdPluginEvents.SizeChanged, ...)`](#addlistenerbanneradplugineventssizechanged-)
* [`addListener(BannerAdPluginEvents.Loaded, ...)`](#addlistenerbanneradplugineventsloaded-)
* [`addListener(BannerAdPluginEvents.FailedToLoad, ...)`](#addlistenerbanneradplugineventsfailedtoload-)
* [`addListener(BannerAdPluginEvents.Opened, ...)`](#addlistenerbanneradplugineventsopened-)
* [`addListener(BannerAdPluginEvents.Closed, ...)`](#addlistenerbanneradplugineventsclosed-)
* [`addListener(BannerAdPluginEvents.AdImpression, ...)`](#addlistenerbanneradplugineventsadimpression-)
* [`requestConsentInfo(...)`](#requestconsentinfo)
* [`showConsentForm()`](#showconsentform)
* [`resetConsentInfo()`](#resetconsentinfo)
* [`prepareInterstitial(...)`](#prepareinterstitial)
* [`showInterstitial()`](#showinterstitial)
* [`addListener(InterstitialAdPluginEvents.FailedToLoad, ...)`](#addlistenerinterstitialadplugineventsfailedtoload-)
* [`addListener(InterstitialAdPluginEvents.Loaded, ...)`](#addlistenerinterstitialadplugineventsloaded-)
* [`addListener(InterstitialAdPluginEvents.Dismissed, ...)`](#addlistenerinterstitialadplugineventsdismissed-)
* [`addListener(InterstitialAdPluginEvents.FailedToShow, ...)`](#addlistenerinterstitialadplugineventsfailedtoshow-)
* [`addListener(InterstitialAdPluginEvents.Showed, ...)`](#addlistenerinterstitialadplugineventsshowed-)
* [`prepareRewardVideoAd(...)`](#preparerewardvideoad)
* [`showRewardVideoAd()`](#showrewardvideoad)
* [`addListener(RewardAdPluginEvents.FailedToLoad, ...)`](#addlistenerrewardadplugineventsfailedtoload-)
* [`addListener(RewardAdPluginEvents.Loaded, ...)`](#addlistenerrewardadplugineventsloaded-)
* [`addListener(RewardAdPluginEvents.Rewarded, ...)`](#addlistenerrewardadplugineventsrewarded-)
* [`addListener(RewardAdPluginEvents.Dismissed, ...)`](#addlistenerrewardadplugineventsdismissed-)
* [`addListener(RewardAdPluginEvents.FailedToShow, ...)`](#addlistenerrewardadplugineventsfailedtoshow-)
* [`addListener(RewardAdPluginEvents.Showed, ...)`](#addlistenerrewardadplugineventsshowed-)
* [`prepareRewardInterstitialAd(...)`](#preparerewardinterstitialad)
* [`showRewardInterstitialAd()`](#showrewardinterstitialad)
* [`addListener(RewardInterstitialAdPluginEvents.FailedToLoad, ...)`](#addlistenerrewardinterstitialadplugineventsfailedtoload-)
* [`addListener(RewardInterstitialAdPluginEvents.Loaded, ...)`](#addlistenerrewardinterstitialadplugineventsloaded-)
* [`addListener(RewardInterstitialAdPluginEvents.Rewarded, ...)`](#addlistenerrewardinterstitialadplugineventsrewarded-)
* [`addListener(RewardInterstitialAdPluginEvents.Dismissed, ...)`](#addlistenerrewardinterstitialadplugineventsdismissed-)
* [`addListener(RewardInterstitialAdPluginEvents.FailedToShow, ...)`](#addlistenerrewardinterstitialadplugineventsfailedtoshow-)
* [`addListener(RewardInterstitialAdPluginEvents.Showed, ...)`](#addlistenerrewardinterstitialadplugineventsshowed-)
* [Interfaces](#interfaces)
* [Type Aliases](#type-aliases)
* [Enums](#enums)## API
### initialize(...)
```typescript
initialize(options?: AdMobInitializationOptions) => Promise
```Initialize AdMob with AdMobInitializationOptions
| Param | Type | Description |
| ------------- | --------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
| **`options`** |AdMobInitializationOptions
| AdMobInitializationOptions |--------------------
### trackingAuthorizationStatus()
```typescript
trackingAuthorizationStatus() => Promise
```Confirm requestTrackingAuthorization status (iOS >14)
**Returns:**
Promise<TrackingAuthorizationStatusInterface>
--------------------
### requestTrackingAuthorization()
```typescript
requestTrackingAuthorization() => Promise
```request requestTrackingAuthorization (iOS >14).
This is deprecated method. We recommend UMP Consent.--------------------
### setApplicationMuted(...)
```typescript
setApplicationMuted(options: ApplicationMutedOptions) => Promise
```Report application mute state to AdMob SDK
| Param | Type |
| ------------- | --------------------------------------------------------------------------- |
| **`options`** |ApplicationMutedOptions
|--------------------
### setApplicationVolume(...)
```typescript
setApplicationVolume(options: ApplicationVolumeOptions) => Promise
```Report application volume to AdMob SDK
| Param | Type |
| ------------- | ----------------------------------------------------------------------------- |
| **`options`** |ApplicationVolumeOptions
|--------------------
### showBanner(...)
```typescript
showBanner(options: BannerAdOptions) => Promise
```Show a banner Ad
| Param | Type | Description |
| ------------- | ----------------------------------------------------------- | ---------------------------------- |
| **`options`** |BannerAdOptions
| AdOptions |--------------------
### hideBanner()
```typescript
hideBanner() => Promise
```Hide the banner, remove it from screen, but can show it later
--------------------
### resumeBanner()
```typescript
resumeBanner() => Promise
```Resume the banner, show it after hide
--------------------
### removeBanner()
```typescript
removeBanner() => Promise
```Destroy the banner, remove it from screen.
--------------------
### addListener(BannerAdPluginEvents.SizeChanged, ...)
```typescript
addListener(eventName: BannerAdPluginEvents.SizeChanged, listenerFunc: (info: AdMobBannerSize) => void) => Promise
```| Param | Type | Description |
| ------------------ | --------------------------------------------------------------------------------- | ------------------- |
| **`eventName`** |BannerAdPluginEvents.SizeChanged
| bannerAdSizeChanged |
| **`listenerFunc`** |(info: AdMobBannerSize) => void
| |**Returns:**
Promise<PluginListenerHandle>
--------------------
### addListener(BannerAdPluginEvents.Loaded, ...)
```typescript
addListener(eventName: BannerAdPluginEvents.Loaded, listenerFunc: () => void) => Promise
```Notice: request loaded Banner ad
| Param | Type | Description |
| ------------------ | ---------------------------------------------------------------------------- | -------------- |
| **`eventName`** |BannerAdPluginEvents.Loaded
| bannerAdLoaded |
| **`listenerFunc`** |() => void
| |**Returns:**
Promise<PluginListenerHandle>
--------------------
### addListener(BannerAdPluginEvents.FailedToLoad, ...)
```typescript
addListener(eventName: BannerAdPluginEvents.FailedToLoad, listenerFunc: (info: AdMobError) => void) => Promise
```Notice: request failed Banner ad
| Param | Type | Description |
| ------------------ | ---------------------------------------------------------------------------------- | -------------------- |
| **`eventName`** |BannerAdPluginEvents.FailedToLoad
| bannerAdFailedToLoad |
| **`listenerFunc`** |(info: AdMobError) => void
| |**Returns:**
Promise<PluginListenerHandle>
--------------------
### addListener(BannerAdPluginEvents.Opened, ...)
```typescript
addListener(eventName: BannerAdPluginEvents.Opened, listenerFunc: () => void) => Promise
```Notice: full-screen banner view will be presented in response to the user clicking on an ad.
| Param | Type | Description |
| ------------------ | ---------------------------------------------------------------------------- | -------------- |
| **`eventName`** |BannerAdPluginEvents.Opened
| bannerAdOpened |
| **`listenerFunc`** |() => void
| |**Returns:**
Promise<PluginListenerHandle>
--------------------
### addListener(BannerAdPluginEvents.Closed, ...)
```typescript
addListener(eventName: BannerAdPluginEvents.Closed, listenerFunc: () => void) => Promise
```Notice: The full-screen banner view will been dismissed.
| Param | Type | Description |
| ------------------ | ---------------------------------------------------------------------------- | -------------- |
| **`eventName`** |BannerAdPluginEvents.Closed
| bannerAdClosed |
| **`listenerFunc`** |() => void
| |**Returns:**
Promise<PluginListenerHandle>
--------------------
### addListener(BannerAdPluginEvents.AdImpression, ...)
```typescript
addListener(eventName: BannerAdPluginEvents.AdImpression, listenerFunc: () => void) => Promise
```Unimplemented
| Param | Type | Description |
| ------------------ | ---------------------------------------------------------------------------------- | ------------ |
| **`eventName`** |BannerAdPluginEvents.AdImpression
| AdImpression |
| **`listenerFunc`** |() => void
| |**Returns:**
Promise<PluginListenerHandle>
--------------------
### requestConsentInfo(...)
```typescript
requestConsentInfo(options?: AdmobConsentRequestOptions) => Promise
```Request user consent information
| Param | Type | Description |
| ------------- | --------------------------------------------------------------------------------- | --------------------- |
| **`options`** |AdmobConsentRequestOptions
| ConsentRequestOptions |**Returns:**
Promise<AdmobConsentInfo>
--------------------
### showConsentForm()
```typescript
showConsentForm() => Promise
```Shows a google user consent form (rendered from your GDPR message config).
**Returns:**
Promise<AdmobConsentInfo>
--------------------
### resetConsentInfo()
```typescript
resetConsentInfo() => Promise
```Resets the UMP SDK state. Call requestConsentInfo function again to allow user modify their consent
--------------------
### prepareInterstitial(...)
```typescript
prepareInterstitial(options: AdOptions) => Promise
```Prepare interstitial banner
| Param | Type | Description |
| ------------- | ----------------------------------------------- | ---------------------------------- |
| **`options`** |AdOptions
| AdOptions |**Returns:**
Promise<AdLoadInfo>
--------------------
### showInterstitial()
```typescript
showInterstitial() => Promise
```Show interstitial ad when it’s ready
--------------------
### addListener(InterstitialAdPluginEvents.FailedToLoad, ...)
```typescript
addListener(eventName: InterstitialAdPluginEvents.FailedToLoad, listenerFunc: (error: AdMobError) => void) => Promise
```| Param | Type |
| ------------------ | ---------------------------------------------------------------------------------------------- |
| **`eventName`** |InterstitialAdPluginEvents.FailedToLoad
|
| **`listenerFunc`** |(error: AdMobError) => void
|**Returns:**
Promise<PluginListenerHandle>
--------------------
### addListener(InterstitialAdPluginEvents.Loaded, ...)
```typescript
addListener(eventName: InterstitialAdPluginEvents.Loaded, listenerFunc: (info: AdLoadInfo) => void) => Promise
```| Param | Type |
| ------------------ | ---------------------------------------------------------------------------------------- |
| **`eventName`** |InterstitialAdPluginEvents.Loaded
|
| **`listenerFunc`** |(info: AdLoadInfo) => void
|**Returns:**
Promise<PluginListenerHandle>
--------------------
### addListener(InterstitialAdPluginEvents.Dismissed, ...)
```typescript
addListener(eventName: InterstitialAdPluginEvents.Dismissed, listenerFunc: () => void) => Promise
```| Param | Type |
| ------------------ | ------------------------------------------------------------------------------------------- |
| **`eventName`** |InterstitialAdPluginEvents.Dismissed
|
| **`listenerFunc`** |() => void
|**Returns:**
Promise<PluginListenerHandle>
--------------------
### addListener(InterstitialAdPluginEvents.FailedToShow, ...)
```typescript
addListener(eventName: InterstitialAdPluginEvents.FailedToShow, listenerFunc: (error: AdMobError) => void) => Promise
```| Param | Type |
| ------------------ | ---------------------------------------------------------------------------------------------- |
| **`eventName`** |InterstitialAdPluginEvents.FailedToShow
|
| **`listenerFunc`** |(error: AdMobError) => void
|**Returns:**
Promise<PluginListenerHandle>
--------------------
### addListener(InterstitialAdPluginEvents.Showed, ...)
```typescript
addListener(eventName: InterstitialAdPluginEvents.Showed, listenerFunc: () => void) => Promise
```| Param | Type |
| ------------------ | ---------------------------------------------------------------------------------------- |
| **`eventName`** |InterstitialAdPluginEvents.Showed
|
| **`listenerFunc`** |() => void
|**Returns:**
Promise<PluginListenerHandle>
--------------------
### prepareRewardVideoAd(...)
```typescript
prepareRewardVideoAd(options: RewardAdOptions) => Promise
```Prepare a reward video ad
| Param | Type | Description |
| ------------- | ----------------------------------------------------------- | ---------------------------------------------- |
| **`options`** |RewardAdOptions
| RewardAdOptions |**Returns:**
Promise<AdLoadInfo>
--------------------
### showRewardVideoAd()
```typescript
showRewardVideoAd() => Promise
```Show a reward video ad
**Returns:**
Promise<AdMobRewardItem>
--------------------
### addListener(RewardAdPluginEvents.FailedToLoad, ...)
```typescript
addListener(eventName: RewardAdPluginEvents.FailedToLoad, listenerFunc: (error: AdMobError) => void) => Promise
```| Param | Type |
| ------------------ | ---------------------------------------------------------------------------------- |
| **`eventName`** |RewardAdPluginEvents.FailedToLoad
|
| **`listenerFunc`** |(error: AdMobError) => void
|**Returns:**
Promise<PluginListenerHandle>
--------------------
### addListener(RewardAdPluginEvents.Loaded, ...)
```typescript
addListener(eventName: RewardAdPluginEvents.Loaded, listenerFunc: (info: AdLoadInfo) => void) => Promise
```| Param | Type |
| ------------------ | ---------------------------------------------------------------------------- |
| **`eventName`** |RewardAdPluginEvents.Loaded
|
| **`listenerFunc`** |(info: AdLoadInfo) => void
|**Returns:**
Promise<PluginListenerHandle>
--------------------
### addListener(RewardAdPluginEvents.Rewarded, ...)
```typescript
addListener(eventName: RewardAdPluginEvents.Rewarded, listenerFunc: (reward: AdMobRewardItem) => void) => Promise
```| Param | Type |
| ------------------ | -------------------------------------------------------------------------------- |
| **`eventName`** |RewardAdPluginEvents.Rewarded
|
| **`listenerFunc`** |(reward: AdMobRewardItem) => void
|**Returns:**
Promise<PluginListenerHandle>
--------------------
### addListener(RewardAdPluginEvents.Dismissed, ...)
```typescript
addListener(eventName: RewardAdPluginEvents.Dismissed, listenerFunc: () => void) => Promise
```| Param | Type |
| ------------------ | ------------------------------------------------------------------------------- |
| **`eventName`** |RewardAdPluginEvents.Dismissed
|
| **`listenerFunc`** |() => void
|**Returns:**
Promise<PluginListenerHandle>
--------------------
### addListener(RewardAdPluginEvents.FailedToShow, ...)
```typescript
addListener(eventName: RewardAdPluginEvents.FailedToShow, listenerFunc: (error: AdMobError) => void) => Promise
```| Param | Type |
| ------------------ | ---------------------------------------------------------------------------------- |
| **`eventName`** |RewardAdPluginEvents.FailedToShow
|
| **`listenerFunc`** |(error: AdMobError) => void
|**Returns:**
Promise<PluginListenerHandle>
--------------------
### addListener(RewardAdPluginEvents.Showed, ...)
```typescript
addListener(eventName: RewardAdPluginEvents.Showed, listenerFunc: () => void) => Promise
```| Param | Type |
| ------------------ | ---------------------------------------------------------------------------- |
| **`eventName`** |RewardAdPluginEvents.Showed
|
| **`listenerFunc`** |() => void
|**Returns:**
Promise<PluginListenerHandle>
--------------------
### prepareRewardInterstitialAd(...)
```typescript
prepareRewardInterstitialAd(options: RewardInterstitialAdOptions) => Promise
```Prepare a reward video ad
| Param | Type | Description |
| ------------- | ----------------------------------------------------------------------------------- | ---------------------------------------------- |
| **`options`** |RewardInterstitialAdOptions
| RewardAdOptions |**Returns:**
Promise<AdLoadInfo>
--------------------
### showRewardInterstitialAd()
```typescript
showRewardInterstitialAd() => Promise
```Show a reward video ad
**Returns:**
Promise<AdMobRewardInterstitialItem>
--------------------
### addListener(RewardInterstitialAdPluginEvents.FailedToLoad, ...)
```typescript
addListener(eventName: RewardInterstitialAdPluginEvents.FailedToLoad, listenerFunc: (error: AdMobError) => void) => Promise
```| Param | Type |
| ------------------ | ---------------------------------------------------------------------------------------------------------- |
| **`eventName`** |RewardInterstitialAdPluginEvents.FailedToLoad
|
| **`listenerFunc`** |(error: AdMobError) => void
|**Returns:**
Promise<PluginListenerHandle>
--------------------
### addListener(RewardInterstitialAdPluginEvents.Loaded, ...)
```typescript
addListener(eventName: RewardInterstitialAdPluginEvents.Loaded, listenerFunc: (info: AdLoadInfo) => void) => Promise
```| Param | Type |
| ------------------ | ---------------------------------------------------------------------------------------------------- |
| **`eventName`** |RewardInterstitialAdPluginEvents.Loaded
|
| **`listenerFunc`** |(info: AdLoadInfo) => void
|**Returns:**
Promise<PluginListenerHandle>
--------------------
### addListener(RewardInterstitialAdPluginEvents.Rewarded, ...)
```typescript
addListener(eventName: RewardInterstitialAdPluginEvents.Rewarded, listenerFunc: (reward: AdMobRewardInterstitialItem) => void) => Promise
```| Param | Type |
| ------------------ | -------------------------------------------------------------------------------------------------------- |
| **`eventName`** |RewardInterstitialAdPluginEvents.Rewarded
|
| **`listenerFunc`** |(reward: AdMobRewardInterstitialItem) => void
|**Returns:**
Promise<PluginListenerHandle>
--------------------
### addListener(RewardInterstitialAdPluginEvents.Dismissed, ...)
```typescript
addListener(eventName: RewardInterstitialAdPluginEvents.Dismissed, listenerFunc: () => void) => Promise
```| Param | Type |
| ------------------ | ------------------------------------------------------------------------------------------------------- |
| **`eventName`** |RewardInterstitialAdPluginEvents.Dismissed
|
| **`listenerFunc`** |() => void
|**Returns:**
Promise<PluginListenerHandle>
--------------------
### addListener(RewardInterstitialAdPluginEvents.FailedToShow, ...)
```typescript
addListener(eventName: RewardInterstitialAdPluginEvents.FailedToShow, listenerFunc: (error: AdMobError) => void) => Promise
```| Param | Type |
| ------------------ | ---------------------------------------------------------------------------------------------------------- |
| **`eventName`** |RewardInterstitialAdPluginEvents.FailedToShow
|
| **`listenerFunc`** |(error: AdMobError) => void
|**Returns:**
Promise<PluginListenerHandle>
--------------------
### addListener(RewardInterstitialAdPluginEvents.Showed, ...)
```typescript
addListener(eventName: RewardInterstitialAdPluginEvents.Showed, listenerFunc: () => void) => Promise
```| Param | Type |
| ------------------ | ---------------------------------------------------------------------------------------------------- |
| **`eventName`** |RewardInterstitialAdPluginEvents.Showed
|
| **`listenerFunc`** |() => void
|**Returns:**
Promise<PluginListenerHandle>
--------------------
### Interfaces
#### AdMobInitializationOptions
| Prop | Type | Description |
| ---------------------------------- | ----------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`testingDevices`** |string[]
| An Array of devices IDs that will be marked as tested devices if {@link AdMobInitializationOptions.initializeForTesting} is true (Real Ads will be served to Testing devices, but they will not count as 'real'). |
| **`initializeForTesting`** |boolean
| If set to true, the devices on {@link AdMobInitializationOptions.testingDevices} will be registered to receive test production ads. |
| **`tagForChildDirectedTreatment`** |boolean
| For purposes of the Children's Online Privacy Protection Act (COPPA), there is a setting called tagForChildDirectedTreatment. |
| **`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. |
| **`maxAdContentRating`** |MaxAdContentRating
| As an app developer, you can indicate whether you want Google to treat your content as child-directed when you make an ad request. |#### TrackingAuthorizationStatusInterface
| Prop | Type |
| ------------ | ------------------------------------------------------------------------ |
| **`status`** |'authorized' \| 'denied' \| 'notDetermined' \| 'restricted'
|#### ApplicationMutedOptions
| Prop | Type | Description |
| ----------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`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. |#### ApplicationVolumeOptions
| Prop | Type | Description |
| ------------ | ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **`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. enable set 0.0 - 1.0, any float allowed. |#### BannerAdOptions
This interface extends AdOptions
| Prop | Type | Description |
| -------------- | ------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| **`adSize`** |BannerAdSize
| Banner Ad Size, defaults to ADAPTIVE_BANNER. IT can be: ADAPTIVE_BANNER, SMART_BANNER, BANNER, MEDIUM_RECTANGLE, FULL_BANNER, LEADERBOARD |
| **`position`** |BannerAdPosition
| Set Banner Ad position. TOP_CENTER or CENTER or BOTTOM_CENTER |#### PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| **`remove`** |() => Promise<void>
|#### AdMobBannerSize
When notice listener of OnAdLoaded, you can get banner size.
| Prop | Type |
| ------------ | ------------------- |
| **`width`** |number
|
| **`height`** |number
|#### AdMobError
For more information
https://developers.google.com/android/reference/com/google/android/gms/ads/AdError| Prop | Type | Description |
| ------------- | ------------------- | -------------------------------------- |
| **`code`** |number
| Gets the error's code. |
| **`message`** |string
| Gets the message describing the error. |#### AdmobConsentInfo
| Prop | Type | Description |
| ---------------------------- | ----------------------------------------------------------------- | ----------------------------------------------------- |
| **`status`** |AdmobConsentStatus
| The consent status of the user. |
| **`isConsentFormAvailable`** |boolean
| If `true` a consent form is available and vice versa. |#### AdmobConsentRequestOptions
| Prop | Type | Description |
| ----------------------------- | --------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| **`debugGeography`** |AdmobConsentDebugGeography
| Sets the debug geography to test the consent locally. |
| **`testDeviceIdentifiers`** |string[]
| An array of test device IDs to allow. Note: On iOS, the ID may renew if you uninstall and reinstall the app. |
| **`tagForUnderAgeOfConsent`** |boolean
| Set to `true` to provide the option for the user to accept being shown personalized ads. |#### AdLoadInfo
| Prop | Type |
| -------------- | ------------------- |
| **`adUnitId`** |string
|#### AdOptions
| Prop | Type | Description |
| --------------- | -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| **`adId`** |string
| The ad unit ID that you want to request |
| **`isTesting`** |boolean
| You can use test mode of ad. |
| **`margin`** |number
| Margin Banner. Default is 0px; If position is BOTTOM_CENTER, margin is be margin-bottom. If position is TOP_CENTER, margin is be margin-top. |
| **`npa`** |boolean
| The default behavior of the Google Mobile Ads SDK is to serve personalized ads. Set this to true to request Non-Personalized Ads |#### RewardAdOptions
| Prop | Type | Description |
| --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`ssv`** |AtLeastOne<{ /** * An optional UserId to pass to your SSV callback function. */ userId: string; /** * An optional custom set of data to pass to your SSV callback function. */ customData: string; }>
| If you have enabled SSV in your AdMob Application. You can provide customData or a userId be passed to your callback to do further processing on. *Important* You *HAVE* to define one of them. |#### AdMobRewardItem
For more information
https://developers.google.com/admob/android/rewarded-video-adapters?hl=en| Prop | Type | Description |
| ------------ | ------------------- | ------------------------ |
| **`type`** |string
| Rewarded type user got |
| **`amount`** |number
| Rewarded amount user got |#### RewardInterstitialAdOptions
| Prop | Type | Description |
| --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`ssv`** |AtLeastOne<{ /** * An optional UserId to pass to your SSV callback function. */ userId: string; /** * An optional custom set of data to pass to your SSV callback function. */ customData: string; }>
| If you have enabled SSV in your AdMob Application. You can provide customData or a userId be passed to your callback to do further processing on. *Important* You *HAVE* to define one of them. |#### AdMobRewardInterstitialItem
For more information
https://developers.google.com/admob/android/rewarded-video-adapters?hl=en| Prop | Type | Description |
| ------------ | ------------------- | ------------------------ |
| **`type`** |string
| Rewarded type user got |
| **`amount`** |number
| Rewarded amount user got |### 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. |#### 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'
| |#### BannerAdPosition
| Members | Value | Description |
| ------------------- | ---------------------------- | ----------------------------------------- |
| **`TOP_CENTER`** |'TOP_CENTER'
| Banner position be top-center |
| **`CENTER`** |'CENTER'
| Banner position be center |
| **`BOTTOM_CENTER`** |'BOTTOM_CENTER'
| Banner position be bottom-center(default) |#### BannerAdPluginEvents
| Members | Value | Description |
| ------------------ | ----------------------------------- | ------------------------------------------------------------------------------------------------------ |
| **`SizeChanged`** |"bannerAdSizeChanged"
| |
| **`Loaded`** |"bannerAdLoaded"
| |
| **`FailedToLoad`** |"bannerAdFailedToLoad"
| |
| **`Opened`** |"bannerAdOpened"
| Open "Adsense" Event after user click banner |
| **`Closed`** |"bannerAdClosed"
| Close "Adsense" Event after user click banner |
| **`AdImpression`** |"bannerAdImpression"
| Similarly, this method should be called when an impression is recorded for the ad by the mediated SDK. |#### 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. |#### 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. |#### InterstitialAdPluginEvents
| Members | Value | Description |
| ------------------ | ----------------------------------------- | -------------------------------------------------------------------------------------- |
| **`Loaded`** |'interstitialAdLoaded'
| Emits after trying to prepare and Interstitial, when it is loaded and ready to be show |
| **`FailedToLoad`** |'interstitialAdFailedToLoad'
| Emits after trying to prepare and Interstitial, when it could not be loaded |
| **`Showed`** |'interstitialAdShowed'
| Emits when the Interstitial ad is visible to the user |
| **`FailedToShow`** |'interstitialAdFailedToShow'
| Emits when the Interstitial ad is failed to show |
| **`Dismissed`** |'interstitialAdDismissed'
| Emits when the Interstitial ad is not visible to the user anymore. |#### RewardAdPluginEvents
| Members | Value | Description |
| ------------------ | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **`Loaded`** |'onRewardedVideoAdLoaded'
| Emits after trying to prepare a RewardAd and the Video is loaded and ready to be show |
| **`FailedToLoad`** |'onRewardedVideoAdFailedToLoad'
| Emits after trying to prepare a RewardAd when it could not be loaded |
| **`Showed`** |'onRewardedVideoAdShowed'
| Emits when the AdReward video is visible to the user |
| **`FailedToShow`** |'onRewardedVideoAdFailedToShow'
| Emits when the AdReward video is failed to show |
| **`Dismissed`** |'onRewardedVideoAdDismissed'
| Emits when the AdReward video is not visible to the user anymore. **Important**: This has nothing to do with the reward it self. This event will emits in this two cases: 1. The user starts the video ad but close it before the reward emit. 2. The user start the video and see it until end, then gets the reward and after that the ad is closed. |
| **`Rewarded`** |'onRewardedVideoAdReward'
| Emits when user get rewarded from AdReward |#### RewardInterstitialAdPluginEvents
| Members | Value | Description |
| ------------------ | --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **`Loaded`** |'onRewardedInterstitialAdLoaded'
| Emits after trying to prepare a RewardAd and the Video is loaded and ready to be show |
| **`FailedToLoad`** |'onRewardedInterstitialAdFailedToLoad'
| Emits after trying to prepare a RewardAd when it could not be loaded |
| **`Showed`** |'onRewardedInterstitialAdShowed'
| Emits when the AdReward video is visible to the user |
| **`FailedToShow`** |'onRewardedInterstitialAdFailedToShow'
| Emits when the AdReward video is failed to show |
| **`Dismissed`** |'onRewardedInterstitialAdDismissed'
| Emits when the AdReward video is not visible to the user anymore. **Important**: This has nothing to do with the reward it self. This event will emits in this two cases: 1. The user starts the video ad but close it before the reward emit. 2. The user start the video and see it until end, then gets the reward and after that the ad is closed. |
| **`Rewarded`** |'onRewardedInterstitialAdReward'
| Emits when user get rewarded from AdReward |## 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](./LICENSE).