@capacitor-community/admob 3.1.0 → 3.3.0
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/LICENSE +1 -1
- package/README.md +91 -36
- package/android/build.gradle +11 -9
- package/android/src/main/java/com/getcapacitor/community/admob/models/AdOptions.java +16 -2
- package/android/src/main/java/com/getcapacitor/community/admob/rewarded/AdRewardExecutor.java +1 -1
- package/android/src/main/java/com/getcapacitor/community/admob/rewarded/RewardedAdCallbackAndListeners.kt +14 -1
- package/android/src/main/java/com/getcapacitor/community/admob/rewarded/models/SsvInfo.kt +20 -0
- package/dist/docs.json +73 -6
- package/dist/esm/reward/index.d.ts +1 -0
- package/dist/esm/reward/index.js +1 -0
- package/dist/esm/reward/index.js.map +1 -1
- package/dist/esm/reward/reward-ad-options.interface.d.ts +25 -0
- package/dist/esm/reward/reward-ad-options.interface.js +2 -0
- package/dist/esm/reward/reward-ad-options.interface.js.map +1 -0
- package/dist/esm/reward/reward-definitions.interface.d.ts +4 -3
- package/dist/plugin.js +1 -1
- package/ios/Plugin/Banner/BannerExecutor.swift +6 -5
- package/ios/Plugin/Interstitial/AdInterstitialExecutor.swift +5 -5
- package/ios/Plugin/Rewarded/AdRewardExecutor.swift +22 -5
- package/package.json +3 -4
- package/ios/Plugin/.DS_Store +0 -0
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -6,15 +6,12 @@
|
|
|
6
6
|
</p>
|
|
7
7
|
|
|
8
8
|
<p align="center">
|
|
9
|
-
<img src="https://img.shields.io/maintenance/yes/
|
|
9
|
+
<img src="https://img.shields.io/maintenance/yes/2022?style=flat-square" />
|
|
10
10
|
<!-- <a href="https://github.com/capacitor-community/example/actions?query=workflow%3A%22CI%22"><img src="https://img.shields.io/github/workflow/status/capacitor-community/example/CI?style=flat-square" /></a> -->
|
|
11
11
|
<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>
|
|
12
12
|
<br>
|
|
13
13
|
<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>
|
|
14
14
|
<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>
|
|
15
|
-
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
16
|
-
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-4-orange?style=flat-square" /></a>
|
|
17
|
-
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
18
15
|
</p>
|
|
19
16
|
|
|
20
17
|
## Maintainers
|
|
@@ -26,9 +23,16 @@
|
|
|
26
23
|
|
|
27
24
|
Maintenance Status: Actively Maintained
|
|
28
25
|
|
|
26
|
+
## Contributors ✨
|
|
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
|
+
|
|
29
33
|
## Demo
|
|
30
34
|
|
|
31
|
-
[Demo code is here.](https://github.com/capacitor-community/admob/tree/
|
|
35
|
+
[Demo code is here.](https://github.com/capacitor-community/admob/tree/master/demo)
|
|
32
36
|
|
|
33
37
|
### Screenshots
|
|
34
38
|
|
|
@@ -49,6 +53,8 @@ Maintenance Status: Actively Maintained
|
|
|
49
53
|
In file `android/app/src/main/java/**/**/MainActivity.java`, add the plugin to the initialization list:
|
|
50
54
|
|
|
51
55
|
```java
|
|
56
|
+
import android.os.Bundle;
|
|
57
|
+
|
|
52
58
|
public class MainActivity extends BridgeActivity {
|
|
53
59
|
@Override
|
|
54
60
|
public void onCreate(Bundle savedInstanceState) {
|
|
@@ -104,6 +110,21 @@ Don't forget to replace `[APP_ID]` by your AdMob application Id.
|
|
|
104
110
|
import { AdMob } from '@capacitor-community/admob';
|
|
105
111
|
|
|
106
112
|
export async function initialize(): Promise<void> {
|
|
113
|
+
const { status } = await AdMob.trackingAuthorizationStatus();
|
|
114
|
+
|
|
115
|
+
if (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
|
+
|
|
107
128
|
AdMob.initialize({
|
|
108
129
|
requestTrackingAuthorization: true,
|
|
109
130
|
testingDevices: ['2077ef9a63d2b398840261c8221a0c9b'],
|
|
@@ -169,7 +190,7 @@ export async function interstitial(): Promise<void> {
|
|
|
169
190
|
### Show RewardVideo
|
|
170
191
|
|
|
171
192
|
```ts
|
|
172
|
-
import { AdMob,
|
|
193
|
+
import { AdMob, RewardAdOptions, AdLoadInfo, RewardAdPluginEvents, AdMobRewardItem } from '@capacitor-community/admob';
|
|
173
194
|
|
|
174
195
|
export async function rewardVideo(): Promise<void> {
|
|
175
196
|
AdMob.addListener(RewardAdPluginEvents.Loaded, (info: AdLoadInfo) => {
|
|
@@ -181,16 +202,52 @@ export async function rewardVideo(): Promise<void> {
|
|
|
181
202
|
console.log(rewardItem);
|
|
182
203
|
});
|
|
183
204
|
|
|
184
|
-
const options:
|
|
205
|
+
const options: RewardAdOptions = {
|
|
185
206
|
adId: 'YOUR ADID',
|
|
186
207
|
// isTesting: true
|
|
187
208
|
// npa: true
|
|
209
|
+
// ssv: {
|
|
210
|
+
// userId: "A user ID to send to your SSV"
|
|
211
|
+
// customData: JSON.stringify({ ...MyCustomData })
|
|
212
|
+
//}
|
|
188
213
|
};
|
|
189
214
|
await AdMob.prepareRewardVideoAd(options);
|
|
190
215
|
const rewardItem = await AdMob.showRewardVideoAd();
|
|
191
216
|
}
|
|
192
217
|
```
|
|
193
218
|
|
|
219
|
+
## Server-side Verification Notice
|
|
220
|
+
SSV callbacks are only fired on Production Adverts, therefore test Ads will not fire off your SSV callback.
|
|
221
|
+
|
|
222
|
+
For E2E tests or just for validating the data in your `RewardAdOptions` work as expected, you can add a custom GET
|
|
223
|
+
request to your mock endpoint after the `RewardAdPluginEvents.Rewarded` similar to this:
|
|
224
|
+
```ts
|
|
225
|
+
AdMob.addListener(RewardAdPluginEvents.Rewarded, async () => {
|
|
226
|
+
// ...
|
|
227
|
+
if (ENVIRONMENT_IS_DEVELOPMENT) {
|
|
228
|
+
try {
|
|
229
|
+
const url = `https://your-staging-ssv-endpoint` + new URLSearchParams({
|
|
230
|
+
'ad_network': 'TEST',
|
|
231
|
+
'ad_unit': 'TEST',
|
|
232
|
+
'custom_data': customData, // <-- passed CustomData
|
|
233
|
+
'reward_amount': 'TEST',
|
|
234
|
+
'reward_item': 'TEST',
|
|
235
|
+
'timestamp': 'TEST',
|
|
236
|
+
'transaction_id': 'TEST',
|
|
237
|
+
'user_id': userId, // <-- Passed UserID
|
|
238
|
+
'signature': 'TEST',
|
|
239
|
+
'key_id': 'TEST'
|
|
240
|
+
});
|
|
241
|
+
await fetch(url);
|
|
242
|
+
} catch (err) {
|
|
243
|
+
console.error(err);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
// ...
|
|
247
|
+
});
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
|
|
194
251
|
## Index
|
|
195
252
|
<docgen-index>
|
|
196
253
|
|
|
@@ -222,6 +279,7 @@ export async function rewardVideo(): Promise<void> {
|
|
|
222
279
|
* [`addListener(RewardAdPluginEvents.FailedToShow, ...)`](#addlistenerrewardadplugineventsfailedtoshow-)
|
|
223
280
|
* [`addListener(RewardAdPluginEvents.Showed, ...)`](#addlistenerrewardadplugineventsshowed-)
|
|
224
281
|
* [Interfaces](#interfaces)
|
|
282
|
+
* [Type Aliases](#type-aliases)
|
|
225
283
|
* [Enums](#enums)
|
|
226
284
|
|
|
227
285
|
</docgen-index>
|
|
@@ -523,14 +581,14 @@ addListener(eventName: InterstitialAdPluginEvents.Showed, listenerFunc: () => vo
|
|
|
523
581
|
### prepareRewardVideoAd(...)
|
|
524
582
|
|
|
525
583
|
```typescript
|
|
526
|
-
prepareRewardVideoAd(options:
|
|
584
|
+
prepareRewardVideoAd(options: RewardAdOptions) => Promise<AdLoadInfo>
|
|
527
585
|
```
|
|
528
586
|
|
|
529
587
|
Prepare a reward video ad
|
|
530
588
|
|
|
531
|
-
| Param | Type
|
|
532
|
-
| ------------- |
|
|
533
|
-
| **`options`** | <code><a href="#
|
|
589
|
+
| Param | Type | Description |
|
|
590
|
+
| ------------- | ----------------------------------------------------------- | ---------------------------------------------- |
|
|
591
|
+
| **`options`** | <code><a href="#rewardadoptions">RewardAdOptions</a></code> | <a href="#rewardadoptions">RewardAdOptions</a> |
|
|
534
592
|
|
|
535
593
|
**Returns:** <code>Promise<<a href="#adloadinfo">AdLoadInfo</a>></code>
|
|
536
594
|
|
|
@@ -723,6 +781,13 @@ https://developers.google.com/android/reference/com/google/android/gms/ads/AdErr
|
|
|
723
781
|
| **`npa`** | <code>boolean</code> | The default behavior of the Google Mobile Ads SDK is to serve personalized ads. Set this to true to request Non-Personalized Ads |
|
|
724
782
|
|
|
725
783
|
|
|
784
|
+
#### RewardAdOptions
|
|
785
|
+
|
|
786
|
+
| Prop | Type | Description |
|
|
787
|
+
| --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
788
|
+
| **`ssv`** | <code><a href="#atleastone">AtLeastOne</a><{ /** * 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; }></code> | 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. |
|
|
789
|
+
|
|
790
|
+
|
|
726
791
|
#### AdMobRewardItem
|
|
727
792
|
|
|
728
793
|
For more information
|
|
@@ -734,6 +799,21 @@ https://developers.google.com/admob/android/rewarded-video-adapters?hl=en
|
|
|
734
799
|
| **`amount`** | <code>number</code> | Rewarded amount user got |
|
|
735
800
|
|
|
736
801
|
|
|
802
|
+
### Type Aliases
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
#### AtLeastOne
|
|
806
|
+
|
|
807
|
+
<code>{[K in keyof T]: <a href="#pick">Pick</a><T, K>}[keyof T]</code>
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
#### Pick
|
|
811
|
+
|
|
812
|
+
From T, pick a set of properties whose keys are in the union K
|
|
813
|
+
|
|
814
|
+
<code>{
|
|
737
815
|
[P in K]: T[P];
|
|
738
816
|
}</code>
|
|
817
|
+
|
|
818
|
+
|
|
739
819
|
### Enums
|
|
740
820
|
|
|
741
821
|
|
|
@@ -817,28 +897,3 @@ You should run `pod repo update` ;
|
|
|
817
897
|
## License
|
|
818
898
|
|
|
819
899
|
Capacitor AdMob is [MIT licensed](./LICENSE).
|
|
820
|
-
|
|
821
|
-
## Contributors ✨
|
|
822
|
-
|
|
823
|
-
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
|
824
|
-
|
|
825
|
-
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
|
826
|
-
<!-- prettier-ignore-start -->
|
|
827
|
-
<!-- markdownlint-disable -->
|
|
828
|
-
<table>
|
|
829
|
-
<tr>
|
|
830
|
-
<td align="center"><a href="https://wako.app"><img src="https://avatars1.githubusercontent.com/u/216573?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jean-Baptiste Malatrasi</b></sub></a><br /><a href="https://github.com/capacitor-community/admob/commits?author=JumBay" title="Code">💻</a></td>
|
|
831
|
-
<td align="center"><a href="https://github.com/gant02"><img src="https://avatars1.githubusercontent.com/u/6771123?v=4?s=100" width="100px;" alt=""/><br /><sub><b>gant02</b></sub></a><br /><a href="https://github.com/capacitor-community/admob/commits?author=gant02" title="Code">💻</a></td>
|
|
832
|
-
<td align="center"><a href="https://www.saninnsalas.com"><img src="https://avatars1.githubusercontent.com/u/5490201?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Saninn Salas Diaz</b></sub></a><br /><a href="https://github.com/capacitor-community/admob/commits?author=distante" title="Code">💻</a></td>
|
|
833
|
-
<td align="center"><a href="https://www.nicolueg.com"><img src="https://avatars.githubusercontent.com/u/48101693?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Nico Lueg</b></sub></a><br /><a href="https://github.com/capacitor-community/admob/commits?author=NLueg" title="Code">💻</a></td>
|
|
834
|
-
<td align="center"><a href="https://www.linkedin.com/in/ghonche-yqr-21774b114/"><img src="https://avatars.githubusercontent.com/u/25591295?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ghonche Yqr</b></sub></a><br /><a href="https://github.com/capacitor-community/admob/commits?author=ghonche-yqr" title="Documentation">📖</a></td>
|
|
835
|
-
<td align="center"><a href="https://github.com/vanessag"><img src="https://avatars.githubusercontent.com/u/4007550?v=4?s=100" width="100px;" alt=""/><br /><sub><b>vanessag</b></sub></a><br /><a href="https://github.com/capacitor-community/admob/commits?author=vanessag" title="Code">💻</a></td>
|
|
836
|
-
</tr>
|
|
837
|
-
</table>
|
|
838
|
-
|
|
839
|
-
<!-- markdownlint-restore -->
|
|
840
|
-
<!-- prettier-ignore-end -->
|
|
841
|
-
|
|
842
|
-
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
843
|
-
|
|
844
|
-
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
|
package/android/build.gradle
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
ext {
|
|
2
|
-
junitVersion =
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.1'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.2.0'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.2'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.3.0'
|
|
5
6
|
}
|
|
6
7
|
|
|
7
8
|
buildscript {
|
|
8
|
-
ext.kotlin_version = '1.
|
|
9
|
+
ext.kotlin_version = '1.5.21'
|
|
9
10
|
repositories {
|
|
10
11
|
google()
|
|
11
12
|
jcenter()
|
|
@@ -49,7 +50,7 @@ repositories {
|
|
|
49
50
|
mavenCentral()
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
def testRunner = "1.
|
|
53
|
+
def testRunner = "1.4.0"
|
|
53
54
|
|
|
54
55
|
dependencies {
|
|
55
56
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
@@ -70,14 +71,15 @@ dependencies {
|
|
|
70
71
|
// androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
71
72
|
// androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
implementation 'com.android.
|
|
74
|
+
// after 20.5.0, require minCompileSdk (31)
|
|
75
|
+
implementation 'com.google.android.gms:play-services-ads:20.4.0'
|
|
76
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
75
77
|
implementation "androidx.coordinatorlayout:coordinatorlayout:1.1.0"
|
|
76
|
-
implementation "androidx.core:core-ktx:1.
|
|
78
|
+
implementation "androidx.core:core-ktx:1.6.0"
|
|
77
79
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
// Allow to run unit test with ./gradlew test
|
|
81
83
|
tasks.withType(Test) {
|
|
82
84
|
useJUnitPlatform()
|
|
83
|
-
}
|
|
85
|
+
}
|
|
@@ -3,6 +3,7 @@ package com.getcapacitor.community.admob.models;
|
|
|
3
3
|
import androidx.annotation.VisibleForTesting;
|
|
4
4
|
import com.getcapacitor.PluginCall;
|
|
5
5
|
import com.getcapacitor.community.admob.banner.BannerAdSizeEnum;
|
|
6
|
+
import com.getcapacitor.community.admob.rewarded.models.SsvInfo;
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Holds the options for an Ad Request
|
|
@@ -59,6 +60,11 @@ public abstract class AdOptions {
|
|
|
59
60
|
*/
|
|
60
61
|
public final boolean npa;
|
|
61
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Used for Server side verification of Reward Ads
|
|
65
|
+
*/
|
|
66
|
+
public final SsvInfo ssvInfo;
|
|
67
|
+
|
|
62
68
|
private AdOptions(PluginCall call) {
|
|
63
69
|
/*
|
|
64
70
|
* TODO: Since the Id in the Typescript AdOptions interface is not optional
|
|
@@ -72,18 +78,20 @@ public abstract class AdOptions {
|
|
|
72
78
|
this.position = call.getString("position", "BOTTOM_CENTER");
|
|
73
79
|
this.margin = call.getInt("margin", 0);
|
|
74
80
|
this.npa = call.getBoolean("npa", false);
|
|
81
|
+
this.ssvInfo = new SsvInfo(call);
|
|
75
82
|
|
|
76
83
|
String sizeString = call.getString("adSize", BannerAdSizeEnum.ADAPTIVE_BANNER.name());
|
|
77
84
|
this.adSize = AdOptions.adSizeStringToAdSizeEnum(sizeString);
|
|
78
85
|
}
|
|
79
86
|
|
|
80
|
-
private AdOptions(String id, boolean isTesting, String position, int margin, boolean npa, BannerAdSizeEnum adSize) {
|
|
87
|
+
private AdOptions(String id, boolean isTesting, String position, int margin, boolean npa, BannerAdSizeEnum adSize, SsvInfo ssvInfo) {
|
|
81
88
|
this.adId = id;
|
|
82
89
|
this.isTesting = isTesting;
|
|
83
90
|
this.position = position;
|
|
84
91
|
this.margin = margin;
|
|
85
92
|
this.npa = npa;
|
|
86
93
|
this.adSize = adSize;
|
|
94
|
+
this.ssvInfo = ssvInfo;
|
|
87
95
|
}
|
|
88
96
|
|
|
89
97
|
/**
|
|
@@ -163,6 +171,12 @@ public abstract class AdOptions {
|
|
|
163
171
|
private int margin = 1;
|
|
164
172
|
private boolean npa = false;
|
|
165
173
|
private BannerAdSizeEnum adSize = BannerAdSizeEnum.ADAPTIVE_BANNER;
|
|
174
|
+
private SsvInfo ssvInfo = new SsvInfo();
|
|
175
|
+
|
|
176
|
+
public TesterAdOptionsBuilder setSsvInfo(SsvInfo info) {
|
|
177
|
+
ssvInfo = info;
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
166
180
|
|
|
167
181
|
public TesterAdOptionsBuilder setIsTesting(boolean value) {
|
|
168
182
|
isTesting = value;
|
|
@@ -200,7 +214,7 @@ public abstract class AdOptions {
|
|
|
200
214
|
}
|
|
201
215
|
|
|
202
216
|
public AdOptions build() {
|
|
203
|
-
return new AdOptions(id, isTesting, position, margin, npa, adSize) {
|
|
217
|
+
return new AdOptions(id, isTesting, position, margin, npa, adSize, ssvInfo) {
|
|
204
218
|
@Override
|
|
205
219
|
public String getTestingId() {
|
|
206
220
|
return testingID;
|
package/android/src/main/java/com/getcapacitor/community/admob/rewarded/AdRewardExecutor.java
CHANGED
|
@@ -43,7 +43,7 @@ public class AdRewardExecutor extends Executor {
|
|
|
43
43
|
contextSupplier.get(),
|
|
44
44
|
id,
|
|
45
45
|
adRequest,
|
|
46
|
-
RewardedAdCallbackAndListeners.INSTANCE.getRewardedAdLoadCallback(call, notifyListenersFunction)
|
|
46
|
+
RewardedAdCallbackAndListeners.INSTANCE.getRewardedAdLoadCallback(call, notifyListenersFunction, adOptions)
|
|
47
47
|
);
|
|
48
48
|
} catch (Exception ex) {
|
|
49
49
|
call.reject(ex.getLocalizedMessage(), ex);
|
|
@@ -4,11 +4,13 @@ import com.getcapacitor.JSObject
|
|
|
4
4
|
import com.getcapacitor.PluginCall
|
|
5
5
|
import com.getcapacitor.community.admob.helpers.FullscreenPluginCallback
|
|
6
6
|
import com.getcapacitor.community.admob.models.AdMobPluginError
|
|
7
|
+
import com.getcapacitor.community.admob.models.AdOptions
|
|
7
8
|
import com.google.android.gms.ads.LoadAdError
|
|
8
9
|
import com.google.android.gms.ads.OnUserEarnedRewardListener
|
|
9
10
|
import com.google.android.gms.ads.rewarded.RewardItem
|
|
10
11
|
import com.google.android.gms.ads.rewarded.RewardedAd
|
|
11
12
|
import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback
|
|
13
|
+
import com.google.android.gms.ads.rewarded.ServerSideVerificationOptions
|
|
12
14
|
import com.google.android.gms.common.util.BiConsumer
|
|
13
15
|
|
|
14
16
|
object RewardedAdCallbackAndListeners {
|
|
@@ -23,13 +25,24 @@ object RewardedAdCallbackAndListeners {
|
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
27
|
|
|
26
|
-
fun getRewardedAdLoadCallback(call: PluginCall, notifyListenersFunction: BiConsumer<String, JSObject
|
|
28
|
+
fun getRewardedAdLoadCallback(call: PluginCall, notifyListenersFunction: BiConsumer<String, JSObject>, adOptions: AdOptions): RewardedAdLoadCallback {
|
|
27
29
|
return object : RewardedAdLoadCallback() {
|
|
28
30
|
override fun onAdLoaded(ad: RewardedAd) {
|
|
29
31
|
AdRewardExecutor.mRewardedAd = ad
|
|
30
32
|
AdRewardExecutor.mRewardedAd.fullScreenContentCallback = FullscreenPluginCallback(
|
|
31
33
|
RewardAdPluginEvents, notifyListenersFunction)
|
|
32
34
|
|
|
35
|
+
if(adOptions.ssvInfo.hasInfo){
|
|
36
|
+
val ssvOptions = ServerSideVerificationOptions.Builder()
|
|
37
|
+
adOptions.ssvInfo.customData?.let {
|
|
38
|
+
ssvOptions.setCustomData(it)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
adOptions.ssvInfo.userId?.let {
|
|
42
|
+
ssvOptions.setUserId(it)
|
|
43
|
+
}
|
|
44
|
+
AdRewardExecutor.mRewardedAd.setServerSideVerificationOptions(ssvOptions.build())
|
|
45
|
+
}
|
|
33
46
|
|
|
34
47
|
val adInfo = JSObject()
|
|
35
48
|
adInfo.put("adUnitId", ad.adUnitId)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
package com.getcapacitor.community.admob.rewarded.models
|
|
2
|
+
|
|
3
|
+
import com.getcapacitor.PluginCall
|
|
4
|
+
|
|
5
|
+
class SsvInfo(
|
|
6
|
+
val customData: String? = null,
|
|
7
|
+
val userId: String? = null) {
|
|
8
|
+
|
|
9
|
+
constructor(pluginCall: PluginCall?) : this(
|
|
10
|
+
pluginCall?.getObject("ssv")?.getString("customData"),
|
|
11
|
+
pluginCall?.getObject("ssv")?.getString("userId")
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
constructor() : this(null, null)
|
|
15
|
+
|
|
16
|
+
val hasInfo
|
|
17
|
+
get(): Boolean {
|
|
18
|
+
return customData != null || userId != null
|
|
19
|
+
}
|
|
20
|
+
}
|
package/dist/docs.json
CHANGED
|
@@ -860,12 +860,12 @@
|
|
|
860
860
|
},
|
|
861
861
|
{
|
|
862
862
|
"name": "prepareRewardVideoAd",
|
|
863
|
-
"signature": "(options:
|
|
863
|
+
"signature": "(options: RewardAdOptions) => Promise<AdLoadInfo>",
|
|
864
864
|
"parameters": [
|
|
865
865
|
{
|
|
866
866
|
"name": "options",
|
|
867
|
-
"docs": "
|
|
868
|
-
"type": "
|
|
867
|
+
"docs": "RewardAdOptions",
|
|
868
|
+
"type": "RewardAdOptions"
|
|
869
869
|
}
|
|
870
870
|
],
|
|
871
871
|
"returns": "Promise<AdLoadInfo>",
|
|
@@ -891,7 +891,7 @@
|
|
|
891
891
|
"kind": "space"
|
|
892
892
|
},
|
|
893
893
|
{
|
|
894
|
-
"text": "
|
|
894
|
+
"text": "RewardAdOptions",
|
|
895
895
|
"kind": "text"
|
|
896
896
|
}
|
|
897
897
|
]
|
|
@@ -909,7 +909,7 @@
|
|
|
909
909
|
"docs": "Prepare a reward video ad",
|
|
910
910
|
"complexTypes": [
|
|
911
911
|
"AdLoadInfo",
|
|
912
|
-
"
|
|
912
|
+
"RewardAdOptions"
|
|
913
913
|
],
|
|
914
914
|
"slug": "preparerewardvideoad"
|
|
915
915
|
},
|
|
@@ -1652,6 +1652,42 @@
|
|
|
1652
1652
|
],
|
|
1653
1653
|
"importObject": []
|
|
1654
1654
|
},
|
|
1655
|
+
{
|
|
1656
|
+
"name": "RewardAdOptions",
|
|
1657
|
+
"slug": "rewardadoptions",
|
|
1658
|
+
"docs": "",
|
|
1659
|
+
"tags": [],
|
|
1660
|
+
"methods": [],
|
|
1661
|
+
"properties": [
|
|
1662
|
+
{
|
|
1663
|
+
"name": "ssv",
|
|
1664
|
+
"tags": [
|
|
1665
|
+
{
|
|
1666
|
+
"text": [
|
|
1667
|
+
{
|
|
1668
|
+
"text": "https",
|
|
1669
|
+
"kind": "text"
|
|
1670
|
+
},
|
|
1671
|
+
{
|
|
1672
|
+
"text": "://support.google.com/admob/answer/9603226?hl=en-GB",
|
|
1673
|
+
"kind": "text"
|
|
1674
|
+
}
|
|
1675
|
+
],
|
|
1676
|
+
"name": "see"
|
|
1677
|
+
}
|
|
1678
|
+
],
|
|
1679
|
+
"docs": "If you have enabled SSV in your AdMob Application. You can provide customData or\na userId be passed to your callback to do further processing on.\n\n*Important* You *HAVE* to define one of them.",
|
|
1680
|
+
"complexTypes": [
|
|
1681
|
+
"AtLeastOne"
|
|
1682
|
+
],
|
|
1683
|
+
"type": "AtLeastOne<{\n /**\n * An optional UserId to pass to your SSV callback function.\n */\n userId: string;\n /**\n * An optional custom set of data to pass to your SSV callback function.\n */\n customData: string;\n }>"
|
|
1684
|
+
}
|
|
1685
|
+
],
|
|
1686
|
+
"importObject": [
|
|
1687
|
+
"AdOptions",
|
|
1688
|
+
"AtLeastOne"
|
|
1689
|
+
]
|
|
1690
|
+
},
|
|
1655
1691
|
{
|
|
1656
1692
|
"name": "AdMobRewardItem",
|
|
1657
1693
|
"slug": "admobrewarditem",
|
|
@@ -1911,6 +1947,37 @@
|
|
|
1911
1947
|
]
|
|
1912
1948
|
}
|
|
1913
1949
|
],
|
|
1914
|
-
"typeAliases": [
|
|
1950
|
+
"typeAliases": [
|
|
1951
|
+
{
|
|
1952
|
+
"name": "AtLeastOne",
|
|
1953
|
+
"slug": "atleastone",
|
|
1954
|
+
"docs": "",
|
|
1955
|
+
"types": [
|
|
1956
|
+
{
|
|
1957
|
+
"text": "{[K in keyof T]: Pick<T, K>}[keyof T]",
|
|
1958
|
+
"complexTypes": [
|
|
1959
|
+
"T",
|
|
1960
|
+
"Pick",
|
|
1961
|
+
"K"
|
|
1962
|
+
]
|
|
1963
|
+
}
|
|
1964
|
+
]
|
|
1965
|
+
},
|
|
1966
|
+
{
|
|
1967
|
+
"name": "Pick",
|
|
1968
|
+
"slug": "pick",
|
|
1969
|
+
"docs": "From T, pick a set of properties whose keys are in the union K",
|
|
1970
|
+
"types": [
|
|
1971
|
+
{
|
|
1972
|
+
"text": "{\r\n [P in K]: T[P];\r\n}",
|
|
1973
|
+
"complexTypes": [
|
|
1974
|
+
"K",
|
|
1975
|
+
"T",
|
|
1976
|
+
"P"
|
|
1977
|
+
]
|
|
1978
|
+
}
|
|
1979
|
+
]
|
|
1980
|
+
}
|
|
1981
|
+
],
|
|
1915
1982
|
"pluginConfigs": []
|
|
1916
1983
|
}
|
package/dist/esm/reward/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/reward/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/reward/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,+BAA+B,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AdOptions } from '../shared/ad-options.interface';
|
|
2
|
+
declare type AtLeastOne<T> = {
|
|
3
|
+
[K in keyof T]: Pick<T, K>;
|
|
4
|
+
}[keyof T];
|
|
5
|
+
export interface RewardAdOptions extends AdOptions {
|
|
6
|
+
/**
|
|
7
|
+
* If you have enabled SSV in your AdMob Application. You can provide customData or
|
|
8
|
+
* a userId be passed to your callback to do further processing on.
|
|
9
|
+
*
|
|
10
|
+
* *Important* You *HAVE* to define one of them.
|
|
11
|
+
*
|
|
12
|
+
* @see https://support.google.com/admob/answer/9603226?hl=en-GB
|
|
13
|
+
*/
|
|
14
|
+
ssv?: AtLeastOne<{
|
|
15
|
+
/**
|
|
16
|
+
* An optional UserId to pass to your SSV callback function.
|
|
17
|
+
*/
|
|
18
|
+
userId: string;
|
|
19
|
+
/**
|
|
20
|
+
* An optional custom set of data to pass to your SSV callback function.
|
|
21
|
+
*/
|
|
22
|
+
customData: string;
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reward-ad-options.interface.js","sourceRoot":"","sources":["../../../src/reward/reward-ad-options.interface.ts"],"names":[],"mappings":""}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PluginListenerHandle } from '@capacitor/core';
|
|
2
2
|
import type { ValidateAllEventsEnumAreImplemented } from '../private/validate-all-events-implemented.type';
|
|
3
|
-
import type { AdLoadInfo, AdMobError
|
|
3
|
+
import type { AdLoadInfo, AdMobError } from '../shared';
|
|
4
|
+
import type { RewardAdOptions } from './reward-ad-options.interface';
|
|
4
5
|
import type { RewardAdPluginEvents } from './reward-ad-plugin-events.enum';
|
|
5
6
|
import type { AdMobRewardItem } from './reward-item.interface';
|
|
6
7
|
export declare type RewardDefinitionsHasAllEvents = ValidateAllEventsEnumAreImplemented<RewardAdPluginEvents, RewardDefinitions>;
|
|
@@ -9,10 +10,10 @@ export interface RewardDefinitions {
|
|
|
9
10
|
* Prepare a reward video ad
|
|
10
11
|
*
|
|
11
12
|
* @group RewardVideo
|
|
12
|
-
* @param options
|
|
13
|
+
* @param options RewardAdOptions
|
|
13
14
|
* @since 1.1.2
|
|
14
15
|
*/
|
|
15
|
-
prepareRewardVideoAd(options:
|
|
16
|
+
prepareRewardVideoAd(options: RewardAdOptions): Promise<AdLoadInfo>;
|
|
16
17
|
/**
|
|
17
18
|
* Show a reward video ad
|
|
18
19
|
*
|
package/dist/plugin.js
CHANGED
|
@@ -17,19 +17,19 @@ class BannerExecutor: NSObject, GADBannerViewDelegate {
|
|
|
17
17
|
|
|
18
18
|
switch adSize {
|
|
19
19
|
case "BANNER":
|
|
20
|
-
bannerSize =
|
|
20
|
+
bannerSize = GADAdSizeBanner
|
|
21
21
|
break
|
|
22
22
|
case "LARGE_BANNER":
|
|
23
|
-
bannerSize =
|
|
23
|
+
bannerSize = GADAdSizeLargeBanner
|
|
24
24
|
break
|
|
25
25
|
case "FULL_BANNER":
|
|
26
|
-
bannerSize =
|
|
26
|
+
bannerSize = GADAdSizeFullBanner
|
|
27
27
|
break
|
|
28
28
|
case "LEADERBOARD":
|
|
29
|
-
bannerSize =
|
|
29
|
+
bannerSize = GADAdSizeLeaderboard
|
|
30
30
|
break
|
|
31
31
|
case "MEDIUM_RECTANGLE":
|
|
32
|
-
bannerSize =
|
|
32
|
+
bannerSize = GADAdSizeMediumRectangle
|
|
33
33
|
break
|
|
34
34
|
case "SMART_BANNER":
|
|
35
35
|
bannerSize = kGADAdSizeSmartBannerPortrait
|
|
@@ -136,6 +136,7 @@ class BannerExecutor: NSObject, GADBannerViewDelegate {
|
|
|
136
136
|
private func removeBannerViewToView() {
|
|
137
137
|
if let rootViewController = UIApplication.shared.keyWindow?.rootViewController {
|
|
138
138
|
if let subView = rootViewController.view.viewWithTag(2743243288699) {
|
|
139
|
+
bannerView.delegate = nil
|
|
139
140
|
NSLog("AdMob: find subView")
|
|
140
141
|
subView.removeFromSuperview()
|
|
141
142
|
}
|
|
@@ -43,11 +43,6 @@ class AdInterstitialExecutor: NSObject, GADFullScreenContentDelegate {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
public func adDidPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
|
|
47
|
-
NSLog("InterstitialFullScreenDelegate Ad did present full screen content.")
|
|
48
|
-
self.plugin?.notifyListeners(InterstitialAdPluginEvents.Showed.rawValue, data: [:])
|
|
49
|
-
}
|
|
50
|
-
|
|
51
46
|
public func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
|
|
52
47
|
NSLog("InterstitialFullScreenDelegate Ad failed to present full screen content with error \(error.localizedDescription).")
|
|
53
48
|
self.plugin?.notifyListeners(InterstitialAdPluginEvents.FailedToShow.rawValue, data: [
|
|
@@ -55,6 +50,11 @@ class AdInterstitialExecutor: NSObject, GADFullScreenContentDelegate {
|
|
|
55
50
|
"message": error.localizedDescription
|
|
56
51
|
])
|
|
57
52
|
}
|
|
53
|
+
|
|
54
|
+
public func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
|
|
55
|
+
NSLog("InterstitialFullScreenDelegate Ad did present full screen content.")
|
|
56
|
+
self.plugin?.notifyListeners(InterstitialAdPluginEvents.Showed.rawValue, data: [:])
|
|
57
|
+
}
|
|
58
58
|
|
|
59
59
|
public func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
|
|
60
60
|
NSLog("InterstitialFullScreenDelegate Ad did dismiss full screen content.")
|
|
@@ -22,6 +22,23 @@ class AdRewardExecutor: NSObject, GADFullScreenContentDelegate {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
self.rewardedAd = ad
|
|
25
|
+
|
|
26
|
+
if let providedOptions = call.getObject("ssv") {
|
|
27
|
+
let ssvOptions = GADServerSideVerificationOptions()
|
|
28
|
+
|
|
29
|
+
if let customData = providedOptions["customData"] as? String {
|
|
30
|
+
NSLog("Sending Custom Data: \(customData) to SSV callback")
|
|
31
|
+
ssvOptions.customRewardString = customData
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if let userId = providedOptions["userId"] as? String {
|
|
35
|
+
NSLog("Sending UserId: \(userId) to SSV callback")
|
|
36
|
+
ssvOptions.userIdentifier = userId
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
self.rewardedAd?.serverSideVerificationOptions = ssvOptions
|
|
40
|
+
}
|
|
41
|
+
|
|
25
42
|
self.rewardedAd?.fullScreenContentDelegate = self
|
|
26
43
|
self.plugin?.notifyListeners(RewardAdPluginEvents.Loaded.rawValue, data: [
|
|
27
44
|
"adUnitId": adUnitID
|
|
@@ -47,11 +64,6 @@ class AdRewardExecutor: NSObject, GADFullScreenContentDelegate {
|
|
|
47
64
|
}
|
|
48
65
|
}
|
|
49
66
|
|
|
50
|
-
public func adDidPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
|
|
51
|
-
NSLog("RewardFullScreenDelegate Ad did present full screen content.")
|
|
52
|
-
self.plugin?.notifyListeners(RewardAdPluginEvents.Showed.rawValue, data: [:])
|
|
53
|
-
}
|
|
54
|
-
|
|
55
67
|
public func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
|
|
56
68
|
NSLog("RewardFullScreenDelegate Ad failed to present full screen content with error \(error.localizedDescription).")
|
|
57
69
|
self.plugin?.notifyListeners(RewardAdPluginEvents.FailedToShow.rawValue, data: [
|
|
@@ -59,6 +71,11 @@ class AdRewardExecutor: NSObject, GADFullScreenContentDelegate {
|
|
|
59
71
|
"message": error.localizedDescription
|
|
60
72
|
])
|
|
61
73
|
}
|
|
74
|
+
|
|
75
|
+
public func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
|
|
76
|
+
NSLog("RewardFullScreenDelegate Ad did present full screen content.")
|
|
77
|
+
self.plugin?.notifyListeners(RewardAdPluginEvents.Showed.rawValue, data: [:])
|
|
78
|
+
}
|
|
62
79
|
|
|
63
80
|
public func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
|
|
64
81
|
NSLog("RewardFullScreenDelegate Ad did dismiss full screen content.")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor-community/admob",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "A native plugin for AdMob",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"clean": "rimraf ./dist",
|
|
38
38
|
"watch": "tsc --watch",
|
|
39
39
|
"prepublishOnly": "npm run build",
|
|
40
|
-
"release": "np"
|
|
40
|
+
"release": "np --no-tests"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@capacitor/android": "^3.0.0",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@ionic/prettier-config": "^1.0.1",
|
|
49
49
|
"@ionic/swiftlint-config": "^1.1.2",
|
|
50
50
|
"eslint": "^7.11.0",
|
|
51
|
-
"husky": "^4.
|
|
51
|
+
"husky": "^4.3.8",
|
|
52
52
|
"lint-staged": "^11.0.0",
|
|
53
53
|
"np": "^7.4.0",
|
|
54
54
|
"pre-commit": "^1.2.2",
|
|
@@ -69,7 +69,6 @@
|
|
|
69
69
|
},
|
|
70
70
|
"lint-staged": {
|
|
71
71
|
"*.{ts}": [
|
|
72
|
-
"npm run eslint -- --fix",
|
|
73
72
|
"npm run prettier -- --write",
|
|
74
73
|
"git add"
|
|
75
74
|
],
|
package/ios/Plugin/.DS_Store
DELETED
|
Binary file
|