cordova-plugin-admob-nextgen 1.0.9 → 1.2.9

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/README.md CHANGED
@@ -71,6 +71,16 @@ We prioritize the safety of your AdMob account and the stability of your app.
71
71
 
72
72
  ## Cordova/Capacitor/Framework7 AdMob Next-Gen: Installation & Usage Guide
73
73
 
74
+ ---
75
+ > Fastest test (APK Debug): **[⚡ With github action ](https://github.com/swaplab-engine/cordova-plugin-admob-nextgen/discussions/4)** (Optional)
76
+ ---
77
+
78
+ ### 🎉 View all plugin release notes
79
+ - 👉 [**Releases**](https://github.com/swaplab-engine/cordova-plugin-admob-nextgen/releases)
80
+
81
+ ---
82
+
83
+
74
84
  ## 1. Cordova or Framework7
75
85
 
76
86
  ### Option A: Via CLI
@@ -98,7 +108,7 @@ Add this to your `config.xml` to restore the plugin automatically.
98
108
  ## For Capacitor users
99
109
  **[⚡ Capacitor Integration: Automated Setup for AdMob Next Gen ](https://github.com/swaplab-engine/cordova-plugin-admob-nextgen/discussions/3)**.
100
110
 
101
- **[⚡ AdMob Next Gen - Starter Templates 🚀 ](https://github.com/swaplab-engine/cordova-plugin-admob-nextgen-template)**.
111
+ **[⚡ AdMob Next Gen - Starter Capacitor Templates 🚀 ](https://github.com/swaplab-engine/cordova-plugin-admob-nextgen-template)**.
102
112
 
103
113
  ---
104
114
 
@@ -224,6 +234,17 @@ Supports **Adaptive**, **Standard**, and **Collapsible** banners.
224
234
  isAutoShow: true
225
235
  });
226
236
 
237
+ ### New large banner adaptive size
238
+
239
+ > new banner size min plugin version: 1.2+
240
+
241
+ - LARGE_LANDSCAPE_ANCHORED_ADAPTIVE
242
+ - LARGE_PORTRAIT_ANCHORED_ADAPTIVE
243
+ - CURRENT_ORIENTATION_INLINE_ADAPTIVE
244
+ - LARGE_ANCHORED_ADAPTIVE
245
+ - PORTRAIT_INLINE_ADAPTIVE
246
+
247
+
227
248
  ### Banner Methods
228
249
 
229
250
  admobNextGen.showBanner();
@@ -316,9 +337,12 @@ Use the background engine to pool ads for 0ms latency.
316
337
  // 2. Show Instantly (from pool)
317
338
  admobNextGen.showPreloadedBanner();
318
339
 
319
- // 3. Stop Engine
340
+ // 3. Stop/Remove Engine
320
341
  admobNextGen.stopBannerPreload();
321
342
 
343
+ // 4. Hide Engine
344
+ admobNextGen.hideBannerPreload()
345
+
322
346
 
323
347
  ### Banner Events
324
348
 
@@ -361,6 +385,9 @@ Supports Auto-Resume logic.
361
385
 
362
386
  admobNextGen.showAppOpenAd();
363
387
 
388
+ ### With App Open Ad Preload
389
+ > App Open Ad Preload **[⚡ Modern ](https://github.com/swaplab-engine/cordova-plugin-admob-nextgen/tree/main/simple-example/www/js/AppOpenAdPreload.js)**
390
+
364
391
  ### App Open Events
365
392
 
366
393
  document.addEventListener('on.appopen.revenue', (data) => console.log(data));
@@ -104,7 +104,7 @@ function updateIosInfoPlist(appIdIos) {
104
104
  setStringKey('NSUserTrackingUsageDescription', 'This identifier will be used to deliver personalized ads to you.');
105
105
 
106
106
  setBoolKey('GADDelayAppMeasurementInit', true);
107
-
107
+ // https://developers.google.com/admob/ios/quick-start
108
108
  if (!content.includes('<key>SKAdNetworkItems</key>')) {
109
109
  const skAdNetworks = [
110
110
  'cstr6suwn9.skadnetwork', '4fzdc2evr5.skadnetwork', '2fnua5tdw4.skadnetwork', 'ydx93a7ass.skadnetwork',
@@ -158,7 +158,7 @@ function run() {
158
158
  admob = {
159
159
  APP_ID_ANDROID: appIdAndroid ? appIdAndroid[1] : "ca-app-pub-3940256099942544~3347511713",
160
160
  APP_ID_IOS: appIdIos ? appIdIos[1] : "ca-app-pub-3940256099942544~1458002511",
161
- NEXT_GEN_SDK_VERSION: sdk ? sdk[1] : "1.0.0",
161
+ NEXT_GEN_SDK_VERSION: sdk ? sdk[1] : "1.0.1",
162
162
  UMP_VERSION: ump ? ump[1] : "4.0.0"
163
163
  };
164
164
  }
@@ -167,7 +167,7 @@ function run() {
167
167
  injectExclusionRules();
168
168
  if (admob?.NEXT_GEN_SDK_VERSION || admob?.UMP_VERSION) {
169
169
  updateGradleDependencies(
170
- admob.NEXT_GEN_SDK_VERSION || "1.0.0",
170
+ admob.NEXT_GEN_SDK_VERSION || "1.0.1",
171
171
  admob.UMP_VERSION || "4.0.0"
172
172
  );
173
173
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordova-plugin-admob-nextgen",
3
- "version": "1.0.9",
3
+ "version": "1.2.9",
4
4
  "description": "Google Mobile Ads Next Gen SDK for Cordova. High performance and modular architecture. ",
5
5
  "cordova": {
6
6
  "id": "cordova-plugin-admob-nextgen",
package/plugin.xml CHANGED
@@ -1,6 +1,6 @@
1
1
  <?xml version='1.0' encoding='utf-8'?>
2
2
  <plugin id="cordova-plugin-admob-nextgen"
3
- version="1.0.9"
3
+ version="1.2.9"
4
4
  xmlns="http://apache.org/cordova/ns/plugins/1.0"
5
5
  xmlns:android="http://schemas.android.com/apk/res/android">
6
6
 
@@ -36,6 +36,7 @@
36
36
  <source-file src="src/android/AdMobNextGen.java" target-dir="app/src/main/java/com/emi/cordova/admob/nextgen" />
37
37
  <source-file src="src/android/BannerExecutor.java" target-dir="app/src/main/java/com/emi/cordova/admob/nextgen" />
38
38
  <source-file src="src/android/BannerPreloadExecutor.java" target-dir="app/src/main/java/com/emi/cordova/admob/nextgen" />
39
+ <source-file src="src/android/AppOpenAdPreloadExecutor.java" target-dir="app/src/main/java/com/emi/cordova/admob/nextgen" />
39
40
  <source-file src="src/android/NativeExecutor.java" target-dir="app/src/main/java/com/emi/cordova/admob/nextgen" />
40
41
  <source-file src="src/android/AppOpenAdExecutor.java" target-dir="app/src/main/java/com/emi/cordova/admob/nextgen" />
41
42
  <source-file src="src/android/InterstitialExecutor.java" target-dir="app/src/main/java/com/emi/cordova/admob/nextgen" />
@@ -46,7 +47,7 @@
46
47
 
47
48
  </platform>
48
49
 
49
- <preference name="NEXT_GEN_SDK_VERSION" default="1.0.0" />
50
+ <preference name="NEXT_GEN_SDK_VERSION" default="1.0.1" />
50
51
  <preference name="UMP_VERSION" default="4.0.0" />
51
52
  <preference name="APP_ID_ANDROID" default="ca-app-pub-3940256099942544~3347511713" />
52
53
 
@@ -39,6 +39,7 @@ public class AdMobNextGen extends CordovaPlugin {
39
39
  private NativeExecutor nativeExecutor;
40
40
 
41
41
  private BannerPreloadExecutor bannerPreloadExecutor;
42
+ private AppOpenAdPreloadExecutor appOpenAdPreloadExecutor;
42
43
 
43
44
  private boolean isNativeValidatorDisabled = true;
44
45
 
@@ -60,6 +61,7 @@ public class AdMobNextGen extends CordovaPlugin {
60
61
  nativeExecutor = new NativeExecutor(cordova, webView);
61
62
 
62
63
  bannerPreloadExecutor = new BannerPreloadExecutor(cordova, webView);
64
+ appOpenAdPreloadExecutor = new AppOpenAdPreloadExecutor(cordova, webView);
63
65
  }
64
66
 
65
67
  @Override
@@ -127,12 +129,30 @@ public class AdMobNextGen extends CordovaPlugin {
127
129
  return true;
128
130
  }
129
131
 
132
+ if ("hideBannerPreload".equals(action)) {
133
+ bannerPreloadExecutor.hideBanner(callbackContext);
134
+ return true;
135
+ }
136
+
130
137
  if ("removeBanner".equals(action)) {
131
138
  bannerExecutor.destroy();
132
139
  callbackContext.success();
133
140
  return true;
134
141
  }
135
142
 
143
+ if ("startAppOpenPreload".equals(action)) {
144
+ appOpenAdPreloadExecutor.startPreload(args, callbackContext);
145
+ return true;
146
+ }
147
+ if ("showPreloadedAppOpenAd".equals(action)) {
148
+ appOpenAdPreloadExecutor.showPolledAd(args, callbackContext);
149
+ return true;
150
+ }
151
+ if ("isAppOpenAdAvailable".equals(action)) {
152
+ appOpenAdPreloadExecutor.checkAdAvailable(args, callbackContext);
153
+ return true;
154
+ }
155
+
136
156
  if ("loadAppOpenAd".equals(action)) {
137
157
  if (appOpenAdExecutor != null) {
138
158
  appOpenAdExecutor.loadAd(args, callbackContext);
@@ -203,6 +223,11 @@ public class AdMobNextGen extends CordovaPlugin {
203
223
  if (appOpenAdExecutor != null && appOpenAdExecutor.shouldAutoShow()) {
204
224
  appOpenAdExecutor.showAdIfAvailable(cordova.getActivity());
205
225
  }
226
+ if (appOpenAdPreloadExecutor != null && appOpenAdPreloadExecutor.shouldAutoShow()) {
227
+ if (appOpenAdPreloadExecutor.hasAvailableAd()) {
228
+ appOpenAdPreloadExecutor.showPolledAd(null, null);
229
+ }
230
+ }
206
231
  }
207
232
 
208
233
  private void initializeSDK(JSONArray args, CallbackContext callbackContext) {
@@ -0,0 +1,285 @@
1
+ package com.emi.cordova.admob.nextgen;
2
+
3
+ import android.util.Log;
4
+
5
+ import androidx.annotation.NonNull;
6
+
7
+ import org.apache.cordova.CallbackContext;
8
+ import org.apache.cordova.CordovaInterface;
9
+ import org.apache.cordova.CordovaWebView;
10
+ import org.json.JSONArray;
11
+ import org.json.JSONException;
12
+ import org.json.JSONObject;
13
+
14
+ import java.util.Date;
15
+
16
+ import com.google.android.libraries.ads.mobile.sdk.appopen.AppOpenAd;
17
+ import com.google.android.libraries.ads.mobile.sdk.appopen.AppOpenAdEventCallback;
18
+ import com.google.android.libraries.ads.mobile.sdk.appopen.AppOpenAdPreloader;
19
+ import com.google.android.libraries.ads.mobile.sdk.common.AdRequest;
20
+ import com.google.android.libraries.ads.mobile.sdk.common.AdValue;
21
+ import com.google.android.libraries.ads.mobile.sdk.common.FullScreenContentError;
22
+ import com.google.android.libraries.ads.mobile.sdk.common.LoadAdError;
23
+ import com.google.android.libraries.ads.mobile.sdk.common.PreloadCallback;
24
+ import com.google.android.libraries.ads.mobile.sdk.common.PreloadConfiguration;
25
+ import com.google.android.libraries.ads.mobile.sdk.common.ResponseInfo;
26
+
27
+ public class AppOpenAdPreloadExecutor {
28
+
29
+ private static final String TAG = "AdMobAppOpenPreload";
30
+
31
+ private CordovaInterface cordova;
32
+ private CordovaWebView webView;
33
+
34
+ private String currentAdUnitId = null;
35
+
36
+ private boolean isAutoShow = false;
37
+ private long retryInterval = 5000;
38
+
39
+ private long lastLoadTime = 0;
40
+
41
+ private boolean isShowingAd = false;
42
+ private long lastAdDismissTime = 0;
43
+
44
+ public AppOpenAdPreloadExecutor(CordovaInterface cordova, CordovaWebView webView) {
45
+ this.cordova = cordova;
46
+ this.webView = webView;
47
+ }
48
+
49
+ public void startPreload(JSONArray args, CallbackContext callbackContext) {
50
+ try {
51
+ long currentTime = new Date().getTime();
52
+ String adUnitId = null;
53
+
54
+ if (args != null && args.length() > 0) {
55
+ JSONObject options = args.optJSONObject(0);
56
+ if (options != null) {
57
+ if (options.has("adUnitId")) {
58
+ adUnitId = options.getString("adUnitId");
59
+ }
60
+ if (options.has("isAutoShow")) {
61
+ this.isAutoShow = options.getBoolean("isAutoShow");
62
+ }
63
+ if (options.has("retryInterval")) {
64
+ this.retryInterval = options.getLong("retryInterval");
65
+ }
66
+ } else {
67
+ adUnitId = args.getString(0);
68
+ }
69
+ } else {
70
+
71
+ if (callbackContext != null) callbackContext.error("adUnitId is required");
72
+ return;
73
+ }
74
+
75
+ if (adUnitId != null) {
76
+ this.currentAdUnitId = adUnitId;
77
+ }
78
+
79
+ if ((currentTime - lastLoadTime) < retryInterval) {
80
+ if (callbackContext != null) {
81
+ callbackContext.success("Preload request debounced.");
82
+ }
83
+ return;
84
+ }
85
+
86
+ lastLoadTime = currentTime;
87
+
88
+ PreloadCallback preloadCallback = new PreloadCallback() {
89
+ @Override
90
+ public void onAdFailedToPreload(@NonNull String preloadId, @NonNull LoadAdError loadAdError) {
91
+ try {
92
+ JSONObject errData = new JSONObject();
93
+ errData.put("preloadId", preloadId);
94
+ errData.put("code", loadAdError.getCode());
95
+ errData.put("message", loadAdError.getMessage());
96
+ fireEvent("on.appopen.preload.failed", errData);
97
+ } catch (JSONException ignored) {}
98
+ }
99
+
100
+ @Override
101
+ public void onAdsExhausted(@NonNull String preloadId) {
102
+ try {
103
+ JSONObject data = new JSONObject();
104
+ data.put("preloadId", preloadId);
105
+ fireEvent("on.appopen.preload.exhausted", data);
106
+ } catch (JSONException ignored) {}
107
+ }
108
+
109
+ @Override
110
+ public void onAdPreloaded(@NonNull String preloadId, @NonNull ResponseInfo responseInfo) {
111
+ try {
112
+ JSONObject data = new JSONObject();
113
+ data.put("preloadId", preloadId);
114
+ fireEvent("on.appopen.preload.loaded", data);
115
+ } catch (JSONException ignored) {}
116
+ }
117
+ };
118
+
119
+ AdRequest adRequest = new AdRequest.Builder(this.currentAdUnitId).build();
120
+ PreloadConfiguration preloadConfiguration = new PreloadConfiguration(adRequest);
121
+
122
+ cordova.getActivity().runOnUiThread(() -> {
123
+ AppOpenAdPreloader.start(this.currentAdUnitId, preloadConfiguration, preloadCallback);
124
+ if (callbackContext != null) {
125
+ callbackContext.success("App open preload started");
126
+ }
127
+ });
128
+
129
+ } catch (Exception e) {
130
+ if (callbackContext != null) {
131
+ callbackContext.error("Exception: " + e.getMessage());
132
+ }
133
+ }
134
+ }
135
+
136
+ public void showPolledAd(JSONArray args, CallbackContext callbackContext) {
137
+ if (isShowingAd) {
138
+
139
+ if (callbackContext != null) callbackContext.error("Ad already showing.");
140
+ return;
141
+ }
142
+
143
+ if (new Date().getTime() - lastAdDismissTime < 1000) {
144
+
145
+ if (callbackContext != null) callbackContext.error("Ad in cooldown period.");
146
+ return;
147
+ }
148
+
149
+ try {
150
+ String adUnitId = this.currentAdUnitId;
151
+
152
+ if (args != null && args.length() > 0) {
153
+ JSONObject options = args.optJSONObject(0);
154
+ if (options != null && options.has("adUnitId")) {
155
+ adUnitId = options.getString("adUnitId");
156
+ } else {
157
+ String stringArg = args.optString(0, null);
158
+ if (stringArg != null && !stringArg.isEmpty() && !stringArg.equals("null")) {
159
+ adUnitId = stringArg;
160
+ }
161
+ }
162
+ }
163
+
164
+ if (adUnitId == null) {
165
+ if (callbackContext != null) callbackContext.error("No Ad Unit ID available.");
166
+ return;
167
+ }
168
+
169
+ final String finalAdUnitId = adUnitId;
170
+
171
+ this.isShowingAd = true;
172
+
173
+ cordova.getActivity().runOnUiThread(() -> {
174
+ AppOpenAd ad = AppOpenAdPreloader.pollAd(finalAdUnitId);
175
+
176
+ if (ad == null) {
177
+
178
+ this.isShowingAd = false;
179
+
180
+ try {
181
+ JSONObject errData = new JSONObject();
182
+ errData.put("message", "No preloaded app open ads available.");
183
+ fireEvent("on.appopen.preload.failed.show", errData);
184
+ } catch (JSONException ignored) {}
185
+
186
+ if (callbackContext != null) {
187
+ callbackContext.error("No preloaded app open ads available.");
188
+ }
189
+ return;
190
+ }
191
+
192
+ ad.setAdEventCallback(new AppOpenAdEventCallback() {
193
+ @Override
194
+ public void onAdPaid(@NonNull AdValue adValue) {
195
+ try {
196
+ JSONObject data = new JSONObject();
197
+ data.put("value", adValue.getValueMicros());
198
+ data.put("currency", adValue.getCurrencyCode());
199
+ data.put("precision", adValue.getPrecisionType());
200
+ fireEvent("on.appopen.preload.revenue", data);
201
+ } catch (JSONException ignored) {}
202
+ }
203
+
204
+ @Override
205
+ public void onAdShowedFullScreenContent() {
206
+ fireEvent("on.appopen.preload.shown", null);
207
+ }
208
+
209
+ @Override
210
+ public void onAdDismissedFullScreenContent() {
211
+ isShowingAd = false;
212
+ lastAdDismissTime = new Date().getTime();
213
+ fireEvent("on.appopen.preload.dismissed", null);
214
+ }
215
+
216
+ @Override
217
+ public void onAdFailedToShowFullScreenContent(@NonNull FullScreenContentError error) {
218
+ isShowingAd = false;
219
+ try {
220
+ JSONObject errData = new JSONObject();
221
+ errData.put("code", error.getCode());
222
+ errData.put("message", error.getMessage());
223
+ fireEvent("on.appopen.preload.failed.show", errData);
224
+ } catch (JSONException ignored) {}
225
+ }
226
+
227
+ @Override
228
+ public void onAdImpression() {
229
+ fireEvent("on.appopen.preload.impression", null);
230
+ }
231
+
232
+ @Override
233
+ public void onAdClicked() {
234
+ fireEvent("on.appopen.preload.clicked", null);
235
+ }
236
+ });
237
+
238
+ ad.show(cordova.getActivity());
239
+
240
+ if (callbackContext != null) {
241
+ callbackContext.success("Showing preloaded app open ad");
242
+ }
243
+ });
244
+
245
+ } catch (Exception e) {
246
+ this.isShowingAd = false;
247
+
248
+ if (callbackContext != null) callbackContext.error("Exception: " + e.getMessage());
249
+ }
250
+ }
251
+
252
+ public void checkAdAvailable(JSONArray args, CallbackContext callbackContext) {
253
+ boolean available = hasAvailableAd();
254
+ if (callbackContext != null) {
255
+ callbackContext.success(available ? 1 : 0);
256
+ }
257
+ }
258
+
259
+ public boolean shouldAutoShow() {
260
+ return this.isAutoShow;
261
+ }
262
+
263
+ public boolean hasAvailableAd() {
264
+ if (this.currentAdUnitId == null) return false;
265
+ return AppOpenAdPreloader.isAdAvailable(this.currentAdUnitId);
266
+ }
267
+
268
+ private void fireEvent(String eventName, JSONObject data) {
269
+ if (cordova == null) return;
270
+ cordova.getActivity().runOnUiThread(() -> {
271
+ StringBuilder js = new StringBuilder();
272
+ js.append("javascript:cordova.fireDocumentEvent('");
273
+ js.append(eventName);
274
+ js.append("'");
275
+ if (data != null) {
276
+ js.append(", ");
277
+ js.append(data.toString());
278
+ }
279
+ js.append(");");
280
+ if (webView != null && webView.getView() != null) {
281
+ webView.loadUrl(js.toString());
282
+ }
283
+ });
284
+ }
285
+ }