Security News
Highlights from the 2024 Rails Community Survey
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
@capacitor-community/admob
Advanced tools
@capacitor-community/admob
Capacitor community plugin for native AdMob.
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
Banner | Interstitial | Reward | |
---|---|---|---|
iOS | |||
Android |
% npm install --save @capacitor-community/admob@next
% npx cap update
In file android/app/src/main/java/**/**/MainActivity.java
, add the plugin to the initialization list:
public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
registerPlugin(com.getcapacitor.community.admob.AdMob.class);
}
}
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.
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.
import { AdMob } from '@capacitor-community/admob';
export async function initialize(): Promise<void> {
AdMob.initialize({
requestTrackingAuthorization: true,
testingDevices: ['2077ef9a63d2b398840261c8221a0c9b'],
initializeForTesting: true,
});
}
You can use option requestTrackingAuthorization
. This change permission to require AppTrackingTransparency
in iOS >= 14:
https://developers.google.com/admob/ios/ios14
Default value is true
. If you don't want to track, set requestTrackingAuthorization false
.
Send and 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
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);
}
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
};
await AdMob.prepareInterstitial(options);
await AdMob.showInterstitial();
}
import { AdMob, AdOptions, 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: AdOptions = {
adId: 'YOUR ADID',
// isTesting: true
// npa: true
};
await AdMob.prepareRewardVideoAd(options);
const rewardItem = await AdMob.showRewardVideoAd();
}
initialize(...)
showBanner(...)
hideBanner()
resumeBanner()
removeBanner()
addListener(BannerAdPluginEvents.SizeChanged, ...)
addListener(BannerAdPluginEvents.Loaded, ...)
addListener(BannerAdPluginEvents.FailedToLoad, ...)
addListener(BannerAdPluginEvents.Opened, ...)
addListener(BannerAdPluginEvents.Closed, ...)
addListener(BannerAdPluginEvents.AdImpression, ...)
prepareInterstitial(...)
showInterstitial()
addListener(InterstitialAdPluginEvents.FailedToLoad, ...)
addListener(InterstitialAdPluginEvents.Loaded, ...)
addListener(InterstitialAdPluginEvents.Dismissed, ...)
addListener(InterstitialAdPluginEvents.FailedToShow, ...)
addListener(InterstitialAdPluginEvents.Showed, ...)
prepareRewardVideoAd(...)
showRewardVideoAd()
addListener(RewardAdPluginEvents.FailedToLoad, ...)
addListener(RewardAdPluginEvents.Loaded, ...)
addListener(RewardAdPluginEvents.Rewarded, ...)
addListener(RewardAdPluginEvents.Dismissed, ...)
addListener(RewardAdPluginEvents.FailedToShow, ...)
addListener(RewardAdPluginEvents.Showed, ...)
initialize(options: AdMobInitializationOptions) => Promise<void>
Initialize AdMob with AdMobInitializationOptions
Param | Type | Description |
---|---|---|
options | AdMobInitializationOptions | AdMobInitializationOptions |
Since: 1.1.2
showBanner(options: BannerAdOptions) => Promise<void>
Show a banner Ad
Param | Type | Description |
---|---|---|
options | BannerAdOptions | AdOptions |
Since: 1.1.2
hideBanner() => Promise<void>
Hide the banner, remove it from screen, but can show it later
Since: 1.1.2
resumeBanner() => Promise<void>
Resume the banner, show it after hide
Since: 1.1.2
removeBanner() => Promise<void>
Destroy the banner, remove it from screen.
Since: 1.1.2
addListener(eventName: BannerAdPluginEvents.SizeChanged, listenerFunc: (info: AdMobBannerSize) => void) => PluginListenerHandle
Param | Type | Description |
---|---|---|
eventName | BannerAdPluginEvents.SizeChanged | bannerAdSizeChanged |
listenerFunc | (info: AdMobBannerSize) => void |
Returns: PluginListenerHandle
Since: 3.0.0
addListener(eventName: BannerAdPluginEvents.Loaded, listenerFunc: () => void) => PluginListenerHandle
Notice: request loaded Banner ad
Param | Type | Description |
---|---|---|
eventName | BannerAdPluginEvents.Loaded | bannerAdLoaded |
listenerFunc | () => void |
Returns: PluginListenerHandle
Since: 3.0.0
addListener(eventName: BannerAdPluginEvents.FailedToLoad, listenerFunc: (info: AdMobError) => void) => PluginListenerHandle
Notice: request failed Banner ad
Param | Type | Description |
---|---|---|
eventName | BannerAdPluginEvents.FailedToLoad | bannerAdFailedToLoad |
listenerFunc | (info: AdMobError) => void |
Returns: PluginListenerHandle
Since: 3.0.0
addListener(eventName: BannerAdPluginEvents.Opened, listenerFunc: () => void) => PluginListenerHandle
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: PluginListenerHandle
Since: 3.0.0
addListener(eventName: BannerAdPluginEvents.Closed, listenerFunc: () => void) => PluginListenerHandle
Notice: The full-screen banner view will been dismissed.
Param | Type | Description |
---|---|---|
eventName | BannerAdPluginEvents.Closed | bannerAdClosed |
listenerFunc | () => void |
Returns: PluginListenerHandle
Since: 3.0.0
addListener(eventName: BannerAdPluginEvents.AdImpression, listenerFunc: () => void) => PluginListenerHandle
Unimplemented
Param | Type | Description |
---|---|---|
eventName | BannerAdPluginEvents.AdImpression | AdImpression |
listenerFunc | () => void |
Returns: PluginListenerHandle
Since: 3.0.0
prepareInterstitial(options: AdOptions) => Promise<AdLoadInfo>
Prepare interstitial banner
Param | Type | Description |
---|---|---|
options | AdOptions | AdOptions |
Returns: Promise<AdLoadInfo>
Since: 1.1.2
showInterstitial() => Promise<void>
Show interstitial ad when it’s ready
Since: 1.1.2
addListener(eventName: InterstitialAdPluginEvents.FailedToLoad, listenerFunc: (error: AdMobError) => void) => PluginListenerHandle
Param | Type |
---|---|
eventName | InterstitialAdPluginEvents.FailedToLoad |
listenerFunc | (error: AdMobError) => void |
Returns: PluginListenerHandle
addListener(eventName: InterstitialAdPluginEvents.Loaded, listenerFunc: (info: AdLoadInfo) => void) => PluginListenerHandle
Param | Type |
---|---|
eventName | InterstitialAdPluginEvents.Loaded |
listenerFunc | (info: AdLoadInfo) => void |
Returns: PluginListenerHandle
addListener(eventName: InterstitialAdPluginEvents.Dismissed, listenerFunc: () => void) => PluginListenerHandle
Param | Type |
---|---|
eventName | InterstitialAdPluginEvents.Dismissed |
listenerFunc | () => void |
Returns: PluginListenerHandle
addListener(eventName: InterstitialAdPluginEvents.FailedToShow, listenerFunc: (error: AdMobError) => void) => PluginListenerHandle
Param | Type |
---|---|
eventName | InterstitialAdPluginEvents.FailedToShow |
listenerFunc | (error: AdMobError) => void |
Returns: PluginListenerHandle
addListener(eventName: InterstitialAdPluginEvents.Showed, listenerFunc: () => void) => PluginListenerHandle
Param | Type |
---|---|
eventName | InterstitialAdPluginEvents.Showed |
listenerFunc | () => void |
Returns: PluginListenerHandle
prepareRewardVideoAd(options: AdOptions) => Promise<AdLoadInfo>
Prepare a reward video ad
Param | Type | Description |
---|---|---|
options | AdOptions | AdOptions |
Returns: Promise<AdLoadInfo>
Since: 1.1.2
showRewardVideoAd() => Promise<AdMobRewardItem>
Show a reward video ad
Returns: Promise<AdMobRewardItem>
Since: 1.1.2
addListener(eventName: RewardAdPluginEvents.FailedToLoad, listenerFunc: (error: AdMobError) => void) => PluginListenerHandle
Param | Type |
---|---|
eventName | RewardAdPluginEvents.FailedToLoad |
listenerFunc | (error: AdMobError) => void |
Returns: PluginListenerHandle
addListener(eventName: RewardAdPluginEvents.Loaded, listenerFunc: (info: AdLoadInfo) => void) => PluginListenerHandle
Param | Type |
---|---|
eventName | RewardAdPluginEvents.Loaded |
listenerFunc | (info: AdLoadInfo) => void |
Returns: PluginListenerHandle
addListener(eventName: RewardAdPluginEvents.Rewarded, listenerFunc: (reward: AdMobRewardItem) => void) => PluginListenerHandle
Param | Type |
---|---|
eventName | RewardAdPluginEvents.Rewarded |
listenerFunc | (reward: AdMobRewardItem) => void |
Returns: PluginListenerHandle
addListener(eventName: RewardAdPluginEvents.Dismissed, listenerFunc: () => void) => PluginListenerHandle
Param | Type |
---|---|
eventName | RewardAdPluginEvents.Dismissed |
listenerFunc | () => void |
Returns: PluginListenerHandle
addListener(eventName: RewardAdPluginEvents.FailedToShow, listenerFunc: (error: AdMobError) => void) => PluginListenerHandle
Param | Type |
---|---|
eventName | RewardAdPluginEvents.FailedToShow |
listenerFunc | (error: AdMobError) => void |
Returns: PluginListenerHandle
addListener(eventName: RewardAdPluginEvents.Showed, listenerFunc: () => void) => PluginListenerHandle
Param | Type |
---|---|
eventName | RewardAdPluginEvents.Showed |
listenerFunc | () => void |
Returns: PluginListenerHandle
Prop | Type | Description | Default | Since |
---|---|---|---|---|
requestTrackingAuthorization | boolean | Use or not requestTrackingAuthorization in iOS(>14) | 1.1.2 | |
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'). | 1.2.0 | |
initializeForTesting | boolean | If set to true, the devices on {@link AdMobInitializationOptions.testingDevices} will be registered to receive test production ads. | false | 1.2.0 |
This interface extends AdOptions
Prop | Type | Description | Default | Since |
---|---|---|---|---|
adSize | BannerAdSize | Banner Ad Size, defaults to ADAPTIVE_BANNER. IT can be: ADAPTIVE_BANNER, SMART_BANNER, BANNER, MEDIUM_RECTANGLE, FULL_BANNER, LEADERBOARD | ADAPTIVE_BANNER | 3.0.0 |
position | BannerAdPosition | Set Banner Ad position. TOP_CENTER or CENTER or BOTTOM_CENTER | TOP_CENTER | 1.1.2 |
Prop | Type |
---|---|
remove | () => Promise<void> |
When notice listener of OnAdLoaded, you can get banner size.
Prop | Type |
---|---|
width | number |
height | number |
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. |
Prop | Type |
---|---|
adUnitId | string |
Prop | Type | Description | Default | Since |
---|---|---|---|---|
adId | string | The ad unit ID that you want to request | 1.1.2 | |
isTesting | boolean | You can use test mode of ad. | false | 1.1.2 |
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. | 0 | 1.1.2 |
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 | false | 1.2.0 |
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 |
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). |
LEADERBOARD | 'LEADERBOARD' | Interactive Advertising Bureau (IAB) leaderboard ad size (728x90 density-independent pixels). |
MEDIUM_RECTANGLE | 'MEDIUM_RECTANGLE' | Interactive Advertising Bureau (IAB) medium rectangle ad size (300x250 density-independent pixels). |
ADAPTIVE_BANNER | 'ADAPTIVE_BANNER' | A dynamically sized banner that is full-width and auto-height. |
SMART_BANNER | 'SMART_BANNER' | Screen width x 32|50|90 |
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) |
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. |
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. |
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 |
[error] Error running update: Analyzing dependencies [!] CocoaPods could not find compatible versions for pod "Google-Mobile-Ads-SDK":
You should run pod repo update
;
Capacitor AdMob is MIT licensed.
Thanks goes to these wonderful people (emoji key):
Jean-Baptiste Malatrasi 💻 | gant02 💻 | Saninn Salas Diaz 💻 | Nico Lueg 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!
FAQs
A native plugin for AdMob
The npm package @capacitor-community/admob receives a total of 647 weekly downloads. As such, @capacitor-community/admob popularity was classified as not popular.
We found that @capacitor-community/admob demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 43 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.