@capacitor-community/admob 8.1.0 → 8.2.0-beta.pr454.sha49386d40323a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapacitorCommunityAdmob.podspec +1 -1
- package/Package.swift +1 -1
- package/README.md +129 -323
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/getcapacitor/community/admob/AdMob.java +86 -3
- package/android/src/main/java/com/getcapacitor/community/admob/banner/BannerExecutor.java +261 -141
- package/android/src/main/java/com/getcapacitor/community/admob/helpers/FullscreenPluginCallback.kt +5 -1
- package/android/src/main/java/com/getcapacitor/community/admob/interstitial/AdInterstitialExecutor.java +27 -31
- package/android/src/main/java/com/getcapacitor/community/admob/interstitial/InterstitialAdCallbackAndListeners.kt +1 -1
- package/android/src/main/java/com/getcapacitor/community/admob/models/LoadPluginEventNames.kt +2 -1
- package/android/src/main/java/com/getcapacitor/community/admob/nativeads/NativeAdExecutor.kt +378 -0
- package/android/src/main/java/com/getcapacitor/community/admob/nativeads/NativeAdFeedSessions.kt +35 -0
- package/android/src/main/java/com/getcapacitor/community/admob/nativeads/NativeAdPlacementValue.kt +44 -0
- package/android/src/main/java/com/getcapacitor/community/admob/nativeads/NativeAdPluginEvents.kt +11 -0
- package/android/src/main/java/com/getcapacitor/community/admob/nativeads/PluginNativeAdView.kt +187 -0
- package/android/src/main/java/com/getcapacitor/community/admob/rewarded/AdRewardExecutor.java +29 -33
- package/android/src/main/java/com/getcapacitor/community/admob/rewarded/RewardAdPluginEvents.kt +2 -1
- package/android/src/main/java/com/getcapacitor/community/admob/rewarded/RewardedAdCallbackAndListeners.kt +1 -1
- package/android/src/main/java/com/getcapacitor/community/admob/rewardedinterstitial/AdRewardInterstitialExecutor.java +29 -37
- package/android/src/main/java/com/getcapacitor/community/admob/rewardedinterstitial/RewardedInterstitialAdCallbackAndListeners.kt +1 -1
- package/dist/docs.json +33 -3
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +5 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/interstitial/interstitial-definitions.interface.d.ts +3 -0
- package/dist/esm/native-ads/index.d.ts +6 -0
- package/dist/esm/native-ads/index.js +4 -0
- package/dist/esm/native-ads/index.js.map +1 -0
- package/dist/esm/native-ads/native-ad-definitions.interface.d.ts +14 -0
- package/dist/esm/native-ads/native-ad-definitions.interface.js +2 -0
- package/dist/esm/native-ads/native-ad-definitions.interface.js.map +1 -0
- package/dist/esm/native-ads/native-ad-element.d.ts +9 -0
- package/dist/esm/native-ads/native-ad-element.js +53 -0
- package/dist/esm/native-ads/native-ad-element.js.map +1 -0
- package/dist/esm/native-ads/native-ad-event.interface.d.ts +5 -0
- package/dist/esm/native-ads/native-ad-event.interface.js +2 -0
- package/dist/esm/native-ads/native-ad-event.interface.js.map +1 -0
- package/dist/esm/native-ads/native-ad-feed.d.ts +72 -0
- package/dist/esm/native-ads/native-ad-feed.js +568 -0
- package/dist/esm/native-ads/native-ad-feed.js.map +1 -0
- package/dist/esm/native-ads/native-ad-geometry.d.ts +8 -0
- package/dist/esm/native-ads/native-ad-geometry.js +91 -0
- package/dist/esm/native-ads/native-ad-geometry.js.map +1 -0
- package/dist/esm/native-ads/native-ad-options.interface.d.ts +36 -0
- package/dist/esm/native-ads/native-ad-options.interface.js +2 -0
- package/dist/esm/native-ads/native-ad-options.interface.js.map +1 -0
- package/dist/esm/native-ads/native-ad-placement.interface.d.ts +26 -0
- package/dist/esm/native-ads/native-ad-placement.interface.js +2 -0
- package/dist/esm/native-ads/native-ad-placement.interface.js.map +1 -0
- package/dist/esm/native-ads/native-ad-plugin-events.enum.d.ts +9 -0
- package/dist/esm/native-ads/native-ad-plugin-events.enum.js +11 -0
- package/dist/esm/native-ads/native-ad-plugin-events.enum.js.map +1 -0
- package/dist/esm/native-ads/native-ad-style.interface.d.ts +30 -0
- package/dist/esm/native-ads/native-ad-style.interface.js +2 -0
- package/dist/esm/native-ads/native-ad-style.interface.js.map +1 -0
- package/dist/esm/native-ads/native-ad-template.enum.d.ts +11 -0
- package/dist/esm/native-ads/native-ad-template.enum.js +13 -0
- package/dist/esm/native-ads/native-ad-template.enum.js.map +1 -0
- package/dist/esm/reward/reward-ad-plugin-events.enum.d.ts +4 -0
- package/dist/esm/reward/reward-ad-plugin-events.enum.js +4 -0
- package/dist/esm/reward/reward-ad-plugin-events.enum.js.map +1 -1
- package/dist/esm/reward/reward-definitions.interface.d.ts +8 -0
- package/dist/esm/reward-interstitial/reward-interstitial-definitions.interface.d.ts +3 -0
- package/dist/esm/web.d.ts +9 -1
- package/dist/esm/web.js +15 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +755 -1
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +755 -1
- package/dist/plugin.js.map +1 -1
- package/docs/app-open.md +53 -0
- package/docs/banner.md +100 -0
- package/docs/configuration.md +30 -0
- package/docs/consent.md +80 -0
- package/docs/events.md +76 -0
- package/docs/interstitial.md +47 -0
- package/docs/migration.md +146 -0
- package/docs/native-ads.md +161 -0
- package/docs/rewarded.md +148 -0
- package/docs/testing.md +67 -0
- package/ios/Sources/AdMobPlugin/AdMobPlugin.swift +106 -41
- package/ios/Sources/AdMobPlugin/AppOpen/AppOpenAdManager.swift +1 -1
- package/ios/Sources/AdMobPlugin/Banner/BannerExecutor.swift +1 -1
- package/ios/Sources/AdMobPlugin/Interstitial/AdInterstitialExecutor.swift +6 -3
- package/ios/Sources/AdMobPlugin/NativeAds/NativeAdExecutor.swift +354 -0
- package/ios/Sources/AdMobPlugin/NativeAds/NativeAdFeedSessions.swift +34 -0
- package/ios/Sources/AdMobPlugin/NativeAds/NativeAdPlacementValue.swift +50 -0
- package/ios/Sources/AdMobPlugin/NativeAds/NativeAdPluginEvents.swift +11 -0
- package/ios/Sources/AdMobPlugin/NativeAds/NativeAdScrollTracker.swift +66 -0
- package/ios/Sources/AdMobPlugin/NativeAds/NativeAdValues.swift +27 -0
- package/ios/Sources/AdMobPlugin/NativeAds/PluginNativeAdView.swift +187 -0
- package/ios/Sources/AdMobPlugin/Rewarded/AdRewardExecutor.swift +10 -3
- package/ios/Sources/AdMobPlugin/Rewarded/RewardAdPluginEvents.swift +1 -0
- package/ios/Sources/AdMobPlugin/RewardedInterstitial/AdRewardInterstitialExecutor.swift +6 -3
- package/ios/Tests/AdMobPluginTests/AdMobPluginTests.swift +82 -10
- package/ios/Tests/AdMobPluginTests/NativeAdScrollTrackerTests.swift +47 -0
- package/package.json +4 -1
|
@@ -15,6 +15,6 @@ Pod::Spec.new do |s|
|
|
|
15
15
|
s.swift_version = '5.1'
|
|
16
16
|
s.static_framework = true
|
|
17
17
|
s.dependency 'Capacitor'
|
|
18
|
-
s.dependency 'Google-Mobile-Ads-SDK', '13.
|
|
18
|
+
s.dependency 'Google-Mobile-Ads-SDK', '13.11.0'
|
|
19
19
|
s.dependency 'GoogleUserMessagingPlatform', '~> 3.1'
|
|
20
20
|
end
|
package/Package.swift
CHANGED
|
@@ -11,7 +11,7 @@ let package = Package(
|
|
|
11
11
|
],
|
|
12
12
|
dependencies: [
|
|
13
13
|
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0"),
|
|
14
|
-
.package(url: "https://github.com/googleads/swift-package-manager-google-mobile-ads.git", exact: "13.
|
|
14
|
+
.package(url: "https://github.com/googleads/swift-package-manager-google-mobile-ads.git", exact: "13.11.0"),
|
|
15
15
|
.package(url: "https://github.com/googleads/swift-package-manager-google-user-messaging-platform.git", .upToNextMinor(from: "3.1.0"))
|
|
16
16
|
],
|
|
17
17
|
targets: [
|
package/README.md
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
<!-- rdlabo-docs-omit -->
|
|
1
2
|
<p align="center"><br><img src="https://user-images.githubusercontent.com/236501/85893648-1c92e880-b7a8-11ea-926d-95355b8175c7.png" width="128" height="128" /></p>
|
|
2
3
|
<h3 align="center">AdMob</h3>
|
|
3
4
|
<p align="center"><strong><code>@capacitor-community/admob</code></strong></p>
|
|
@@ -5,6 +6,10 @@
|
|
|
5
6
|
Capacitor community plugin for native AdMob.
|
|
6
7
|
</p>
|
|
7
8
|
|
|
9
|
+
<p align="center">
|
|
10
|
+
<strong><a href="https://docs.rdlabo.dev/projects/capacitor-admob">Read the full documentation</a></strong>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
8
13
|
<p align="center">
|
|
9
14
|
<img src="https://img.shields.io/maintenance/yes/2026?style=flat-square" />
|
|
10
15
|
<a href="https://www.npmjs.com/package/@capacitor-community/admob"><img src="https://img.shields.io/npm/l/@capacitor-community/admob?style=flat-square" /></a>
|
|
@@ -15,10 +20,10 @@
|
|
|
15
20
|
|
|
16
21
|
## Maintainers
|
|
17
22
|
|
|
18
|
-
| Maintainer | GitHub | Social |
|
|
19
|
-
| ------------------- | ------------------------------------------------ | ----------------------------------------------- |
|
|
20
|
-
| Masahiko Sakakibara | [rdlabo](https://github.com/rdlabo) | [@rdlabo](https://twitter.com/rdlabo) |
|
|
21
|
-
| Saninn Salas Diaz | [Saninn Salas Diaz](https://github.com/distante) | [@SaninnSalas](https://twitter.com/SaninnSalas) |
|
|
23
|
+
| Maintainer | GitHub | Social | Website |
|
|
24
|
+
| ------------------- | ------------------------------------------------ | ----------------------------------------------- | ----------------------------------------------- |
|
|
25
|
+
| Masahiko Sakakibara | [rdlabo](https://github.com/rdlabo) | [@rdlabo](https://twitter.com/rdlabo) | [rdlabo.dev](https://rdlabo.dev/) |
|
|
26
|
+
| Saninn Salas Diaz | [Saninn Salas Diaz](https://github.com/distante) | [@SaninnSalas](https://twitter.com/SaninnSalas) | — |
|
|
22
27
|
|
|
23
28
|
Maintenance Status: Actively Maintained
|
|
24
29
|
|
|
@@ -41,51 +46,60 @@ Made with [contributors-img](https://contrib.rocks).
|
|
|
41
46
|
| **iOS** |  |  |  |  |
|
|
42
47
|
| **Android** |  |  |  |  |
|
|
43
48
|
|
|
49
|
+
<!-- /rdlabo-docs-omit -->
|
|
50
|
+
|
|
51
|
+
## Overview
|
|
52
|
+
|
|
53
|
+
Capacitor community plugin for native AdMob. This plugin wraps the Google Mobile Ads SDK for iOS and Android so you can display banner, interstitial, rewarded, rewarded interstitial, and app open ads in Capacitor apps. It also covers Google User Messaging Platform (UMP) consent and App Tracking Transparency helpers on iOS.
|
|
54
|
+
|
|
44
55
|
## Installation
|
|
45
56
|
|
|
46
|
-
|
|
57
|
+
This plugin already ships Google Mobile Ads SDK. Install the package, then add your AdMob **application** ID in AndroidManifest / Info.plist. Google's Get started guides for [Android](https://developers.google.com/admob/android/quick-start) and [iOS](https://developers.google.com/admob/ios/quick-start) explain app IDs and SKAdNetwork identifiers (Apple's ad conversion IDs); do not add a second Mobile Ads dependency.
|
|
47
58
|
|
|
48
|
-
|
|
49
|
-
% npm install --save @capacitor-community/admob@7
|
|
50
|
-
% npx cap update
|
|
51
|
-
```
|
|
59
|
+
This plugin targets `@capacitor-community/admob` **v8.2.0** and Capacitor 8.5 or later (within v8). It supports iOS 15 or later and Android API 24 or later.
|
|
52
60
|
|
|
53
|
-
|
|
61
|
+
```bash
|
|
62
|
+
npm install @capacitor-community/admob
|
|
63
|
+
npx cap sync
|
|
64
|
+
```
|
|
54
65
|
|
|
55
|
-
|
|
66
|
+
If you still use Capacitor 7, install `@capacitor-community/admob@7`.
|
|
56
67
|
|
|
57
|
-
|
|
68
|
+
### Google Mobile Ads SDK versions
|
|
58
69
|
|
|
59
|
-
|
|
70
|
+
This major version pins Google Mobile Ads SDK **25.4.x** on Android and **13.11.0** on iOS (Swift Package Manager and CocoaPods). Leave those versions unless you have a specific need. Google's [Next-Gen SDK for Android](https://developers.google.com/admob/android/next-gen) waits until the next plugin major. See [Migration](https://docs.rdlabo.dev/projects/capacitor-admob/docs/migration) for the policy behind the pins.
|
|
60
71
|
|
|
61
72
|
### Android configuration
|
|
62
73
|
|
|
63
|
-
In
|
|
74
|
+
In `android/app/src/main/AndroidManifest.xml`, add the following under `<application>`:
|
|
64
75
|
|
|
65
76
|
```xml
|
|
66
77
|
<meta-data
|
|
67
|
-
|
|
68
|
-
|
|
78
|
+
android:name="com.google.android.gms.ads.APPLICATION_ID"
|
|
79
|
+
android:value="@string/admob_app_id" />
|
|
69
80
|
```
|
|
70
81
|
|
|
71
|
-
In
|
|
82
|
+
In `android/app/src/main/res/values/strings.xml`:
|
|
72
83
|
|
|
73
84
|
```xml
|
|
74
85
|
<string name="admob_app_id">[APP_ID]</string>
|
|
75
86
|
```
|
|
76
87
|
|
|
77
|
-
|
|
88
|
+
Replace `[APP_ID]` with your AdMob **application** ID, not an ad unit ID.
|
|
78
89
|
|
|
79
90
|
#### Variables
|
|
80
91
|
|
|
81
|
-
|
|
92
|
+
You can leave these unset. Override them in your app's `variables.gradle` only when you need a specific artifact version:
|
|
82
93
|
|
|
83
|
-
|
|
84
|
-
|
|
94
|
+
| Variable | Artifact | Default |
|
|
95
|
+
| ------------------------------ | ------------------------------------------------ | -------- |
|
|
96
|
+
| `playServicesAdsVersion` | `com.google.android.gms:play-services-ads` | `25.4.+` |
|
|
97
|
+
| `userMessagingPlatformVersion` | `com.google.android.ump:user-messaging-platform` | `4.0.0` |
|
|
98
|
+
| `androidxCoreKTXVersion` | `androidx.core:core-ktx` | `1.15.0` |
|
|
85
99
|
|
|
86
100
|
### iOS configuration
|
|
87
101
|
|
|
88
|
-
Add the following
|
|
102
|
+
Add the following inside the outermost `<dict>` in `ios/App/App/Info.plist`:
|
|
89
103
|
|
|
90
104
|
```xml
|
|
91
105
|
<key>GADIsAdManagerApp</key>
|
|
@@ -100,337 +114,91 @@ Add the following in the `ios/App/App/info.plist` file inside of the outermost `
|
|
|
100
114
|
</dict>
|
|
101
115
|
</array>
|
|
102
116
|
<key>NSUserTrackingUsageDescription</key>
|
|
103
|
-
<string>
|
|
117
|
+
<string>This identifier will be used to deliver personalized ads to you.</string>
|
|
104
118
|
```
|
|
105
119
|
|
|
106
|
-
|
|
120
|
+
Replace `[APP_ID]` with your AdMob application ID, and describe your actual tracking use in `NSUserTrackingUsageDescription`.
|
|
107
121
|
|
|
108
|
-
|
|
122
|
+
The `SKAdNetworkItems` snippet includes Google's own identifier. Add the other IDs from Google's [iOS setup guide](https://developers.google.com/admob/ios/quick-start#update_your_infoplist).
|
|
109
123
|
|
|
110
|
-
###
|
|
124
|
+
### Troubleshooting
|
|
111
125
|
|
|
112
|
-
|
|
113
|
-
import { AdMob, AdmobConsentStatus } from '@capacitor-community/admob';
|
|
114
|
-
|
|
115
|
-
export async function initialize(): Promise<void> {
|
|
116
|
-
await AdMob.initialize();
|
|
126
|
+
If CocoaPods cannot resolve `Google-Mobile-Ads-SDK`:
|
|
117
127
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
]);
|
|
122
|
-
|
|
123
|
-
if (trackingInfo.status === 'notDetermined') {
|
|
124
|
-
/**
|
|
125
|
-
* If you want to explain TrackingAuthorization before showing the iOS dialog,
|
|
126
|
-
* you can show the modal here.
|
|
127
|
-
* ex)
|
|
128
|
-
* const modal = await this.modalCtrl.create({
|
|
129
|
-
* component: RequestTrackingPage,
|
|
130
|
-
* });
|
|
131
|
-
* await modal.present();
|
|
132
|
-
* await modal.onDidDismiss(); // Wait for close modal
|
|
133
|
-
**/
|
|
134
|
-
|
|
135
|
-
await AdMob.requestTrackingAuthorization();
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const authorizationStatus = await AdMob.trackingAuthorizationStatus();
|
|
139
|
-
if (
|
|
140
|
-
authorizationStatus.status === 'authorized' &&
|
|
141
|
-
consentInfo.isConsentFormAvailable &&
|
|
142
|
-
consentInfo.status === AdmobConsentStatus.REQUIRED
|
|
143
|
-
) {
|
|
144
|
-
await AdMob.showConsentForm();
|
|
145
|
-
}
|
|
146
|
-
}
|
|
128
|
+
```text
|
|
129
|
+
[error] Error running update: Analyzing dependencies
|
|
130
|
+
[!] CocoaPods could not find compatible versions for pod "Google-Mobile-Ads-SDK":
|
|
147
131
|
```
|
|
148
132
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
### User Message Platform (UMP)
|
|
133
|
+
Run `pod repo update` in `ios/`, then `npx cap sync ios` again.
|
|
152
134
|
|
|
153
|
-
|
|
135
|
+
## First test banner
|
|
154
136
|
|
|
155
|
-
|
|
137
|
+
After installation and platform setup, request consent, initialize the SDK when ads may be requested, and show a Google demo banner. Use the platform banner IDs from [Testing](https://docs.rdlabo.dev/projects/capacitor-admob/docs/testing)—do not create your own ad unit for this first check.
|
|
156
138
|
|
|
157
|
-
|
|
139
|
+
Call `startAdMob` from a user action or after the UI is ready (for example a button or post-navigation hook), not only at module evaluation time.
|
|
158
140
|
|
|
159
141
|
```ts
|
|
160
|
-
import {
|
|
142
|
+
import { Capacitor } from '@capacitor/core';
|
|
143
|
+
import { AdMob, AdmobConsentStatus, BannerAdOptions, BannerAdSize, BannerAdPosition } from '@capacitor-community/admob';
|
|
161
144
|
|
|
162
|
-
|
|
145
|
+
const bannerAdId =
|
|
146
|
+
Capacitor.getPlatform() === 'ios'
|
|
147
|
+
? 'ca-app-pub-3940256099942544/2934735716'
|
|
148
|
+
: 'ca-app-pub-3940256099942544/6300978111';
|
|
163
149
|
|
|
164
|
-
async
|
|
150
|
+
async function startAdMob() {
|
|
165
151
|
let consentInfo = await AdMob.requestConsentInfo();
|
|
166
|
-
if (
|
|
152
|
+
if (consentInfo.isConsentFormAvailable && consentInfo.status === AdmobConsentStatus.REQUIRED) {
|
|
167
153
|
consentInfo = await AdMob.showConsentForm();
|
|
168
|
-
this.canShowAds = consentInfo.canRequestAds;
|
|
169
154
|
}
|
|
170
|
-
}
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
To let users manage their privacy options at any time, show the privacy options form.
|
|
174
|
-
```ts
|
|
175
|
-
import { AdMob } from '@capacitor-community/admob';
|
|
176
|
-
|
|
177
|
-
showPrivacyOptionsForm() {
|
|
178
|
-
AdMob.showPrivacyOptionsForm();
|
|
179
|
-
}
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
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).
|
|
183
|
-
|
|
184
|
-
```ts
|
|
185
|
-
import { AdMob, AdmobConsentDebugGeography } from '@capacitor-community/admob';
|
|
186
|
-
|
|
187
|
-
const consentInfo = await AdMob.requestConsentInfo({
|
|
188
|
-
debugGeography: AdmobConsentDebugGeography.EEA,
|
|
189
|
-
testDeviceIdentifiers: ['YOUR_DEVICE_ID'],
|
|
190
|
-
});
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
**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.
|
|
194
|
-
|
|
195
|
-
**Note**: The order in which they are combined with other methods is as follows.
|
|
196
155
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
3/ AdMob.showBanner
|
|
201
|
-
|
|
202
|
-
### Show App Open Ad
|
|
203
|
-
|
|
204
|
-
```ts
|
|
205
|
-
import {
|
|
206
|
-
AdMob,
|
|
207
|
-
AppOpenAdPluginEvents,
|
|
208
|
-
AppOpenAdOptions,
|
|
209
|
-
AdLoadInfo,
|
|
210
|
-
} from '@capacitor-community/admob';
|
|
211
|
-
|
|
212
|
-
export async function showAppOpenAd(): Promise<void> {
|
|
213
|
-
// listen to events
|
|
214
|
-
AdMob.addListener(AppOpenAdPluginEvents.Loaded, (info: AdLoadInfo) => {
|
|
215
|
-
console.log('App Open Ad loaded', info.adUnitId);
|
|
216
|
-
});
|
|
217
|
-
AdMob.addListener(AppOpenAdPluginEvents.FailedToLoad, (error) => {
|
|
218
|
-
console.log('Failed to load App Open Ad', error);
|
|
219
|
-
});
|
|
220
|
-
AdMob.addListener(AppOpenAdPluginEvents.Opened, () => {
|
|
221
|
-
console.log('App Open Ad open');
|
|
222
|
-
});
|
|
223
|
-
AdMob.addListener(AppOpenAdPluginEvents.Closed, () => {
|
|
224
|
-
console.log('App Open Ad close');
|
|
225
|
-
});
|
|
226
|
-
AdMob.addListener(AppOpenAdPluginEvents.FailedToShow, (error) => {
|
|
227
|
-
console.log('Failed to show App Open Ad', error);
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
const options: AppOpenAdOptions = {
|
|
231
|
-
adId: 'YOUR_AD_UNIT_ID',
|
|
232
|
-
};
|
|
233
|
-
const { adUnitId } = await AdMob.loadAppOpen(options);
|
|
234
|
-
const { value } = await AdMob.isAppOpenLoaded({ adId: adUnitId });
|
|
235
|
-
if (value) {
|
|
236
|
-
await AdMob.showAppOpen({ adId: adUnitId });
|
|
156
|
+
if (!consentInfo.canRequestAds) {
|
|
157
|
+
// Consent not ready — no banner is shown.
|
|
158
|
+
return;
|
|
237
159
|
}
|
|
238
|
-
}
|
|
239
|
-
```
|
|
240
|
-
### Show Banner
|
|
241
160
|
|
|
242
|
-
|
|
243
|
-
import {
|
|
244
|
-
AdMob,
|
|
245
|
-
BannerAdOptions,
|
|
246
|
-
BannerAdSize,
|
|
247
|
-
BannerAdPosition,
|
|
248
|
-
BannerAdPluginEvents,
|
|
249
|
-
AdMobBannerSize,
|
|
250
|
-
} from '@capacitor-community/admob';
|
|
251
|
-
|
|
252
|
-
export async function banner(): Promise<void> {
|
|
253
|
-
AdMob.addListener(BannerAdPluginEvents.Loaded, () => {
|
|
254
|
-
// Subscribe Banner Event Listener
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
AdMob.addListener(
|
|
258
|
-
BannerAdPluginEvents.SizeChanged,
|
|
259
|
-
(size: AdMobBannerSize) => {
|
|
260
|
-
// Subscribe Change Banner Size
|
|
261
|
-
},
|
|
262
|
-
);
|
|
161
|
+
await AdMob.initialize();
|
|
263
162
|
|
|
264
163
|
const options: BannerAdOptions = {
|
|
265
|
-
adId:
|
|
266
|
-
adSize: BannerAdSize.
|
|
164
|
+
adId: bannerAdId,
|
|
165
|
+
adSize: BannerAdSize.ADAPTIVE_BANNER,
|
|
267
166
|
position: BannerAdPosition.BOTTOM_CENTER,
|
|
268
167
|
margin: 0,
|
|
269
|
-
// isTesting: true
|
|
270
|
-
// npa: true
|
|
271
|
-
};
|
|
272
|
-
AdMob.showBanner(options);
|
|
273
|
-
}
|
|
274
|
-
```
|
|
275
|
-
|
|
276
|
-
### Impression-level ad revenue
|
|
277
|
-
|
|
278
|
-
Full-screen ad formats emit revenue data through their `AdImpression` event. Banners use the separate `AdPaid` event.
|
|
279
|
-
|
|
280
|
-
```ts
|
|
281
|
-
import {
|
|
282
|
-
AdMob,
|
|
283
|
-
AdMobRevenueData,
|
|
284
|
-
BannerAdPluginEvents,
|
|
285
|
-
InterstitialAdPluginEvents,
|
|
286
|
-
} from '@capacitor-community/admob';
|
|
287
|
-
|
|
288
|
-
AdMob.addListener(
|
|
289
|
-
InterstitialAdPluginEvents.AdImpression,
|
|
290
|
-
(data: AdMobRevenueData) => {
|
|
291
|
-
console.log(data);
|
|
292
|
-
},
|
|
293
|
-
);
|
|
294
|
-
|
|
295
|
-
AdMob.addListener(BannerAdPluginEvents.AdPaid, (data: AdMobRevenueData) => {
|
|
296
|
-
console.log(data);
|
|
297
|
-
});
|
|
298
|
-
```
|
|
299
|
-
|
|
300
|
-
### Show Interstitial
|
|
301
|
-
|
|
302
|
-
```ts
|
|
303
|
-
import {
|
|
304
|
-
AdMob,
|
|
305
|
-
AdOptions,
|
|
306
|
-
AdLoadInfo,
|
|
307
|
-
InterstitialAdPluginEvents,
|
|
308
|
-
} from '@capacitor-community/admob';
|
|
309
|
-
|
|
310
|
-
export async function interstitial(): Promise<void> {
|
|
311
|
-
AdMob.addListener(InterstitialAdPluginEvents.Loaded, (info: AdLoadInfo) => {
|
|
312
|
-
// Subscribe prepared interstitial
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
const options: AdOptions = {
|
|
316
|
-
adId: 'YOUR ADID',
|
|
317
|
-
// isTesting: true
|
|
318
|
-
// npa: true
|
|
319
|
-
// immersiveMode: true
|
|
320
168
|
};
|
|
321
|
-
await AdMob.
|
|
322
|
-
await AdMob.showInterstitial();
|
|
323
|
-
|
|
324
|
-
// You can also prepare multiple interstitials and show a specific one by passing its adId:
|
|
325
|
-
await AdMob.prepareInterstitial({ adId: 'ca-app-pub-xxx/interstitial-1' });
|
|
326
|
-
await AdMob.prepareInterstitial({ adId: 'ca-app-pub-xxx/interstitial-2' });
|
|
327
|
-
|
|
328
|
-
// Show a specific prepared ad
|
|
329
|
-
await AdMob.showInterstitial({ adId: 'ca-app-pub-xxx/interstitial-1' });
|
|
330
|
-
|
|
331
|
-
// Or omit adId to show the most recently prepared one (default behavior)
|
|
332
|
-
await AdMob.showInterstitial();
|
|
169
|
+
await AdMob.showBanner(options);
|
|
333
170
|
}
|
|
334
171
|
```
|
|
335
172
|
|
|
336
|
-
|
|
173
|
+
Expected result: when `canRequestAds` is true, a Google test banner appears at the bottom of the native screen. When `canRequestAds` is false, the function returns and no banner is shown. The banner sits above the WebView and can cover HTML—see [Banner Ads](https://docs.rdlabo.dev/projects/capacitor-admob/docs/banner) to inset your layout. Details: [Configuration](https://docs.rdlabo.dev/projects/capacitor-admob/docs/configuration), [Consent](https://docs.rdlabo.dev/projects/capacitor-admob/docs/consent), and [Testing](https://docs.rdlabo.dev/projects/capacitor-admob/docs/testing).
|
|
337
174
|
|
|
338
|
-
|
|
339
|
-
import {
|
|
340
|
-
AdMob,
|
|
341
|
-
RewardAdOptions,
|
|
342
|
-
AdLoadInfo,
|
|
343
|
-
RewardAdPluginEvents,
|
|
344
|
-
AdMobRewardItem,
|
|
345
|
-
} from '@capacitor-community/admob';
|
|
346
|
-
|
|
347
|
-
export async function rewardVideo(): Promise<void> {
|
|
348
|
-
AdMob.addListener(RewardAdPluginEvents.Loaded, (info: AdLoadInfo) => {
|
|
349
|
-
// Subscribe prepared rewardVideo
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
AdMob.addListener(
|
|
353
|
-
RewardAdPluginEvents.Rewarded,
|
|
354
|
-
(rewardItem: AdMobRewardItem) => {
|
|
355
|
-
// Subscribe user rewarded
|
|
356
|
-
console.log(rewardItem);
|
|
357
|
-
},
|
|
358
|
-
);
|
|
359
|
-
|
|
360
|
-
const options: RewardAdOptions = {
|
|
361
|
-
adId: 'YOUR ADID',
|
|
362
|
-
// isTesting: true
|
|
363
|
-
// npa: true
|
|
364
|
-
// immersiveMode: true
|
|
365
|
-
// ssv: {
|
|
366
|
-
// userId: "A user ID to send to your SSV"
|
|
367
|
-
// customData: JSON.stringify({ ...MyCustomData })
|
|
368
|
-
//}
|
|
369
|
-
};
|
|
370
|
-
await AdMob.prepareRewardVideoAd(options);
|
|
371
|
-
const rewardItem = await AdMob.showRewardVideoAd();
|
|
175
|
+
## Choose by advertising goal
|
|
372
176
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
177
|
+
| Goal | Ad format | Guide |
|
|
178
|
+
| ----------------------------------------------------------------- | ------------------------- | ------------------------------------------ |
|
|
179
|
+
| Keep an ad visible alongside app content | Banner | [Banner Ads](https://docs.rdlabo.dev/projects/capacitor-admob/docs/banner) |
|
|
180
|
+
| Show a full-screen ad at a natural break without granting a reward | Interstitial | [Interstitial Ads](https://docs.rdlabo.dev/projects/capacitor-admob/docs/interstitial) |
|
|
181
|
+
| Offer a dedicated rewarded experience | Rewarded | [Rewarded Ads](https://docs.rdlabo.dev/projects/capacitor-admob/docs/rewarded) |
|
|
182
|
+
| Offer a reward at a natural transition | Rewarded interstitial | [Rewarded Ads](https://docs.rdlabo.dev/projects/capacitor-admob/docs/rewarded) |
|
|
183
|
+
| Monetize an app-open experience | App Open | [App Open Ads](https://docs.rdlabo.dev/projects/capacitor-admob/docs/app-open) |
|
|
376
184
|
|
|
377
|
-
|
|
378
|
-
const reward = await AdMob.showRewardVideoAd({ adId: 'ca-app-pub-xxx/reward-1' });
|
|
185
|
+
## Documentation
|
|
379
186
|
|
|
380
|
-
|
|
381
|
-
const reward2 = await AdMob.showRewardVideoAd();
|
|
382
|
-
}
|
|
383
|
-
```
|
|
187
|
+
Start with [Installation](#installation) above, then [Configuration](https://docs.rdlabo.dev/projects/capacitor-admob/docs/configuration) and [Consent](https://docs.rdlabo.dev/projects/capacitor-admob/docs/consent). Run the first test banner, then use [Testing](https://docs.rdlabo.dev/projects/capacitor-admob/docs/testing) for demo units and devices. Pick an ad format from the table above. The same guides are also on the [documentation site](https://docs.rdlabo.dev/projects/capacitor-admob) (English and Japanese). If you opened this README on npm, use that site for the guides — the `docs/` files are also included in the package. Method signatures are in the API section below.
|
|
384
188
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
}
|
|
397
|
-
```
|
|
398
|
-
|
|
399
|
-
## Server-side Verification Notice
|
|
400
|
-
|
|
401
|
-
SSV callbacks are only fired on Production Adverts, therefore test Ads will not fire off your SSV callback.
|
|
402
|
-
|
|
403
|
-
For E2E tests or just for validating the data in your `RewardAdOptions` work as expected, you can add a custom GET
|
|
404
|
-
request to your mock endpoint after the `RewardAdPluginEvents.Rewarded` similar to this:
|
|
405
|
-
|
|
406
|
-
```ts
|
|
407
|
-
AdMob.addListener(RewardAdPluginEvents.Rewarded, async () => {
|
|
408
|
-
// ...
|
|
409
|
-
if (ENVIRONMENT_IS_DEVELOPMENT) {
|
|
410
|
-
try {
|
|
411
|
-
const url =
|
|
412
|
-
`https://your-staging-ssv-endpoint` +
|
|
413
|
-
new URLSearchParams({
|
|
414
|
-
ad_network: 'TEST',
|
|
415
|
-
ad_unit: 'TEST',
|
|
416
|
-
custom_data: customData, // <-- passed CustomData
|
|
417
|
-
reward_amount: 'TEST',
|
|
418
|
-
reward_item: 'TEST',
|
|
419
|
-
timestamp: 'TEST',
|
|
420
|
-
transaction_id: 'TEST',
|
|
421
|
-
user_id: userId, // <-- Passed UserID
|
|
422
|
-
signature: 'TEST',
|
|
423
|
-
key_id: 'TEST',
|
|
424
|
-
});
|
|
425
|
-
await fetch(url);
|
|
426
|
-
} catch (err) {
|
|
427
|
-
console.error(err);
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
// ...
|
|
431
|
-
});
|
|
432
|
-
```
|
|
189
|
+
- [Configuration](https://docs.rdlabo.dev/projects/capacitor-admob/docs/configuration) — `AdMob.initialize` and SDK options.
|
|
190
|
+
- [Consent](https://docs.rdlabo.dev/projects/capacitor-admob/docs/consent) — privacy consent and iOS tracking authorization.
|
|
191
|
+
- [Testing](https://docs.rdlabo.dev/projects/capacitor-admob/docs/testing) — demo ad units, test devices, and consent testing.
|
|
192
|
+
- [Banner Ads](https://docs.rdlabo.dev/projects/capacitor-admob/docs/banner) — banner options, lifecycle, and events.
|
|
193
|
+
- [Native Ads (Preview)](./docs/native-ads.md) — available for testing and production use. Its API may change in a minor release while in Preview.
|
|
194
|
+
- Full-screen ads:
|
|
195
|
+
- [Interstitial Ads](https://docs.rdlabo.dev/projects/capacitor-admob/docs/interstitial) — load, show, and multiple prepared ads.
|
|
196
|
+
- [Rewarded Ads](https://docs.rdlabo.dev/projects/capacitor-admob/docs/rewarded) — rewarded video, rewarded interstitial, and server-side verification.
|
|
197
|
+
- [App Open Ads](https://docs.rdlabo.dev/projects/capacitor-admob/docs/app-open) — load and present on foreground transitions.
|
|
198
|
+
- [Ad Events](https://docs.rdlabo.dev/projects/capacitor-admob/docs/events) — shared lifecycle events, errors, and revenue data.
|
|
199
|
+
- [Migration Guide](https://docs.rdlabo.dev/projects/capacitor-admob/docs/migration) — upgrade steps and behavior changes in v8.2.0 and earlier versions.
|
|
433
200
|
|
|
201
|
+
<!-- rdlabo-docs-omit -->
|
|
434
202
|
## Index
|
|
435
203
|
|
|
436
204
|
<docgen-index>
|
|
@@ -474,6 +242,7 @@ AdMob.addListener(RewardAdPluginEvents.Rewarded, async () => {
|
|
|
474
242
|
* [`addListener(InterstitialAdPluginEvents.AdImpression, ...)`](#addlistenerinterstitialadplugineventsadimpression-)
|
|
475
243
|
* [`prepareRewardVideoAd(...)`](#preparerewardvideoad)
|
|
476
244
|
* [`showRewardVideoAd(...)`](#showrewardvideoad)
|
|
245
|
+
* [`addListener(RewardAdPluginEvents.adClicked, ...)`](#addlistenerrewardadplugineventsadclicked-)
|
|
477
246
|
* [`addListener(RewardAdPluginEvents.FailedToLoad, ...)`](#addlistenerrewardadplugineventsfailedtoload-)
|
|
478
247
|
* [`addListener(RewardAdPluginEvents.Loaded, ...)`](#addlistenerrewardadplugineventsloaded-)
|
|
479
248
|
* [`addListener(RewardAdPluginEvents.Rewarded, ...)`](#addlistenerrewardadplugineventsrewarded-)
|
|
@@ -1001,6 +770,9 @@ prepareInterstitial(options: AdOptions) => Promise<AdLoadInfo>
|
|
|
1001
770
|
|
|
1002
771
|
Loads an interstitial ad and returns the loaded ad unit ID.
|
|
1003
772
|
|
|
773
|
+
SDK load failures reject with the native error message and a string `code`.
|
|
774
|
+
Codes are platform-specific; FailedToLoad events expose the same code as a number.
|
|
775
|
+
|
|
1004
776
|
| Param | Type | Description |
|
|
1005
777
|
| ------------- | ----------------------------------------------- | ---------------------------------- |
|
|
1006
778
|
| **`options`** | <code><a href="#adoptions">AdOptions</a></code> | <a href="#adoptions">AdOptions</a> |
|
|
@@ -1145,6 +917,9 @@ prepareRewardVideoAd(options: RewardAdOptions) => Promise<AdLoadInfo>
|
|
|
1145
917
|
|
|
1146
918
|
Loads a rewarded ad and returns the loaded ad unit ID.
|
|
1147
919
|
|
|
920
|
+
SDK load failures reject with the native error message and a string `code`.
|
|
921
|
+
Codes are platform-specific; FailedToLoad events expose the same code as a number.
|
|
922
|
+
|
|
1148
923
|
| Param | Type | Description |
|
|
1149
924
|
| ------------- | ----------------------------------------------------------- | ---------------------------------------------- |
|
|
1150
925
|
| **`options`** | <code><a href="#rewardadoptions">RewardAdOptions</a></code> | <a href="#rewardadoptions">RewardAdOptions</a> |
|
|
@@ -1175,6 +950,25 @@ Shows a loaded rewarded ad and resolves when the user earns the reward.
|
|
|
1175
950
|
--------------------
|
|
1176
951
|
|
|
1177
952
|
|
|
953
|
+
### addListener(RewardAdPluginEvents.adClicked, ...)
|
|
954
|
+
|
|
955
|
+
```typescript
|
|
956
|
+
addListener(eventName: RewardAdPluginEvents.adClicked, listenerFunc: () => void) => Promise<PluginListenerHandle>
|
|
957
|
+
```
|
|
958
|
+
|
|
959
|
+
Listens for clicks recorded by the rewarded ad SDK, including after a reward is earned.
|
|
960
|
+
A click does not indicate that the user earned a reward.
|
|
961
|
+
|
|
962
|
+
| Param | Type |
|
|
963
|
+
| ------------------ | ------------------------------------------------------------------------------- |
|
|
964
|
+
| **`eventName`** | <code><a href="#rewardadpluginevents">RewardAdPluginEvents.adClicked</a></code> |
|
|
965
|
+
| **`listenerFunc`** | <code>() => void</code> |
|
|
966
|
+
|
|
967
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>></code>
|
|
968
|
+
|
|
969
|
+
--------------------
|
|
970
|
+
|
|
971
|
+
|
|
1178
972
|
### addListener(RewardAdPluginEvents.FailedToLoad, ...)
|
|
1179
973
|
|
|
1180
974
|
```typescript
|
|
@@ -1309,6 +1103,9 @@ prepareRewardInterstitialAd(options: RewardInterstitialAdOptions) => Promise<AdL
|
|
|
1309
1103
|
|
|
1310
1104
|
Loads a rewarded interstitial ad and returns the loaded ad unit ID.
|
|
1311
1105
|
|
|
1106
|
+
SDK load failures reject with the native error message and a string `code`.
|
|
1107
|
+
Codes are platform-specific; FailedToLoad events expose the same code as a number.
|
|
1108
|
+
|
|
1312
1109
|
| Param | Type | Description |
|
|
1313
1110
|
| ------------- | ----------------------------------------------------------------------------------- | ---------------------------------------------------------------------- |
|
|
1314
1111
|
| **`options`** | <code><a href="#rewardinterstitialadoptions">RewardInterstitialAdOptions</a></code> | <a href="#rewardinterstitialadoptions">RewardInterstitialAdOptions</a> |
|
|
@@ -1799,6 +1596,7 @@ From T, pick a set of properties whose keys are in the union K
|
|
|
1799
1596
|
|
|
1800
1597
|
| Members | Value | Description |
|
|
1801
1598
|
| ------------------ | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
1599
|
+
| **`adClicked`** | <code>'onRewardedVideoAdClicked'</code> | Emits when the SDK records a click on a rewarded ad. |
|
|
1802
1600
|
| **`Loaded`** | <code>'onRewardedVideoAdLoaded'</code> | Emits when a rewarded ad has loaded and is ready to show. |
|
|
1803
1601
|
| **`FailedToLoad`** | <code>'onRewardedVideoAdFailedToLoad'</code> | Emits when a rewarded ad fails to load. |
|
|
1804
1602
|
| **`Showed`** | <code>'onRewardedVideoAdShowed'</code> | Emits when a rewarded ad is shown. |
|
|
@@ -1822,15 +1620,23 @@ From T, pick a set of properties whose keys are in the union K
|
|
|
1822
1620
|
|
|
1823
1621
|
</docgen-api>
|
|
1824
1622
|
|
|
1825
|
-
##
|
|
1623
|
+
## Prerelease channels
|
|
1624
|
+
|
|
1625
|
+
An open, non-draft pull request can be published to the npm `beta` dist-tag after its `Validation` and `Package Candidate` workflows pass. A repository owner or maintainer must add a comment whose entire body is:
|
|
1626
|
+
|
|
1627
|
+
```text
|
|
1628
|
+
/beta
|
|
1629
|
+
```
|
|
1630
|
+
|
|
1631
|
+
The request authorizes only the pull request head SHA that existed when the comment was added. The workflow revalidates the owner or maintainer permission and head SHA immediately before publishing. Any new commit requires CI to pass again and a fresh owner or maintainer `/beta` comment. Fork pull requests are supported. Pull requests that change a release-gating workflow cannot be beta-published until those workflow changes land on `main`.
|
|
1826
1632
|
|
|
1827
|
-
|
|
1633
|
+
Beta versions use `<base>-beta.pr<PR number>.sha<12-character SHA>`. The candidate is built in a read-only workflow without npm publishing credentials. The privileged release workflow publishes only the validated immutable package artifact with lifecycle scripts disabled. A notification failure cannot invalidate a successful npm publish.
|
|
1828
1634
|
|
|
1829
|
-
|
|
1830
|
-
> [!] CocoaPods could not find compatible versions for pod "Google-Mobile-Ads-SDK":
|
|
1635
|
+
When a pull request is merged into `main`, it is automatically published to `beta` only after the required CI and `Package Candidate` succeed for that exact merge commit. Direct pushes to `main` do not publish a candidate.
|
|
1831
1636
|
|
|
1832
|
-
|
|
1637
|
+
Only `npm run release` creates a release tag. Stable `vX.Y.Z` tags publish to npm `latest`; revision/prerelease tags publish to `next`. Neither `beta` nor `next` publishing changes the npm `latest` dist-tag.
|
|
1833
1638
|
|
|
1834
1639
|
## License
|
|
1835
1640
|
|
|
1836
1641
|
Capacitor AdMob is [MIT licensed](./LICENSE).
|
|
1642
|
+
<!-- /rdlabo-docs-omit -->
|
package/android/build.gradle
CHANGED
|
@@ -37,7 +37,7 @@ android {
|
|
|
37
37
|
buildTypes {
|
|
38
38
|
release {
|
|
39
39
|
minifyEnabled false
|
|
40
|
-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
40
|
+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
lintOptions {
|