cordova-plugin-metkasu-admob 0.1.0 → 0.1.3

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/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
1
+ # 0.1.3
2
+
3
+ - Replaces the SDK preloaders (RewardedAdPreloader / InterstitialAdPreloader) with one explicit `RewardedAd.load` / `InterstitialAd.load` per `preload` call. Google documents that the preloader automatically loads a replacement after every pollAd, retries failed requests with exponential backoff and refreshes expired ads, and starts with a buffer (rewarded used 2). That produced ~3 requests per impression.
4
+ - At most one cached ad and one in-flight request per format. No request while an ad is cached, loading or on screen. A cached ad older than 50 minutes is discarded and never shown.
5
+ - Load failures send `state: ERROR` with the SDK error code and are NOT retried natively; the game controller schedules retries (30 s jittered exponential backoff, 15 min cooldown after 5 failures).
6
+ - After a show, nothing is reloaded until the game asks again (the controller asks when the format is next needed; interstitials only inside a level scene).
7
+ - Banner unchanged.
8
+ - API check against the official ads-mobile-sdk-1.6.0.aar (Google Maven): `RewardedAd.load(AdRequest, AdLoadCallback)` and `InterstitialAd.load(AdRequest, AdLoadCallback)` are public static, `AdLoadCallback.onAdLoaded/onAdFailedToLoad(LoadAdError)` and `LoadAdError.getCode()` exist. Still NOT compiled here (no Android SDK on this machine) and NOT device-tested: verify with the first build and Google TEST ads / a registered test device.
9
+ - Requires the game-side MetkasuAds controller that loads again only after a shown ad (Harfin İzinde, 2026-11-29); older controllers would not request a new ad after a show.
10
+
11
+ # 0.1.2
12
+
13
+ - Rewarded preload buffer reduced from 2 to 1 (interstitial was already 1). Each format has an independent SDK preloader keyed by its own ad unit, so at most one ready ad per format.
14
+ - Documented SDK behaviour: pollAd() "automatically preloads the next ad in the background". Whether that refill starts while the polled ad is on screen is NOT documented and NOT verified; destroy() is documented to remove cached ads, its effect on an already-polled ad is not documented.
15
+ - UNVERIFIED RISK: Google's guide recommends a buffer size of two and does not state that 1 is valid. Test on a device with Google test ads before publishing.
16
+ - NOT PUBLISHED. Project dependency stays on 0.1.1 until this version is published and validated.
17
+
18
+ # 0.1.1
19
+
20
+ - Fix Cordova installation: remove a preference accidentally requiring an ANDROID-MINSDKVERSION install variable. Android 13+ platform minimums and the existing Gradle SDK checks remain enforced.
21
+ - Declare AD_ID explicitly under the Android manifest root.
22
+ - Use the standard Cordova Android Java source target directory.
23
+ - Suspension, demo-only testing, reward deduplication and SDK versions unchanged.
24
+
1
25
  # 0.1.0
2
26
 
3
27
  - Fail-closed SUSPENDED policy and native TEST-only guard.
@@ -5,3 +29,5 @@
5
29
  - SDK-managed rewarded buffer of two; interstitial buffer of one; explicit banner display with reserved WebView margin.
6
30
  - Request/scene/placement-scoped reward receipts, once-only consumption, no reward on dismissal.
7
31
  - Pending publication and GDevelop cloud/Android-device validation.
32
+
33
+ 0.1.1 owner clarification: normal PRODUCTION configuration is supported. UI visibility is managed independently by the GDevelop facade; no date-based toggle. Valid app/unit IDs, release/test boundaries and UMP are still required.
package/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # cordova-plugin-metkasu-admob 0.1.0
1
+ > 0.1.1: Production is supported with explicit valid IDs and release configuration, as requested by the owner. UI visibility is separate. The older hard production lock described below is superseded. METKASU_ADMOB_APP_ID has a default and can be overridden at Cordova installation; it is not a secret.
2
+
3
+ # cordova-plugin-metkasu-admob 0.1.1
2
4
 
3
5
  Reusable Android Cordova advertising bridge. Default is **DISABLED**. No native onload initialization and no advertising timers. This version permits **TEST only**, on a debuggable application or a separate application ID ending `.adstest`. `PRODUCTION` is rejected even if JavaScript requests it. There is no date-based reactivation.
4
6
 
@@ -11,7 +13,7 @@ Reusable Android Cordova advertising bridge. Default is **DISABLED**. No native
11
13
 
12
14
  Do **not** install alongside `admob-plus-cordova` or another legacy Mobile Ads plugin. Installation and Gradle guards reject common old plugins and `play-services-ads` / `play-services-ads-lite` dependencies. They do not exclude PGS, Firebase or Billing libraries.
13
15
 
14
- After approved NPM publication, use `cordova plugin add cordova-plugin-metkasu-admob@0.1.0`. For local install validation before publication, use the package folder. GDevelop integration declares a pinned Cordova dependency in an events extension and includes the JS controller/facade in that extension. See the parent integration directory for generated projects and validation reports.
16
+ After approved NPM publication, use `cordova plugin add cordova-plugin-metkasu-admob@0.1.1`. For local install validation before publication, use the package folder. GDevelop integration declares a pinned Cordova dependency in an events extension and includes the JS controller/facade in that extension. See the parent integration directory for generated projects and validation reports.
15
17
 
16
18
  ## API
17
19
 
package/package.json CHANGED
@@ -1,11 +1,34 @@
1
1
  {
2
2
  "name": "cordova-plugin-metkasu-admob",
3
- "version": "0.1.0",
4
- "description": "Fail-closed Android Next-Gen AdMob bridge with UMP and a two-ad rewarded preload buffer",
3
+ "version": "0.1.3",
4
+ "description": "Fail-closed Android Next-Gen AdMob bridge with UMP and a one-ad-per-request loading (no SDK auto-refill or auto-retry)",
5
5
  "license": "UNLICENSED",
6
- "cordova": { "id": "cordova-plugin-metkasu-admob", "platforms": ["android"] },
7
- "engines": { "cordova": ">=11.0.0" },
8
- "keywords": ["cordova", "android", "gdevelop", "admob", "metkasu"],
9
- "files": ["plugin.xml", "www", "src", "hooks", "tests", "README.md", "CHANGELOG.md"],
10
- "scripts": { "test": "node --test tests/*.test.cjs" }
6
+ "cordova": {
7
+ "id": "cordova-plugin-metkasu-admob",
8
+ "platforms": [
9
+ "android"
10
+ ]
11
+ },
12
+ "engines": {
13
+ "cordova": ">=11.0.0"
14
+ },
15
+ "keywords": [
16
+ "cordova",
17
+ "android",
18
+ "gdevelop",
19
+ "admob",
20
+ "metkasu"
21
+ ],
22
+ "files": [
23
+ "plugin.xml",
24
+ "www",
25
+ "src",
26
+ "hooks",
27
+ "tests",
28
+ "README.md",
29
+ "CHANGELOG.md"
30
+ ],
31
+ "scripts": {
32
+ "test": "node --test tests/*.test.cjs"
33
+ }
11
34
  }
package/plugin.xml CHANGED
@@ -1,23 +1,23 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-metkasu-admob" version="0.1.0">
2
+ <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-metkasu-admob" version="0.1.3">
3
3
  <name>MetkasuAdMob</name>
4
4
  <description>Explicitly gated Next-Gen advertising. No onload initialization.</description>
5
5
  <license>UNLICENSED</license>
6
6
  <engines><engine name="cordova-android" version=">=13.0.0" /></engines>
7
7
  <js-module src="www/metkasu-admob.js" name="MetkasuAdMob"><clobbers target="MetkasuAdMob" /></js-module>
8
8
  <js-module src="www/controller.js" name="Controller"><clobbers target="MetkasuAdMobController" /></js-module>
9
+ <preference name="METKASU_ADMOB_APP_ID" default="ca-app-pub-7841059527940381~9227518637" />
9
10
  <platform name="android">
10
11
  <config-file target="res/xml/config.xml" parent="/*"><feature name="MetkasuAdMob"><param name="android-package" value="com.metkasu.admob.MetkasuAdMob" /></feature></config-file>
11
- <config-file target="AndroidManifest.xml" parent="/*"><uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /></config-file>
12
- <config-file target="AndroidManifest.xml" parent="/manifest/application"><meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-3940256099942544~3347511713" /></config-file>
13
- <preference name="android-minSdkVersion" value="24" />
12
+ <config-file target="AndroidManifest.xml" parent="/*"><uses-permission android:name="com.google.android.gms.permission.AD_ID" /><uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /></config-file>
13
+ <config-file target="AndroidManifest.xml" parent="/manifest/application"><meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="$METKASU_ADMOB_APP_ID" /></config-file>
14
14
  <framework src="com.google.android.libraries.ads.mobile.sdk:ads-mobile-sdk:1.6.0" />
15
15
  <framework src="com.google.android.ump:user-messaging-platform:4.0.0" />
16
16
  <framework src="src/android/metkasu-ads.gradle" custom="true" type="gradleReference" />
17
- <source-file src="src/android/MetkasuAdMob.java" target-dir="app/src/main/java/com/metkasu/admob" />
18
- <source-file src="src/android/AdsPolicy.java" target-dir="app/src/main/java/com/metkasu/admob" />
19
- <source-file src="src/android/AdSession.java" target-dir="app/src/main/java/com/metkasu/admob" />
20
- <source-file src="src/android/NextGenAds.java" target-dir="app/src/main/java/com/metkasu/admob" />
17
+ <source-file src="src/android/MetkasuAdMob.java" target-dir="src/com/metkasu/admob" />
18
+ <source-file src="src/android/AdsPolicy.java" target-dir="src/com/metkasu/admob" />
19
+ <source-file src="src/android/AdSession.java" target-dir="src/com/metkasu/admob" />
20
+ <source-file src="src/android/NextGenAds.java" target-dir="src/com/metkasu/admob" />
21
21
  <hook type="before_plugin_install" src="hooks/check-conflicts.js" />
22
22
  </platform>
23
23
  </plugin>
@@ -1,9 +1,9 @@
1
1
  package com.metkasu.admob;
2
2
 
3
- /** No date, remote flag or JavaScript request can enable production in this version. */
3
+ /** Production and TEST are explicit modes; UI visibility does not disable the SDK. */
4
4
  final class AdsPolicy {
5
- // Source-release gate. Remains false until explicit owner approval after suspension ends.
6
- static final boolean PRODUCTION_IMPLEMENTATION_APPROVED = false;
5
+ // Source-release gate. Owner requested normal advertising configuration with UI hidden separately.
6
+ static final boolean PRODUCTION_IMPLEMENTATION_APPROVED = true;
7
7
  static final String TEST_APP_ID = "ca-app-pub-3940256099942544~3347511713";
8
8
  static final String REWARDED = "ca-app-pub-3940256099942544/5224354917";
9
9
  static final String INTERSTITIAL = "ca-app-pub-3940256099942544/1033173712";
@@ -12,20 +12,18 @@ import com.google.android.libraries.ads.mobile.sdk.common.AdLoadCallback;
12
12
  import com.google.android.libraries.ads.mobile.sdk.common.AdRequest;
13
13
  import com.google.android.libraries.ads.mobile.sdk.common.FullScreenContentError;
14
14
  import com.google.android.libraries.ads.mobile.sdk.common.LoadAdError;
15
- import com.google.android.libraries.ads.mobile.sdk.common.PreloadCallback;
16
- import com.google.android.libraries.ads.mobile.sdk.common.PreloadConfiguration;
17
- import com.google.android.libraries.ads.mobile.sdk.common.ResponseInfo;
18
15
  import com.google.android.libraries.ads.mobile.sdk.interstitial.InterstitialAd;
19
16
  import com.google.android.libraries.ads.mobile.sdk.interstitial.InterstitialAdEventCallback;
20
- import com.google.android.libraries.ads.mobile.sdk.interstitial.InterstitialAdPreloader;
21
17
  import com.google.android.libraries.ads.mobile.sdk.rewarded.RewardedAd;
22
18
  import com.google.android.libraries.ads.mobile.sdk.rewarded.RewardedAdEventCallback;
23
- import com.google.android.libraries.ads.mobile.sdk.rewarded.RewardedAdPreloader;
24
- import java.util.HashSet;
25
- import java.util.Set;
19
+ import java.util.HashMap;
20
+ import java.util.Map;
26
21
  import org.json.JSONObject;
27
22
 
28
- /** SDK-managed buffer; no manual reload loop and no cached RewardedAd references. */
23
+ /**
24
+ * One ad request per explicit preload call. No SDK preloader: nothing is refilled, retried or refreshed automatically.
25
+ * The JavaScript controller decides when (and whether) the next request happens, with its own backoff.
26
+ */
29
27
  final class NextGenAds {
30
28
  interface Events { void send(JSONObject event); }
31
29
  private final Activity activity;
@@ -33,7 +31,11 @@ final class NextGenAds {
33
31
  private final View gameView;
34
32
  private final String mode;
35
33
  private final JSONObject units;
36
- private final Set<String> started = new HashSet<>();
34
+ // At most one cached ad and one in-flight request per format.
35
+ private static final long AD_TTL_MS = 50L * 60L * 1000L; // AdMob ads expire after 1 hour; never show one older than this.
36
+ private final Map<String, Object> cached = new HashMap<>();
37
+ private final Map<String, Long> cachedAt = new HashMap<>();
38
+ private final Map<String, Boolean> loading = new HashMap<>();
37
39
  private boolean enabled = true, showing;
38
40
  private long generation;
39
41
  private AdView banner;
@@ -47,34 +49,61 @@ final class NextGenAds {
47
49
  try {
48
50
  value.put("type", type).put("format", format).put("state", state);
49
51
  if (session != null) value.put("requestId", session.requestId).put("scene", session.scene).put("placement", session.placement);
50
- if ("rewarded".equals(format)) value.put("available", enabled && started.contains(format) ? RewardedAdPreloader.getNumAdsAvailable(unit(format)) : 0);
52
+ if ("rewarded".equals(format)) value.put("available", enabled && fresh(format) ? 1 : 0);
51
53
  } catch (Exception ignored) { }
52
54
  return value;
53
55
  }
54
56
  private void state(String format, String value) { events.send(event("state", format, enabled ? value : "DISABLED", null)); }
57
+ private boolean fresh(String format) {
58
+ Long at = cachedAt.get(format);
59
+ if (cached.get(format) == null || at == null) return false;
60
+ if (System.currentTimeMillis() - at > AD_TTL_MS) { cached.remove(format); cachedAt.remove(format); return false; }
61
+ return true;
62
+ }
55
63
  String status(String format) {
56
64
  if (!enabled) return "DISABLED";
57
65
  if (showing && !"banner".equals(format)) return "SHOWING";
58
66
  if ("banner".equals(format)) return bannerState;
59
- if (!started.contains(format)) return "UNAVAILABLE";
60
- boolean ready = "rewarded".equals(format) ? RewardedAdPreloader.isAdAvailable(unit(format)) : InterstitialAdPreloader.isAdAvailable(unit(format));
61
- return ready ? "READY" : "LOADING";
67
+ if (fresh(format)) return "READY";
68
+ return Boolean.TRUE.equals(loading.get(format)) ? "LOADING" : "UNAVAILABLE";
62
69
  }
63
70
  void preload(String format) {
64
71
  if (!enabled) return;
65
72
  if ("banner".equals(format)) { loadBanner(); return; }
66
- if (!started.add(format)) return;
73
+ if (!"rewarded".equals(format) && !"interstitial".equals(format)) throw new IllegalArgumentException("Unsupported format");
74
+ // Never a second request while one ad is cached (and not expired), in flight, or on screen.
75
+ if (showing || fresh(format) || Boolean.TRUE.equals(loading.get(format))) return;
67
76
  final long epoch = generation;
77
+ loading.put(format, true);
68
78
  state(format, "LOADING");
69
- PreloadCallback callback = new PreloadCallback() {
70
- @Override public void onAdPreloaded(String id, ResponseInfo response) { activity.runOnUiThread(() -> { if(enabled && epoch == generation) state(format, "READY"); }); }
71
- @Override public void onAdsExhausted(String id) { activity.runOnUiThread(() -> { if(enabled && epoch == generation) state(format, "UNAVAILABLE"); }); }
72
- @Override public void onAdFailedToPreload(String id, LoadAdError error) { activity.runOnUiThread(() -> { if(enabled && epoch == generation) state(format, "ERROR"); }); }
73
- };
74
- // Constructor bufferSize verified against the published 1.6.0 AAR.
75
- PreloadConfiguration configuration = new PreloadConfiguration(new AdRequest.Builder(unit(format)).build(), "rewarded".equals(format) ? 2 : 1);
76
- boolean accepted = "rewarded".equals(format) ? RewardedAdPreloader.start(unit(format), configuration, callback) : InterstitialAdPreloader.start(unit(format), configuration, callback);
77
- if (!accepted) { started.remove(format); state(format, "ERROR"); }
79
+ AdRequest request = new AdRequest.Builder(unit(format)).build();
80
+ if ("rewarded".equals(format)) {
81
+ RewardedAd.load(request, new AdLoadCallback<RewardedAd>() {
82
+ @Override public void onAdLoaded(RewardedAd ad) { activity.runOnUiThread(() -> loaded(format, ad, epoch)); }
83
+ @Override public void onAdFailedToLoad(LoadAdError error) { activity.runOnUiThread(() -> failed(format, error, epoch)); }
84
+ });
85
+ } else {
86
+ InterstitialAd.load(request, new AdLoadCallback<InterstitialAd>() {
87
+ @Override public void onAdLoaded(InterstitialAd ad) { activity.runOnUiThread(() -> loaded(format, ad, epoch)); }
88
+ @Override public void onAdFailedToLoad(LoadAdError error) { activity.runOnUiThread(() -> failed(format, error, epoch)); }
89
+ });
90
+ }
91
+ }
92
+ private void loaded(String format, Object ad, long epoch) {
93
+ if (!enabled || epoch != generation) return;
94
+ loading.remove(format); cached.put(format, ad); cachedAt.put(format, System.currentTimeMillis());
95
+ state(format, "READY");
96
+ }
97
+ private void failed(String format, LoadAdError error, long epoch) {
98
+ if (!enabled || epoch != generation) return;
99
+ loading.remove(format);
100
+ JSONObject value = event("state", format, "ERROR", null);
101
+ try { if (error != null) value.put("code", String.valueOf(error.getCode())); } catch (Exception ignored) { }
102
+ events.send(value); // No retry here: the JavaScript controller schedules it with backoff.
103
+ }
104
+ private Object take(String format) {
105
+ if (!fresh(format)) return null;
106
+ Object ad = cached.remove(format); cachedAt.remove(format); return ad;
78
107
  }
79
108
  JSONObject show(AdSession session) {
80
109
  String format = session.format;
@@ -89,8 +118,8 @@ final class NextGenAds {
89
118
  }
90
119
  final long epoch = generation;
91
120
  if ("rewarded".equals(format)) {
92
- // Poll ONLY on an explicit show request. SDK automatically refills the cache.
93
- final RewardedAd ad = RewardedAdPreloader.pollAd(unit(format));
121
+ // Taken ONLY on an explicit show request. Nothing is reloaded until the game asks again.
122
+ final RewardedAd ad = (RewardedAd) take(format);
94
123
  if (ad == null) return event("state", format, "UNAVAILABLE", session);
95
124
  showing = true;
96
125
  ad.setAdEventCallback(new RewardedAdEventCallback() {
@@ -104,7 +133,7 @@ final class NextGenAds {
104
133
  });
105
134
  } catch (RuntimeException error) { showing = false; session.failed = true; events.send(event("showfail", format, "ERROR", session)); }
106
135
  } else if ("interstitial".equals(format)) {
107
- final InterstitialAd ad = InterstitialAdPreloader.pollAd(unit(format));
136
+ final InterstitialAd ad = (InterstitialAd) take(format);
108
137
  if (ad == null) return event("state", format, "UNAVAILABLE", session);
109
138
  showing = true;
110
139
  ad.setAdEventCallback(new InterstitialAdEventCallback() {
@@ -136,9 +165,7 @@ final class NextGenAds {
136
165
  void pause() { hideBanner(); }
137
166
  void disable() {
138
167
  hideBanner();enabled = false; generation++;
139
- if(started.contains("rewarded")) RewardedAdPreloader.destroy(unit("rewarded"));
140
- if(started.contains("interstitial")) InterstitialAdPreloader.destroy(unit("interstitial"));
141
- started.clear(); if(banner != null) { banner.destroy(); banner = null; }
168
+ cached.clear(); cachedAt.clear(); loading.clear(); if(banner != null) { banner.destroy(); banner = null; }
142
169
  if(bannerContainer != null) { ((android.view.ViewGroup)bannerContainer.getParent()).removeView(bannerContainer); bannerContainer = null; }
143
170
  }
144
171
  }
@@ -9,3 +9,5 @@ test('five simulated SDK rewards each grant exactly once; no extra preload calls
9
9
  test('wrong placement and stale request cannot award',async()=>{
10
10
  let request;const c=createController(testConfig,async(action,payload)=>{if(action==='show')request=payload;return {state:'READY'};});await c.initialize();c.receive({type:'state',format:'rewarded',state:'READY'});await c.show('rewarded',{scene:'a',placement:'daily'});c.receive({type:'reward',...request,placement:'shop'});assert.equal(c.consumeReward('a'),false);c.receive({type:'showfail',...request});c.receive({type:'reward',...request});assert.equal(c.consumeReward('a'),false);
11
11
  });
12
+
13
+ test('normal production mode accepts real IDs independently of hidden UI configuration',async()=>{const raw={BUILD_CHANNEL:'release',ADMOB_SUSPENDED:false,ADS_ENABLED:true,ADS_MODE:'PRODUCTION',PRODUCTION_APPROVED:true,REWARDED_ENABLED:true,INTERSTITIAL_ENABLED:true,BANNER_ENABLED:false,REWARDED_BUTTONS_VISIBLE:true,REKLAM_BUTONLARI_GIZLI:true,ADMOB_APP_ID:'ca-app-pub-7841059527940381~9227518637',ADMOB_UNITS:{rewarded:'ca-app-pub-7841059527940381/2925085739',interstitial:'ca-app-pub-7841059527940381/7055902436',banner:''}};let requests=0;const c=createController(raw,async()=>{requests++;return {state:'READY'};});await c.preload('rewarded');assert.equal(c.config.mode,'PRODUCTION');assert.equal(c.enabled('rewarded'),true);assert.equal(requests,2);assert.equal(c.config.units.rewarded,raw.ADMOB_UNITS.rewarded);});
package/www/controller.js CHANGED
@@ -1,7 +1,7 @@
1
1
  (function(root,factory){const api=factory();if(typeof module==='object'&&module.exports)module.exports=api;else root.__MetkasuAdsCore=api;})(typeof gdjs!=='undefined'?gdjs:globalThis,function(){
2
2
  'use strict';
3
3
  // Changing this requires a reviewed source release and the owner's explicit approval.
4
- const PRODUCTION_IMPLEMENTATION_APPROVED=false;
4
+ const PRODUCTION_IMPLEMENTATION_APPROVED=true;
5
5
  const units=Object.freeze({rewarded:'ca-app-pub-3940256099942544/5224354917',interstitial:'ca-app-pub-3940256099942544/1033173712',banner:'ca-app-pub-3940256099942544/9214589741'});
6
6
  function normalize(c){
7
7
  const complete=!!c&&['REWARDED_ENABLED','INTERSTITIAL_ENABLED','BANNER_ENABLED','REWARDED_BUTTONS_VISIBLE'].every(k=>typeof c[k]==='boolean')&&c.ADMOB_SUSPENDED===false&&c.ADS_ENABLED===true;