@capacitor-community/admob 7.0.1 → 7.0.2
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 -0
- package/README.md +338 -338
- package/package.json +1 -1
- package/android/src/main/res/layout/bridge_layout_main.xml +0 -15
- package/android/src/main/res/values/colors.xml +0 -3
- package/android/src/main/res/values/strings.xml +0 -2
- package/android/src/main/res/values/styles.xml +0 -3
package/README.md
CHANGED
|
@@ -1,323 +1,323 @@
|
|
|
1
|
-
<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
|
-
<h3 align="center">AdMob</h3>
|
|
3
|
-
<p align="center"><strong><code>@capacitor-community/admob</code></strong></p>
|
|
4
|
-
<p align="center">
|
|
5
|
-
Capacitor community plugin for native AdMob.
|
|
6
|
-
</p>
|
|
7
|
-
|
|
8
|
-
<p align="center">
|
|
9
|
-
<img src="https://img.shields.io/maintenance/yes/2025?style=flat-square" />
|
|
10
|
-
<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>
|
|
11
|
-
<br>
|
|
12
|
-
<a href="https://www.npmjs.com/package/@capacitor-community/admob"><img src="https://img.shields.io/npm/dw/@capacitor-community/admob?style=flat-square" /></a>
|
|
13
|
-
<a href="https://www.npmjs.com/package/@capacitor-community/admob"><img src="https://img.shields.io/npm/v/@capacitor-community/admob?style=flat-square" /></a>
|
|
14
|
-
</p>
|
|
15
|
-
|
|
16
|
-
## Maintainers
|
|
17
|
-
|
|
18
|
-
| Maintainer | GitHub | Social | Sponsoring Company |
|
|
19
|
-
| ------------------- | ------------------------------------------------ | ----------------------------------------------- | ---------------------------------------------- |
|
|
20
|
-
| Masahiko Sakakibara | [rdlabo](https://github.com/rdlabo) | [@rdlabo](https://twitter.com/rdlabo) | RELATION DESIGN LABO, GENERAL INC. ASSOCIATION |
|
|
21
|
-
| Saninn Salas Diaz | [Saninn Salas Diaz](https://github.com/distante) | [@SaninnSalas](https://twitter.com/SaninnSalas) | |
|
|
22
|
-
|
|
23
|
-
Maintenance Status: Actively Maintained
|
|
24
|
-
|
|
25
|
-
## Contributors ✨
|
|
26
|
-
|
|
27
|
-
<a href="https://github.com/capacitor-community/admob/graphs/contributors">
|
|
28
|
-
<img src="https://contrib.rocks/image?repo=capacitor-community/admob" />
|
|
29
|
-
</a>
|
|
30
|
-
|
|
31
|
-
Made with [contributors-img](https://contrib.rocks).
|
|
32
|
-
|
|
33
|
-
## Demo
|
|
34
|
-
|
|
35
|
-
[Demo code is here.](https://github.com/capacitor-community/admob/tree/master/demo)
|
|
36
|
-
|
|
37
|
-
### Screenshots
|
|
38
|
-
|
|
39
|
-
| | Banner | Interstitial | Reward |
|
|
40
|
-
| :---------- | :----------------------------------: | :----------------------------------------: | :----------------------------------: |
|
|
41
|
-
| **iOS** |  |  |  |
|
|
42
|
-
| **Android** |  |  |  |
|
|
43
|
-
|
|
44
|
-
## Installation
|
|
45
|
-
|
|
46
|
-
If you use capacitor 6:
|
|
47
|
-
|
|
48
|
-
```
|
|
49
|
-
% npm install --save @capacitor-community/admob@6
|
|
50
|
-
% npx cap update
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
### Android configuration
|
|
54
|
-
|
|
55
|
-
In file `android/app/src/main/AndroidManifest.xml`, add the following XML elements under `<manifest><application>` :
|
|
56
|
-
|
|
57
|
-
```xml
|
|
58
|
-
<meta-data
|
|
59
|
-
android:name="com.google.android.gms.ads.APPLICATION_ID"
|
|
60
|
-
android:value="@string/admob_app_id"/>
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
In file `android/app/src/main/res/values/strings.xml` add the following lines :
|
|
64
|
-
|
|
65
|
-
```xml
|
|
66
|
-
<string name="admob_app_id">[APP_ID]</string>
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
Don't forget to replace `[APP_ID]` by your AdMob application Id.
|
|
70
|
-
|
|
71
|
-
#### Variables
|
|
72
|
-
|
|
73
|
-
This plugin will use the following project variables (defined in your app's `variables.gradle` file):
|
|
74
|
-
|
|
75
|
-
- `playServicesAdsVersion` version of `com.google.android.gms:play-services-ads` (default: `
|
|
76
|
-
- `androidxCoreKTXVersion`: version of `androidx.core:core-ktx` (default: `1.
|
|
77
|
-
|
|
78
|
-
### iOS configuration
|
|
79
|
-
|
|
80
|
-
Add the following in the `ios/App/App/info.plist` file inside of the outermost `<dict>`:
|
|
81
|
-
|
|
82
|
-
```xml
|
|
83
|
-
<key>GADIsAdManagerApp</key>
|
|
84
|
-
<true/>
|
|
85
|
-
<key>GADApplicationIdentifier</key>
|
|
86
|
-
<string>[APP_ID]</string>
|
|
87
|
-
<key>SKAdNetworkItems</key>
|
|
88
|
-
<array>
|
|
89
|
-
<dict>
|
|
90
|
-
<key>SKAdNetworkIdentifier</key>
|
|
91
|
-
<string>cstr6suwn9.skadnetwork</string>
|
|
92
|
-
</dict>
|
|
93
|
-
</array>
|
|
94
|
-
<key>NSUserTrackingUsageDescription</key>
|
|
95
|
-
<string>[Why you use NSUserTracking. ex: This identifier will be used to deliver personalized ads to you.]</string>
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
Don't forget to replace `[APP_ID]` by your AdMob application Id.
|
|
99
|
-
|
|
100
|
-
## Example
|
|
101
|
-
|
|
102
|
-
### Initialize AdMob
|
|
103
|
-
|
|
104
|
-
```ts
|
|
105
|
-
import { AdMob } from '@capacitor-community/admob';
|
|
106
|
-
|
|
107
|
-
export async function initialize(): Promise<void> {
|
|
108
|
-
await AdMob.initialize();
|
|
109
|
-
|
|
110
|
-
const [trackingInfo, consentInfo] = await Promise.all([
|
|
111
|
-
AdMob.trackingAuthorizationStatus(),
|
|
112
|
-
AdMob.requestConsentInfo(),
|
|
113
|
-
]);
|
|
114
|
-
|
|
115
|
-
if (trackingInfo.status === 'notDetermined') {
|
|
116
|
-
/**
|
|
117
|
-
* If you want to explain TrackingAuthorization before showing the iOS dialog,
|
|
118
|
-
* you can show the modal here.
|
|
119
|
-
* ex)
|
|
120
|
-
* const modal = await this.modalCtrl.create({
|
|
121
|
-
* component: RequestTrackingPage,
|
|
122
|
-
* });
|
|
123
|
-
* await modal.present();
|
|
124
|
-
* await modal.onDidDismiss(); // Wait for close modal
|
|
125
|
-
**/
|
|
126
|
-
|
|
127
|
-
await AdMob.requestTrackingAuthorization();
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const authorizationStatus = await AdMob.trackingAuthorizationStatus();
|
|
131
|
-
if (
|
|
132
|
-
authorizationStatus.status === 'authorized' &&
|
|
133
|
-
consentInfo.isConsentFormAvailable &&
|
|
134
|
-
consentInfo.status === AdmobConsentStatus.REQUIRED
|
|
135
|
-
) {
|
|
136
|
-
await AdMob.showConsentForm();
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
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
|
|
142
|
-
|
|
143
|
-
### User Message Platform (UMP)
|
|
144
|
-
|
|
145
|
-
Later this year, Google will require all publishers serving ads to EEA and UK users to use a Google-certified Consent Management Platform (CMP)
|
|
146
|
-
|
|
147
|
-
Currently we just support Google's consent management solution.
|
|
148
|
-
|
|
149
|
-
To use UMP, you must [create your GDPR messages](https://support.google.com/admob/answer/10113207?hl=en&ref_topic=10105230&sjid=6731900490614517032-AP)
|
|
150
|
-
|
|
151
|
-
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.
|
|
152
|
-
|
|
153
|
-
Example of how to use UMP
|
|
154
|
-
|
|
155
|
-
```ts
|
|
156
|
-
import { AdMob, AdmobConsentStatus, AdmobConsentDebugGeography } from '@capacitor-community/admob';
|
|
157
|
-
|
|
158
|
-
async showConsent() {
|
|
159
|
-
const consentInfo = await AdMob.requestConsentInfo();
|
|
160
|
-
|
|
161
|
-
if (consentInfo.isConsentFormAvailable && consentInfo.status === AdmobConsentStatus.REQUIRED) {
|
|
162
|
-
const {status} = await AdMob.showConsentForm();
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
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).
|
|
168
|
-
|
|
169
|
-
```ts
|
|
170
|
-
const consentInfo = await AdMob.requestConsentInfo({
|
|
171
|
-
debugGeography: AdmobConsentDebugGeography.EEA,
|
|
172
|
-
testDeviceIdentifiers: ['YOUR_DEVICE_ID'],
|
|
173
|
-
});
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
**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.
|
|
177
|
-
|
|
178
|
-
**Note**: The order in which they are combined with other methods is as follows.
|
|
179
|
-
|
|
180
|
-
1. AdMob.initialize
|
|
181
|
-
2. AdMob.requestConsentInfo
|
|
182
|
-
3. AdMob.showConsentForm (If consent form required )
|
|
183
|
-
3/ AdMob.showBanner
|
|
184
|
-
|
|
185
|
-
### Show Banner
|
|
186
|
-
|
|
187
|
-
```ts
|
|
188
|
-
import {
|
|
189
|
-
AdMob,
|
|
190
|
-
BannerAdOptions,
|
|
191
|
-
BannerAdSize,
|
|
192
|
-
BannerAdPosition,
|
|
193
|
-
BannerAdPluginEvents,
|
|
194
|
-
AdMobBannerSize,
|
|
195
|
-
} from '@capacitor-community/admob';
|
|
196
|
-
|
|
197
|
-
export async function banner(): Promise<void> {
|
|
198
|
-
AdMob.addListener(BannerAdPluginEvents.Loaded, () => {
|
|
199
|
-
// Subscribe Banner Event Listener
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
AdMob.addListener(
|
|
203
|
-
BannerAdPluginEvents.SizeChanged,
|
|
204
|
-
(size: AdMobBannerSize) => {
|
|
205
|
-
// Subscribe Change Banner Size
|
|
206
|
-
},
|
|
207
|
-
);
|
|
208
|
-
|
|
209
|
-
const options: BannerAdOptions = {
|
|
210
|
-
adId: 'YOUR ADID',
|
|
211
|
-
adSize: BannerAdSize.BANNER,
|
|
212
|
-
position: BannerAdPosition.BOTTOM_CENTER,
|
|
213
|
-
margin: 0,
|
|
214
|
-
// isTesting: true
|
|
215
|
-
// npa: true
|
|
216
|
-
};
|
|
217
|
-
AdMob.showBanner(options);
|
|
218
|
-
}
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
### Show Interstitial
|
|
222
|
-
|
|
223
|
-
```ts
|
|
224
|
-
import {
|
|
225
|
-
AdMob,
|
|
226
|
-
AdOptions,
|
|
227
|
-
AdLoadInfo,
|
|
228
|
-
InterstitialAdPluginEvents,
|
|
229
|
-
} from '@capacitor-community/admob';
|
|
230
|
-
|
|
231
|
-
export async function interstitial(): Promise<void> {
|
|
232
|
-
AdMob.addListener(InterstitialAdPluginEvents.Loaded, (info: AdLoadInfo) => {
|
|
233
|
-
// Subscribe prepared interstitial
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
const options: AdOptions = {
|
|
237
|
-
adId: 'YOUR ADID',
|
|
238
|
-
// isTesting: true
|
|
239
|
-
// npa: true
|
|
240
|
-
};
|
|
241
|
-
await AdMob.prepareInterstitial(options);
|
|
242
|
-
await AdMob.showInterstitial();
|
|
243
|
-
}
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
### Show RewardVideo
|
|
247
|
-
|
|
248
|
-
```ts
|
|
249
|
-
import {
|
|
250
|
-
AdMob,
|
|
251
|
-
RewardAdOptions,
|
|
252
|
-
AdLoadInfo,
|
|
253
|
-
RewardAdPluginEvents,
|
|
254
|
-
AdMobRewardItem,
|
|
255
|
-
} from '@capacitor-community/admob';
|
|
256
|
-
|
|
257
|
-
export async function rewardVideo(): Promise<void> {
|
|
258
|
-
AdMob.addListener(RewardAdPluginEvents.Loaded, (info: AdLoadInfo) => {
|
|
259
|
-
// Subscribe prepared rewardVideo
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
AdMob.addListener(
|
|
263
|
-
RewardAdPluginEvents.Rewarded,
|
|
264
|
-
(rewardItem: AdMobRewardItem) => {
|
|
265
|
-
// Subscribe user rewarded
|
|
266
|
-
console.log(rewardItem);
|
|
267
|
-
},
|
|
268
|
-
);
|
|
269
|
-
|
|
270
|
-
const options: RewardAdOptions = {
|
|
271
|
-
adId: 'YOUR ADID',
|
|
272
|
-
// isTesting: true
|
|
273
|
-
// npa: true
|
|
274
|
-
// ssv: {
|
|
275
|
-
// userId: "A user ID to send to your SSV"
|
|
276
|
-
// customData: JSON.stringify({ ...MyCustomData })
|
|
277
|
-
//}
|
|
278
|
-
};
|
|
279
|
-
await AdMob.prepareRewardVideoAd(options);
|
|
280
|
-
const rewardItem = await AdMob.showRewardVideoAd();
|
|
281
|
-
}
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
## Server-side Verification Notice
|
|
285
|
-
|
|
286
|
-
SSV callbacks are only fired on Production Adverts, therefore test Ads will not fire off your SSV callback.
|
|
287
|
-
|
|
288
|
-
For E2E tests or just for validating the data in your `RewardAdOptions` work as expected, you can add a custom GET
|
|
289
|
-
request to your mock endpoint after the `RewardAdPluginEvents.Rewarded` similar to this:
|
|
290
|
-
|
|
291
|
-
```ts
|
|
292
|
-
AdMob.addListener(RewardAdPluginEvents.Rewarded, async () => {
|
|
293
|
-
// ...
|
|
294
|
-
if (ENVIRONMENT_IS_DEVELOPMENT) {
|
|
295
|
-
try {
|
|
296
|
-
const url =
|
|
297
|
-
`https://your-staging-ssv-endpoint` +
|
|
298
|
-
new URLSearchParams({
|
|
299
|
-
ad_network: 'TEST',
|
|
300
|
-
ad_unit: 'TEST',
|
|
301
|
-
custom_data: customData, // <-- passed CustomData
|
|
302
|
-
reward_amount: 'TEST',
|
|
303
|
-
reward_item: 'TEST',
|
|
304
|
-
timestamp: 'TEST',
|
|
305
|
-
transaction_id: 'TEST',
|
|
306
|
-
user_id: userId, // <-- Passed UserID
|
|
307
|
-
signature: 'TEST',
|
|
308
|
-
key_id: 'TEST',
|
|
309
|
-
});
|
|
310
|
-
await fetch(url);
|
|
311
|
-
} catch (err) {
|
|
312
|
-
console.error(err);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
// ...
|
|
316
|
-
});
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
## Index
|
|
320
|
-
|
|
1
|
+
<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
|
+
<h3 align="center">AdMob</h3>
|
|
3
|
+
<p align="center"><strong><code>@capacitor-community/admob</code></strong></p>
|
|
4
|
+
<p align="center">
|
|
5
|
+
Capacitor community plugin for native AdMob.
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<img src="https://img.shields.io/maintenance/yes/2025?style=flat-square" />
|
|
10
|
+
<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>
|
|
11
|
+
<br>
|
|
12
|
+
<a href="https://www.npmjs.com/package/@capacitor-community/admob"><img src="https://img.shields.io/npm/dw/@capacitor-community/admob?style=flat-square" /></a>
|
|
13
|
+
<a href="https://www.npmjs.com/package/@capacitor-community/admob"><img src="https://img.shields.io/npm/v/@capacitor-community/admob?style=flat-square" /></a>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
## Maintainers
|
|
17
|
+
|
|
18
|
+
| Maintainer | GitHub | Social | Sponsoring Company |
|
|
19
|
+
| ------------------- | ------------------------------------------------ | ----------------------------------------------- | ---------------------------------------------- |
|
|
20
|
+
| Masahiko Sakakibara | [rdlabo](https://github.com/rdlabo) | [@rdlabo](https://twitter.com/rdlabo) | RELATION DESIGN LABO, GENERAL INC. ASSOCIATION |
|
|
21
|
+
| Saninn Salas Diaz | [Saninn Salas Diaz](https://github.com/distante) | [@SaninnSalas](https://twitter.com/SaninnSalas) | |
|
|
22
|
+
|
|
23
|
+
Maintenance Status: Actively Maintained
|
|
24
|
+
|
|
25
|
+
## Contributors ✨
|
|
26
|
+
|
|
27
|
+
<a href="https://github.com/capacitor-community/admob/graphs/contributors">
|
|
28
|
+
<img src="https://contrib.rocks/image?repo=capacitor-community/admob" />
|
|
29
|
+
</a>
|
|
30
|
+
|
|
31
|
+
Made with [contributors-img](https://contrib.rocks).
|
|
32
|
+
|
|
33
|
+
## Demo
|
|
34
|
+
|
|
35
|
+
[Demo code is here.](https://github.com/capacitor-community/admob/tree/master/demo)
|
|
36
|
+
|
|
37
|
+
### Screenshots
|
|
38
|
+
|
|
39
|
+
| | Banner | Interstitial | Reward |
|
|
40
|
+
| :---------- | :----------------------------------: | :----------------------------------------: | :----------------------------------: |
|
|
41
|
+
| **iOS** |  |  |  |
|
|
42
|
+
| **Android** |  |  |  |
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
If you use capacitor 6:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
% npm install --save @capacitor-community/admob@6
|
|
50
|
+
% npx cap update
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Android configuration
|
|
54
|
+
|
|
55
|
+
In file `android/app/src/main/AndroidManifest.xml`, add the following XML elements under `<manifest><application>` :
|
|
56
|
+
|
|
57
|
+
```xml
|
|
58
|
+
<meta-data
|
|
59
|
+
android:name="com.google.android.gms.ads.APPLICATION_ID"
|
|
60
|
+
android:value="@string/admob_app_id"/>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
In file `android/app/src/main/res/values/strings.xml` add the following lines :
|
|
64
|
+
|
|
65
|
+
```xml
|
|
66
|
+
<string name="admob_app_id">[APP_ID]</string>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Don't forget to replace `[APP_ID]` by your AdMob application Id.
|
|
70
|
+
|
|
71
|
+
#### Variables
|
|
72
|
+
|
|
73
|
+
This plugin will use the following project variables (defined in your app's `variables.gradle` file):
|
|
74
|
+
|
|
75
|
+
- `playServicesAdsVersion` version of `com.google.android.gms:play-services-ads` (default: `23.0.0`)
|
|
76
|
+
- `androidxCoreKTXVersion`: version of `androidx.core:core-ktx` (default: `1.13.0`)
|
|
77
|
+
|
|
78
|
+
### iOS configuration
|
|
79
|
+
|
|
80
|
+
Add the following in the `ios/App/App/info.plist` file inside of the outermost `<dict>`:
|
|
81
|
+
|
|
82
|
+
```xml
|
|
83
|
+
<key>GADIsAdManagerApp</key>
|
|
84
|
+
<true/>
|
|
85
|
+
<key>GADApplicationIdentifier</key>
|
|
86
|
+
<string>[APP_ID]</string>
|
|
87
|
+
<key>SKAdNetworkItems</key>
|
|
88
|
+
<array>
|
|
89
|
+
<dict>
|
|
90
|
+
<key>SKAdNetworkIdentifier</key>
|
|
91
|
+
<string>cstr6suwn9.skadnetwork</string>
|
|
92
|
+
</dict>
|
|
93
|
+
</array>
|
|
94
|
+
<key>NSUserTrackingUsageDescription</key>
|
|
95
|
+
<string>[Why you use NSUserTracking. ex: This identifier will be used to deliver personalized ads to you.]</string>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Don't forget to replace `[APP_ID]` by your AdMob application Id.
|
|
99
|
+
|
|
100
|
+
## Example
|
|
101
|
+
|
|
102
|
+
### Initialize AdMob
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
import { AdMob } from '@capacitor-community/admob';
|
|
106
|
+
|
|
107
|
+
export async function initialize(): Promise<void> {
|
|
108
|
+
await AdMob.initialize();
|
|
109
|
+
|
|
110
|
+
const [trackingInfo, consentInfo] = await Promise.all([
|
|
111
|
+
AdMob.trackingAuthorizationStatus(),
|
|
112
|
+
AdMob.requestConsentInfo(),
|
|
113
|
+
]);
|
|
114
|
+
|
|
115
|
+
if (trackingInfo.status === 'notDetermined') {
|
|
116
|
+
/**
|
|
117
|
+
* If you want to explain TrackingAuthorization before showing the iOS dialog,
|
|
118
|
+
* you can show the modal here.
|
|
119
|
+
* ex)
|
|
120
|
+
* const modal = await this.modalCtrl.create({
|
|
121
|
+
* component: RequestTrackingPage,
|
|
122
|
+
* });
|
|
123
|
+
* await modal.present();
|
|
124
|
+
* await modal.onDidDismiss(); // Wait for close modal
|
|
125
|
+
**/
|
|
126
|
+
|
|
127
|
+
await AdMob.requestTrackingAuthorization();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const authorizationStatus = await AdMob.trackingAuthorizationStatus();
|
|
131
|
+
if (
|
|
132
|
+
authorizationStatus.status === 'authorized' &&
|
|
133
|
+
consentInfo.isConsentFormAvailable &&
|
|
134
|
+
consentInfo.status === AdmobConsentStatus.REQUIRED
|
|
135
|
+
) {
|
|
136
|
+
await AdMob.showConsentForm();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
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
|
|
142
|
+
|
|
143
|
+
### User Message Platform (UMP)
|
|
144
|
+
|
|
145
|
+
Later this year, Google will require all publishers serving ads to EEA and UK users to use a Google-certified Consent Management Platform (CMP)
|
|
146
|
+
|
|
147
|
+
Currently we just support Google's consent management solution.
|
|
148
|
+
|
|
149
|
+
To use UMP, you must [create your GDPR messages](https://support.google.com/admob/answer/10113207?hl=en&ref_topic=10105230&sjid=6731900490614517032-AP)
|
|
150
|
+
|
|
151
|
+
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.
|
|
152
|
+
|
|
153
|
+
Example of how to use UMP
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
import { AdMob, AdmobConsentStatus, AdmobConsentDebugGeography } from '@capacitor-community/admob';
|
|
157
|
+
|
|
158
|
+
async showConsent() {
|
|
159
|
+
const consentInfo = await AdMob.requestConsentInfo();
|
|
160
|
+
|
|
161
|
+
if (consentInfo.isConsentFormAvailable && consentInfo.status === AdmobConsentStatus.REQUIRED) {
|
|
162
|
+
const {status} = await AdMob.showConsentForm();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
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).
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
const consentInfo = await AdMob.requestConsentInfo({
|
|
171
|
+
debugGeography: AdmobConsentDebugGeography.EEA,
|
|
172
|
+
testDeviceIdentifiers: ['YOUR_DEVICE_ID'],
|
|
173
|
+
});
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
**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.
|
|
177
|
+
|
|
178
|
+
**Note**: The order in which they are combined with other methods is as follows.
|
|
179
|
+
|
|
180
|
+
1. AdMob.initialize
|
|
181
|
+
2. AdMob.requestConsentInfo
|
|
182
|
+
3. AdMob.showConsentForm (If consent form required )
|
|
183
|
+
3/ AdMob.showBanner
|
|
184
|
+
|
|
185
|
+
### Show Banner
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
import {
|
|
189
|
+
AdMob,
|
|
190
|
+
BannerAdOptions,
|
|
191
|
+
BannerAdSize,
|
|
192
|
+
BannerAdPosition,
|
|
193
|
+
BannerAdPluginEvents,
|
|
194
|
+
AdMobBannerSize,
|
|
195
|
+
} from '@capacitor-community/admob';
|
|
196
|
+
|
|
197
|
+
export async function banner(): Promise<void> {
|
|
198
|
+
AdMob.addListener(BannerAdPluginEvents.Loaded, () => {
|
|
199
|
+
// Subscribe Banner Event Listener
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
AdMob.addListener(
|
|
203
|
+
BannerAdPluginEvents.SizeChanged,
|
|
204
|
+
(size: AdMobBannerSize) => {
|
|
205
|
+
// Subscribe Change Banner Size
|
|
206
|
+
},
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
const options: BannerAdOptions = {
|
|
210
|
+
adId: 'YOUR ADID',
|
|
211
|
+
adSize: BannerAdSize.BANNER,
|
|
212
|
+
position: BannerAdPosition.BOTTOM_CENTER,
|
|
213
|
+
margin: 0,
|
|
214
|
+
// isTesting: true
|
|
215
|
+
// npa: true
|
|
216
|
+
};
|
|
217
|
+
AdMob.showBanner(options);
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Show Interstitial
|
|
222
|
+
|
|
223
|
+
```ts
|
|
224
|
+
import {
|
|
225
|
+
AdMob,
|
|
226
|
+
AdOptions,
|
|
227
|
+
AdLoadInfo,
|
|
228
|
+
InterstitialAdPluginEvents,
|
|
229
|
+
} from '@capacitor-community/admob';
|
|
230
|
+
|
|
231
|
+
export async function interstitial(): Promise<void> {
|
|
232
|
+
AdMob.addListener(InterstitialAdPluginEvents.Loaded, (info: AdLoadInfo) => {
|
|
233
|
+
// Subscribe prepared interstitial
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
const options: AdOptions = {
|
|
237
|
+
adId: 'YOUR ADID',
|
|
238
|
+
// isTesting: true
|
|
239
|
+
// npa: true
|
|
240
|
+
};
|
|
241
|
+
await AdMob.prepareInterstitial(options);
|
|
242
|
+
await AdMob.showInterstitial();
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Show RewardVideo
|
|
247
|
+
|
|
248
|
+
```ts
|
|
249
|
+
import {
|
|
250
|
+
AdMob,
|
|
251
|
+
RewardAdOptions,
|
|
252
|
+
AdLoadInfo,
|
|
253
|
+
RewardAdPluginEvents,
|
|
254
|
+
AdMobRewardItem,
|
|
255
|
+
} from '@capacitor-community/admob';
|
|
256
|
+
|
|
257
|
+
export async function rewardVideo(): Promise<void> {
|
|
258
|
+
AdMob.addListener(RewardAdPluginEvents.Loaded, (info: AdLoadInfo) => {
|
|
259
|
+
// Subscribe prepared rewardVideo
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
AdMob.addListener(
|
|
263
|
+
RewardAdPluginEvents.Rewarded,
|
|
264
|
+
(rewardItem: AdMobRewardItem) => {
|
|
265
|
+
// Subscribe user rewarded
|
|
266
|
+
console.log(rewardItem);
|
|
267
|
+
},
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
const options: RewardAdOptions = {
|
|
271
|
+
adId: 'YOUR ADID',
|
|
272
|
+
// isTesting: true
|
|
273
|
+
// npa: true
|
|
274
|
+
// ssv: {
|
|
275
|
+
// userId: "A user ID to send to your SSV"
|
|
276
|
+
// customData: JSON.stringify({ ...MyCustomData })
|
|
277
|
+
//}
|
|
278
|
+
};
|
|
279
|
+
await AdMob.prepareRewardVideoAd(options);
|
|
280
|
+
const rewardItem = await AdMob.showRewardVideoAd();
|
|
281
|
+
}
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## Server-side Verification Notice
|
|
285
|
+
|
|
286
|
+
SSV callbacks are only fired on Production Adverts, therefore test Ads will not fire off your SSV callback.
|
|
287
|
+
|
|
288
|
+
For E2E tests or just for validating the data in your `RewardAdOptions` work as expected, you can add a custom GET
|
|
289
|
+
request to your mock endpoint after the `RewardAdPluginEvents.Rewarded` similar to this:
|
|
290
|
+
|
|
291
|
+
```ts
|
|
292
|
+
AdMob.addListener(RewardAdPluginEvents.Rewarded, async () => {
|
|
293
|
+
// ...
|
|
294
|
+
if (ENVIRONMENT_IS_DEVELOPMENT) {
|
|
295
|
+
try {
|
|
296
|
+
const url =
|
|
297
|
+
`https://your-staging-ssv-endpoint` +
|
|
298
|
+
new URLSearchParams({
|
|
299
|
+
ad_network: 'TEST',
|
|
300
|
+
ad_unit: 'TEST',
|
|
301
|
+
custom_data: customData, // <-- passed CustomData
|
|
302
|
+
reward_amount: 'TEST',
|
|
303
|
+
reward_item: 'TEST',
|
|
304
|
+
timestamp: 'TEST',
|
|
305
|
+
transaction_id: 'TEST',
|
|
306
|
+
user_id: userId, // <-- Passed UserID
|
|
307
|
+
signature: 'TEST',
|
|
308
|
+
key_id: 'TEST',
|
|
309
|
+
});
|
|
310
|
+
await fetch(url);
|
|
311
|
+
} catch (err) {
|
|
312
|
+
console.error(err);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
// ...
|
|
316
|
+
});
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
## Index
|
|
320
|
+
|
|
321
321
|
<docgen-index>
|
|
322
322
|
|
|
323
323
|
* [`initialize(...)`](#initialize)
|
|
@@ -365,10 +365,10 @@ AdMob.addListener(RewardAdPluginEvents.Rewarded, async () => {
|
|
|
365
365
|
* [Type Aliases](#type-aliases)
|
|
366
366
|
* [Enums](#enums)
|
|
367
367
|
|
|
368
|
-
</docgen-index>
|
|
369
|
-
|
|
370
|
-
## API
|
|
371
|
-
|
|
368
|
+
</docgen-index>
|
|
369
|
+
|
|
370
|
+
## API
|
|
371
|
+
|
|
372
372
|
<docgen-api>
|
|
373
373
|
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
374
374
|
|
|
@@ -1303,17 +1303,17 @@ From T, pick a set of properties whose keys are in the union K
|
|
|
1303
1303
|
| **`Dismissed`** | <code>'onRewardedInterstitialAdDismissed'</code> | 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. |
|
|
1304
1304
|
| **`Rewarded`** | <code>'onRewardedInterstitialAdReward'</code> | Emits when user get rewarded from AdReward |
|
|
1305
1305
|
|
|
1306
|
-
</docgen-api>
|
|
1307
|
-
|
|
1308
|
-
## TROUBLE SHOOTING
|
|
1309
|
-
|
|
1310
|
-
### If you have error:
|
|
1311
|
-
|
|
1312
|
-
> [error] Error running update: Analyzing dependencies
|
|
1313
|
-
> [!] CocoaPods could not find compatible versions for pod "Google-Mobile-Ads-SDK":
|
|
1314
|
-
|
|
1315
|
-
You should run `pod repo update` ;
|
|
1316
|
-
|
|
1317
|
-
## License
|
|
1318
|
-
|
|
1319
|
-
Capacitor AdMob is [MIT licensed](./LICENSE).
|
|
1306
|
+
</docgen-api>
|
|
1307
|
+
|
|
1308
|
+
## TROUBLE SHOOTING
|
|
1309
|
+
|
|
1310
|
+
### If you have error:
|
|
1311
|
+
|
|
1312
|
+
> [error] Error running update: Analyzing dependencies
|
|
1313
|
+
> [!] CocoaPods could not find compatible versions for pod "Google-Mobile-Ads-SDK":
|
|
1314
|
+
|
|
1315
|
+
You should run `pod repo update` ;
|
|
1316
|
+
|
|
1317
|
+
## License
|
|
1318
|
+
|
|
1319
|
+
Capacitor AdMob is [MIT licensed](./LICENSE).
|
package/package.json
CHANGED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
-
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
|
-
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
4
|
-
xmlns:tools="http://schemas.android.com/tools"
|
|
5
|
-
android:layout_width="match_parent"
|
|
6
|
-
android:layout_height="match_parent"
|
|
7
|
-
tools:context="com.getcapacitor.BridgeActivity"
|
|
8
|
-
>
|
|
9
|
-
|
|
10
|
-
<WebView
|
|
11
|
-
android:id="@+id/webview"
|
|
12
|
-
android:layout_width="fill_parent"
|
|
13
|
-
android:layout_height="fill_parent" />
|
|
14
|
-
|
|
15
|
-
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|