emi-indo-cordova-plugin-admob 1.5.9 → 1.6.1

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
@@ -1,4 +1,9 @@
1
1
 
2
+ ## New feature suggestion
3
+ > [!TIP]
4
+ > - Funding is needed to add a new feature of native ads that can be scrolled within html content elements.
5
+ > - I will not settle how much funding is needed to add this feature.
6
+
2
7
 
3
8
  # emi-indo-cordova-plugin-admob
4
9
  Cordova Plugin Admob Android and IOS
@@ -11,11 +16,15 @@
11
16
  ### User Messaging Platform (UMP IOS: 2.6.0) [Release Notes:](https://developers.google.com/ad-manager/mobile-ads-sdk/ios/privacy/download)
12
17
  ### IAB Europe Transparency & Consent Framework (CPM: 2.2.0)
13
18
 
14
-
15
19
  ## New example
16
20
  - https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/tree/main/example/www
17
21
 
18
22
 
23
+ ## Documentation Capacitor example
24
+ - [Documentation Capacitor example: ](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/discussions/29)
25
+
26
+
27
+
19
28
  ## Minimum Cordova Engines
20
29
  - cordova-android version = 12.0.0
21
30
  - cordova-ios version = 7.0.0
@@ -333,7 +342,7 @@ document.addEventListener('on.appOpenAd.loaded', () => {
333
342
  </pre>
334
343
  </details>
335
344
 
336
- - [FULL AppOpenAd basic:](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/blob/main/example/www/js/appOpenAd.js)
345
+ - [FULL AppOpenAd basic:](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/blob/main/Example/www/js/appOpenAd.js)
337
346
 
338
347
 
339
348
 
@@ -436,7 +445,7 @@ console.log("Collapsible Status: " + event.collapsible);
436
445
  </pre>
437
446
  </details>
438
447
 
439
- [FULL Banner basic:](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/blob/main/example/www/js/bannerAd.js)
448
+ [FULL Banner basic:](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/blob/main/Example/www/js/bannerAd.js)
440
449
 
441
450
 
442
451
  ## Interstitial ADS
@@ -499,7 +508,7 @@ document.addEventListener('on.interstitial.dismissed', () => {
499
508
  </details>
500
509
 
501
510
 
502
- [FULL Interstitial basic: ](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/blob/main/example/www/js/interstitialAd.js)
511
+ [FULL Interstitial basic: ](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/blob/main/Example/www/js/interstitialAd.js)
503
512
 
504
513
 
505
514
 
@@ -628,7 +637,7 @@ document.addEventListener('on.rewarded.dismissed', () => {
628
637
  </pre>
629
638
  </details>
630
639
 
631
- [FULL Rewarded basic: ](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/blob/main/example/www/js/rewardedAd.js)
640
+ [FULL Rewarded basic: ](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/blob/main/Example/www/js/rewardedAd.js)
632
641
 
633
642
 
634
643
 
@@ -0,0 +1,95 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const plist = require('plist');
4
+
5
+ const configPath = path.join(process.cwd(), 'capacitor.config.json');
6
+ const androidPlatformPath = path.join(process.cwd(), 'android');
7
+ const iosPlatformPath = path.join(process.cwd(), 'ios');
8
+ const pluginPath = path.join(process.cwd(), 'node_modules', 'emi-indo-cordova-plugin-admob', 'plugin.xml');
9
+ const infoPlistPath = path.join(process.cwd(), 'ios', 'App', 'App', 'Info.plist');
10
+
11
+
12
+ function fileExists(filePath) {
13
+ return fs.existsSync(filePath);
14
+ }
15
+
16
+
17
+ function getAdMobConfig() {
18
+ if (!fileExists(configPath)) {
19
+ throw new Error('capacitor.config.json not found. Ensure this is a Capacitor project.');
20
+ }
21
+
22
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
23
+ const admobConfig = config.plugins?.AdMob;
24
+
25
+ if (!admobConfig || !admobConfig.APP_ID_ANDROID || !admobConfig.APP_ID_IOS) {
26
+ throw new Error('AdMob configuration is missing in capacitor.config.json. Ensure APP_ID_ANDROID and APP_ID_IOS are defined.');
27
+ }
28
+
29
+ return {
30
+ APP_ID_ANDROID: admobConfig.APP_ID_ANDROID,
31
+ APP_ID_IOS: admobConfig.APP_ID_IOS,
32
+ };
33
+ }
34
+
35
+
36
+ function updatePluginXml(admobConfig) {
37
+ if (!fileExists(pluginPath)) {
38
+ console.error('plugin.xml not found. Ensure the plugin is installed.');
39
+ return;
40
+ }
41
+
42
+ let pluginContent = fs.readFileSync(pluginPath, 'utf8');
43
+
44
+ pluginContent = pluginContent
45
+ .replace(/<preference name="APP_ID_ANDROID" default=".*?" \/>/, `<preference name="APP_ID_ANDROID" default="${admobConfig.APP_ID_ANDROID}" />`)
46
+ .replace(/<preference name="APP_ID_IOS" default=".*?" \/>/, `<preference name="APP_ID_IOS" default="${admobConfig.APP_ID_IOS}" />`);
47
+
48
+ fs.writeFileSync(pluginPath, pluginContent, 'utf8');
49
+ console.log('AdMob IDs successfully updated in plugin.xml');
50
+ }
51
+
52
+
53
+ function updateInfoPlist(admobConfig) {
54
+ if (!fileExists(infoPlistPath)) {
55
+ console.error('Info.plist not found. Ensure you have built the iOS project.');
56
+ return;
57
+ }
58
+
59
+ const plistContent = fs.readFileSync(infoPlistPath, 'utf8');
60
+ const plistData = plist.parse(plistContent);
61
+
62
+
63
+ plistData.GADApplicationIdentifier = admobConfig.APP_ID_IOS;
64
+
65
+ const updatedPlistContent = plist.build(plistData);
66
+ fs.writeFileSync(infoPlistPath, updatedPlistContent, 'utf8');
67
+ console.log('AdMob IDs successfully updated in Info.plist');
68
+ }
69
+
70
+
71
+ try {
72
+
73
+ if (!fileExists(configPath)) {
74
+ throw new Error('capacitor.config.json not found. Skipping setup.');
75
+ }
76
+
77
+ if (!fileExists(androidPlatformPath) && !fileExists(iosPlatformPath)) {
78
+ throw new Error('Neither Android nor iOS platforms are found. Ensure platforms are added to your Capacitor project.');
79
+ }
80
+
81
+
82
+ const admobConfig = getAdMobConfig();
83
+
84
+
85
+ if (fileExists(androidPlatformPath)) {
86
+ updatePluginXml(admobConfig);
87
+ }
88
+
89
+
90
+ if (fileExists(iosPlatformPath)) {
91
+ updateInfoPlist(admobConfig);
92
+ }
93
+ } catch (error) {
94
+ console.error(error.message);
95
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "appId": "io.cordova.hellocordova",
3
+ "appName": "HelloCordova",
4
+ "webDir": "www",
5
+ "bundledWebRuntime": false,
6
+ "plugins": {
7
+ "AdMob": {
8
+ "APP_ID_ANDROID": "ca-app-pub-3940256099942544~3347511713",
9
+ "APP_ID_IOS": "ca-app-pub-3940256099942544~1458002511"
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,11 @@
1
+ <?xml version='1.0' encoding='utf-8'?>
2
+ <widget id="io.cordova.hellocordova" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
3
+ <name>HelloCordova</name>
4
+ <description>Sample Apache Cordova App</description>
5
+ <author email="dev@cordova.apache.org" href="https://cordova.apache.org">
6
+ Apache Cordova Team
7
+ </author>
8
+ <content src="index.html" />
9
+ <allow-intent href="http://*/*" />
10
+ <allow-intent href="https://*/*" />
11
+ </widget>
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "io.cordova.hellocordova",
3
+ "displayName": "HelloCordova",
4
+ "version": "1.0.0",
5
+ "description": "A sample Apache Cordova application that responds to the deviceready event.",
6
+ "main": "index.js",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1",
9
+ "update-admob": "node node_modules/emi-indo-cordova-plugin-admob/capacitor-hook-admob-ids.js"
10
+ },
11
+ "keywords": [
12
+ "ecosystem:cordova"
13
+ ],
14
+ "author": "Apache Cordova Team",
15
+ "license": "Apache-2.0",
16
+ "devDependencies": {
17
+ "emi-indo-cordova-plugin-admob": "^1.6.1"
18
+ },
19
+ "cordova": {
20
+ "plugins": {
21
+ "emi-indo-cordova-plugin-admob": {}
22
+ }
23
+ },
24
+ "dependencies": {
25
+ "@capacitor/android": "^6.2.0",
26
+ "@capacitor/ios": "^6.2.0",
27
+ "@capacitor/cli": "^6.2.0",
28
+ "@capacitor/core": "^6.2.0"
29
+ }
30
+ }
@@ -20,7 +20,7 @@ function loadBanner() {
20
20
  cordova.plugins.emiAdmobPlugin.loadBannerAd({
21
21
  adUnitId: Banner_ID, //Banner_ID,
22
22
  position: "bottom-center",
23
- size: "responsive_adaptive", // autoResize: true (only responsive_adaptive)
23
+ size: "banner", // autoResize: true (only responsive_adaptive)
24
24
  collapsible: "bottom", // position: top | bottom (disable, empty string)
25
25
  autoResize: true, // default false
26
26
  autoShow: true, // default false
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "emi-indo-cordova-plugin-admob",
3
- "version": "1.5.9",
4
- "description": "Cordova Plugin Admob Android IOS",
3
+ "version": "1.6.1",
4
+ "description": "Cordova Plugin Admob Android IOS Support Capacitor",
5
5
  "cordova": {
6
6
  "id": "emi-indo-cordova-plugin-admob",
7
7
  "platforms": [
@@ -20,7 +20,11 @@
20
20
  "admob-plus-cordova",
21
21
  "cordova-admob-pro",
22
22
  "cordova-admob-ios",
23
- "cordova-admob-android"
23
+ "cordova-admob-android",
24
+ "capacitor",
25
+ "capacitor-admob",
26
+ "capacitor-android",
27
+ "capacitor-ios"
24
28
  ],
25
29
  "author": "EMI INDO",
26
30
  "email": "cordova.c3addon@gmail.com",
package/plugin.xml CHANGED
@@ -1,6 +1,6 @@
1
1
  <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
2
2
  xmlns:android="http://schemas.android.com/apk/res/android"
3
- id="emi-indo-cordova-plugin-admob" version="1.5.9">
3
+ id="emi-indo-cordova-plugin-admob" version="1.6.1">
4
4
 
5
5
  <name>emiAdmobPlugin</name>
6
6
  <description>Cordova Plugin Admob Android IOS</description>
@@ -161,6 +161,7 @@ class emiAdmobPlugin : CordovaPlugin() {
161
161
  if(mActivity != null) {
162
162
  mActivity!!.runOnUiThread {
163
163
  try {
164
+ bannerOverlappingToZero()
164
165
  if (bannerViewLayout != null && bannerView != null) {
165
166
  val parentView = bannerViewLayout!!.parent as ViewGroup
166
167
  parentView.removeView(bannerViewLayout)
@@ -169,22 +170,17 @@ class emiAdmobPlugin : CordovaPlugin() {
169
170
  FrameLayout.LayoutParams.MATCH_PARENT,
170
171
  FrameLayout.LayoutParams.WRAP_CONTENT
171
172
  )
172
- val rootView =
173
- mActivity!!.window.decorView.findViewById<View>(View.generateViewId())
174
- if (rootView is ViewGroup) {
175
- rootView.addView(bannerViewLayout, params)
176
- } else {
177
- mActivity!!.addContentView(bannerViewLayout, params)
178
- }
179
- bannerView = AdView(mContext!!)
173
+ val decorView = mActivity!!.window.decorView as ViewGroup
174
+ decorView.addView(bannerViewLayout, params)
175
+ bannerView = AdView(mActivity!!)
180
176
  setBannerPosition(this.isPosition)
181
177
  setBannerSiz(this.isSize)
182
178
  bannerView!!.adUnitId = bannerAdUnitId!!
183
179
  bannerView!!.adListener = bannerAdListener
184
180
  bannerView!!.loadAd(buildAdRequest())
185
- adjustWebViewForBanner(this.isPosition)
186
181
  bannerViewLayout!!.addView(bannerView)
187
182
  bannerViewLayout!!.bringToFront()
183
+ bannerOverlappingToZero()
188
184
  }
189
185
  } catch (e: Exception) {
190
186
  PUBLIC_CALLBACKS!!.error("Error adjusting banner size: " + e.message)
@@ -195,9 +191,15 @@ class emiAdmobPlugin : CordovaPlugin() {
195
191
 
196
192
  when (orientation) {
197
193
  Configuration.ORIENTATION_PORTRAIT -> {
194
+ if (isOverlapping) {
195
+ bannerOverlapping()
196
+ }
198
197
  cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.orientation.portrait');")
199
198
  }
200
199
  Configuration.ORIENTATION_LANDSCAPE -> {
200
+ if (isOverlapping) {
201
+ bannerOverlapping()
202
+ }
201
203
  cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.orientation.landscape');")
202
204
  }
203
205
  Configuration.ORIENTATION_UNDEFINED -> {
@@ -1071,6 +1073,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1071
1073
  try {
1072
1074
  bannerView!!.visibility = View.VISIBLE
1073
1075
  bannerView!!.resume()
1076
+ // bannerOverlappingToZero()
1074
1077
 
1075
1078
  if (isOverlapping) {
1076
1079
  bannerOverlapping()
@@ -1362,6 +1365,8 @@ class emiAdmobPlugin : CordovaPlugin() {
1362
1365
  put("cause", adError.cause?.toString() ?: "null")
1363
1366
  }
1364
1367
 
1368
+ bannerOverlappingToZero()
1369
+
1365
1370
  if (bannerViewLayout != null && bannerView != null) {
1366
1371
  bannerViewLayout!!.removeView(bannerView)
1367
1372
  bannerView!!.destroy()
@@ -1439,7 +1444,6 @@ class emiAdmobPlugin : CordovaPlugin() {
1439
1444
 
1440
1445
 
1441
1446
 
1442
-
1443
1447
  private fun bannerOverlappingToZero() {
1444
1448
  if (bannerView != null && mActivity != null && cWebView != null) {
1445
1449
  mActivity!!.runOnUiThread {
@@ -1485,7 +1489,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1485
1489
  val screenHeightInPx = displayMetrics.heightPixels
1486
1490
 
1487
1491
  // Adjust the WebView height to account for the banner ad
1488
- val webViewHeight = screenHeightInPx - (adSize.height+overlappingHeight)
1492
+ val webViewHeight = screenHeightInPx - (adSize.height + overlappingHeight)
1489
1493
  val layoutParams = cWebView!!.view.layoutParams
1490
1494
  layoutParams.height = webViewHeight
1491
1495
  cWebView!!.view.layoutParams = layoutParams
@@ -1,3 +0,0 @@
1
- {
2
- "xml.downloadExternalResources.enabled": true
3
- }