emi-indo-cordova-plugin-admob 1.7.9 → 1.9.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
@@ -1,12 +1,16 @@
1
1
 
2
2
 
3
3
  ### emi-indo-cordova-plugin-admob
4
- Cordova Plugin Admob Android and IOS
5
- ## Support
4
+ Cordova/Quasar/Capacitor Plugin Admob Android and IOS
5
+ ## Support Request Ad Builder
6
6
  - AdMob
7
7
  - AdManager
8
8
  - AdSense New [example ](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/blob/main/example/www/js/adSense.js)
9
9
 
10
+ ## Support framework
11
+ - Quasar: https://github.com/quasarframework/quasar/discussions/17706
12
+ - Capacitor: https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/discussions/29
13
+
10
14
  > [!NOTE]
11
15
  > - To maintain this plugin in the long run,
12
16
  > - for (regular maintenance),
@@ -44,6 +48,7 @@ https://github.com/EMI-INDO/emi-indo-cordova-plugin-fanalytics
44
48
 
45
49
 
46
50
  ## IOS Ad Support IOS 18 *
51
+ - Fix error build IOS: https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/discussions/42
47
52
  - Mobile Ads SDK (IOS: 11.12.0)
48
53
  - emi-indo-cordova-plugin-admob@1.6.3 or higher requires cocoapods 1.16.2 or higher
49
54
  > [!WARNING]
@@ -6,7 +6,8 @@
6
6
  "plugins": {
7
7
  "AdMob": {
8
8
  "APP_ID_ANDROID": "ca-app-pub-3940256099942544~3347511713",
9
- "APP_ID_IOS": "ca-app-pub-3940256099942544~1458002511"
9
+ "APP_ID_IOS": "ca-app-pub-3940256099942544~1458002511",
10
+ "USE_LITE_ADS": "lite"
10
11
  }
11
12
  }
12
13
  }
@@ -14,7 +14,7 @@
14
14
  "author": "Apache Cordova Team",
15
15
  "license": "Apache-2.0",
16
16
  "devDependencies": {
17
- "emi-indo-cordova-plugin-admob": "^1.6.4"
17
+ "emi-indo-cordova-plugin-admob": "^1.8.9"
18
18
  },
19
19
  "cordova": {
20
20
  "plugins": {
@@ -1,4 +1,4 @@
1
- // ccordova.plugins.emiAdmobPlugin.styleBannerAd({isOverlapping: true, overlappingHeight: 5, padding: 0, margins: 0 }); // ( only android)
1
+ // ccordova.plugins.emiAdmobPlugin.styleBannerAd({isOverlapping: true, overlappingHeight: 0, padding: 0, margins: 0 }); // ( only android)
2
2
  //cordova.plugins.emiAdmobPlugin.loadBannerAd({config});
3
3
  //cordova.plugins.emiAdmobPlugin.showBannerAd(); // default
4
4
  //cordova.plugins.emiAdmobPlugin.hideBannerAd(); // default
@@ -13,10 +13,10 @@ function loadBanner() {
13
13
  if (!isPlatformIOS){
14
14
 
15
15
  cordova.plugins.emiAdmobPlugin.styleBannerAd({
16
- isOverlapping: true,
17
- overlappingHeight: 5,
18
- padding: 0,
19
- margins: 0
16
+ isOverlapping: true,
17
+ overlappingHeight: 0, // default 0 (Automatic)
18
+ padding: 0, // default 0
19
+ margins: 0 // default 0 (Automatic)
20
20
  });
21
21
 
22
22
  }
@@ -24,7 +24,7 @@ function loadBanner() {
24
24
 
25
25
  cordova.plugins.emiAdmobPlugin.loadBannerAd({
26
26
  adUnitId: Banner_ID, //Banner_ID,
27
- position: "bottom-center",
27
+ position: "bottom-center", // "Recommended: bottom-center"
28
28
  size: "banner", // autoResize: true (only responsive_adaptive)
29
29
  collapsible: "bottom", // position: top | bottom (disable, empty string)
30
30
  autoResize: true, // default false
@@ -114,9 +114,33 @@ on.banner.hide
114
114
 
115
115
  // EVENT For example
116
116
 
117
+
118
+ // (Optional)
119
+ // This is only triggered when cordova.plugins.emiAdmobPlugin.styleBannerAd
120
+ document.addEventListener('on.style.banner.ad', (data) => {
121
+ console.log("on.style.banner.ad: " + JSON.stringify(data));
122
+ /*
123
+ const navBarHeight = data.navBarHeight;
124
+ const screenHeight = data.screenHeight;
125
+ const usableHeight = data.usableHeight;
126
+ const isOverlapping = data.isOverlapping;
127
+ const overlappingHeight = data.overlappingHeight;
128
+ const paddingInPx = data.paddingInPx;
129
+ const marginsInPx = data.marginsInPx;
130
+ */
131
+
132
+ // You can load banner ads here, or manipulate variables, even rearrange cordova.plugins.emiAdmobPlugin.styleBannerAd to your liking.
133
+
134
+
135
+ });
136
+
137
+
138
+
139
+
140
+
117
141
  document.addEventListener('on.banner.load', (arg) => {
118
142
  let bannerAdHeight=arg.height;
119
- console.log("on banner load");
143
+ console.log("on banner load", bannerAdHeight);
120
144
  });
121
145
 
122
146
 
@@ -83,7 +83,7 @@ document.addEventListener("deviceready", function () {
83
83
  }
84
84
 
85
85
 
86
- // deactivate Google's consent
86
+ // (Optional) deactivate Google's consent
87
87
  /*
88
88
  cordova.plugins.emiAdmobPlugin.metaData({
89
89
 
@@ -75,7 +75,7 @@ document.addEventListener('on.interstitial.loaded', () => {
75
75
 
76
76
  if (typeof cordova !== 'undefined') {
77
77
 
78
- cordova.plugins.EmiFirebaseAnalyticsPlugin.logEvent({ name: "interstitial_Ad", params: adEventData.on_interstitial_loaded });
78
+ cordova.plugins.EmiFirebaseAnalyticsPlugin.logEvent({ name: "on_interstitial_loaded", params: adEventData.on_interstitial_loaded });
79
79
 
80
80
  }
81
81
 
@@ -92,7 +92,7 @@ document.addEventListener('on.interstitial.dismissed', () => {
92
92
 
93
93
  if (typeof cordova !== 'undefined') {
94
94
 
95
- cordova.plugins.EmiFirebaseAnalyticsPlugin.logEvent({ name: "interstitial_Ad", params: adEventData.on_interstitial_dismissed });
95
+ cordova.plugins.EmiFirebaseAnalyticsPlugin.logEvent({ name: "on_interstitial_dismissed", params: adEventData.on_interstitial_dismissed });
96
96
 
97
97
  }
98
98
 
@@ -118,7 +118,7 @@ document.addEventListener('on.interstitial.failed.load', (error) => {
118
118
 
119
119
  if (typeof cordova !== 'undefined') {
120
120
 
121
- cordova.plugins.EmiFirebaseAnalyticsPlugin.logEvent({ name: "interstitial_Ad", params: adEventData.on_interstitial_failed_load });
121
+ cordova.plugins.EmiFirebaseAnalyticsPlugin.logEvent({ name: "on_interstitial_failed_load", params: adEventData.on_interstitial_failed_load });
122
122
 
123
123
  }
124
124
 
@@ -133,7 +133,7 @@ document.addEventListener('on.interstitial.failed.show', (error) => {
133
133
 
134
134
  if (typeof cordova !== 'undefined') {
135
135
 
136
- cordova.plugins.EmiFirebaseAnalyticsPlugin.logEvent({ name: "interstitial_Ad", params: adEventData.on_interstitial_failed_show });
136
+ cordova.plugins.EmiFirebaseAnalyticsPlugin.logEvent({ name: "on_interstitial_failed_show", params: adEventData.on_interstitial_failed_show });
137
137
 
138
138
  }
139
139
 
@@ -167,7 +167,7 @@ document.addEventListener('on.interstitial.revenue', (data) => {
167
167
 
168
168
  cordova.plugins.EmiFirebaseAnalyticsPlugin.setAdMobRevenuePaid({ data: adRevenuePaid });
169
169
 
170
- cordova.plugins.EmiFirebaseAnalyticsPlugin.logEvent({ name: "interstitial_Ad", params: adEventData.on_interstitial_revenue });
170
+ cordova.plugins.EmiFirebaseAnalyticsPlugin.logEvent({ name: "on_interstitial_revenue", params: adEventData.on_interstitial_revenue });
171
171
 
172
172
  }
173
173
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "emi-indo-cordova-plugin-admob",
3
- "version": "1.7.9",
4
- "description": "Cordova Plugin Admob Android IOS Support Capacitor",
3
+ "version": "1.9.9",
4
+ "description": "Cordova/Quasar/Capacitor Plugin Admob Android IOS",
5
5
  "cordova": {
6
6
  "id": "emi-indo-cordova-plugin-admob",
7
7
  "platforms": [
@@ -27,7 +27,9 @@
27
27
  "capacitor-ios",
28
28
  "adsense",
29
29
  "webview",
30
- "admanager"
30
+ "admanager",
31
+ "quasar-framework",
32
+ "quasar"
31
33
  ],
32
34
  "author": "EMI INDO",
33
35
  "email": "cordova.c3addon@gmail.com",
package/plugin.xml CHANGED
@@ -1,9 +1,9 @@
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.7.9">
3
+ id="emi-indo-cordova-plugin-admob" version="1.9.9">
4
4
 
5
5
  <name>emiAdmobPlugin</name>
6
- <description>Cordova Plugin Admob Android IOS</description>
6
+ <description>Cordova/Quasar/Capacitor Plugin Admob Android IOS</description>
7
7
  <author>EMI INDO</author>
8
8
  <license>ISC</license>
9
9
 
@@ -41,7 +41,6 @@
41
41
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
42
42
  </config-file>
43
43
 
44
-
45
44
  <config-file target="AndroidManifest.xml" parent="/manifest/application">
46
45
  <activity
47
46
  android:launchMode="singleTask"
@@ -93,7 +92,7 @@
93
92
 
94
93
  <config-file parent="/*" target="config.xml">
95
94
  <!--minimum deployment-target: 12.2 -->
96
- <preference name="deployment-target" value="12.2" />
95
+ <preference name="deployment-target" value="12.3" />
97
96
  <preference name="SwiftVersion" value="5.10" />
98
97
  </config-file>
99
98
 
@@ -5,6 +5,7 @@ import android.content.Context
5
5
  import android.content.Intent
6
6
  import android.content.SharedPreferences
7
7
  import android.content.res.Configuration
8
+ import android.graphics.Point
8
9
  import android.os.Build
9
10
  import android.os.Bundle
10
11
  import android.provider.Settings
@@ -91,6 +92,8 @@ class emiAdmobPlugin : CordovaPlugin() {
91
92
  private var isOverlapping: Boolean = false
92
93
  private var overlappingHeight: Int = 0
93
94
 
95
+ var adType = ""
96
+
94
97
  var isBannerLoad: Boolean = false
95
98
  var isBannerShow: Boolean = false
96
99
 
@@ -1197,18 +1200,59 @@ class emiAdmobPlugin : CordovaPlugin() {
1197
1200
  val options = args.getJSONObject(0)
1198
1201
  if (mActivity != null) {
1199
1202
  mActivity!!.runOnUiThread {
1200
- val isOverlapping = options.optBoolean("isOverlapping")
1201
- val overlappingHeight = options.optInt("overlappingHeight")
1202
- val paddingPx = options.optInt("padding")
1203
- val marginsPx = options.optInt("margins")
1203
+ val screenHeight: Int
1204
+ val usableHeight: Int
1205
+
1206
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
1207
+ val windowMetrics = cordova.activity.windowManager.currentWindowMetrics
1208
+ val insets = windowMetrics.windowInsets.getInsetsIgnoringVisibility(WindowInsets.Type.navigationBars())
1209
+ screenHeight = windowMetrics.bounds.height()
1210
+ usableHeight = screenHeight - insets.bottom
1211
+ } else {
1212
+ val display = cordova.activity.windowManager.defaultDisplay
1213
+ val size = Point()
1214
+ val realSize = Point()
1215
+ display.getSize(size)
1216
+ display.getRealSize(realSize)
1217
+
1218
+ usableHeight = size.y
1219
+ screenHeight = realSize.y
1220
+ }
1221
+
1222
+ val navBarHeight = maxOf(0, screenHeight - usableHeight)
1223
+
1224
+ val isOverlapping = options.optBoolean("isOverlapping", false)
1225
+ val overlappingHeight = options.optInt("overlappingHeight", navBarHeight)
1226
+ val paddingPx = options.optInt("padding", 0)
1227
+ val marginsPx = options.optInt("margins", navBarHeight)
1228
+
1229
+ val result = JSONObject()
1204
1230
  try {
1231
+ // Make sure to only set variables if they have the correct values
1205
1232
  this.isOverlapping = isOverlapping
1206
- this.overlappingHeight = overlappingHeight
1233
+ this.overlappingHeight = if (overlappingHeight > 0) overlappingHeight else navBarHeight
1207
1234
  this.paddingInPx = paddingPx
1208
- this.marginsInPx = marginsPx
1235
+ this.marginsInPx = if (marginsPx > 0) marginsPx else navBarHeight
1236
+
1237
+ // Add more useful data to the result
1238
+ result.put("navBarHeight", navBarHeight)
1239
+ result.put("screenHeight", screenHeight)
1240
+ result.put("usableHeight", usableHeight)
1241
+ result.put("isOverlapping", isOverlapping)
1242
+ result.put("overlappingHeight", this.overlappingHeight)
1243
+ result.put("paddingInPx", paddingPx)
1244
+ result.put("marginsInPx", this.marginsInPx)
1245
+
1246
+ cWebView?.let {
1247
+ it.loadUrl("javascript:cordova.fireDocumentEvent('on.style.banner.ad', ${result});")
1248
+ } ?: run {
1249
+ callbackContext.error("Error: cWebView is null.")
1250
+ }
1251
+
1209
1252
  } catch (e: Exception) {
1210
- callbackContext.error(e.toString())
1253
+ callbackContext.error("Error in styleBannerAd: ${e.message}")
1211
1254
  }
1255
+
1212
1256
  }
1213
1257
  }
1214
1258
  return true
@@ -1323,6 +1367,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1323
1367
 
1324
1368
 
1325
1369
  private fun loadBannerAd(adUnitId: String, position: String, size: String) {
1370
+ adType = size;
1326
1371
  try {
1327
1372
  if (bannerViewLayout == null) {
1328
1373
  bannerViewLayout = FrameLayout(mActivity!!)
@@ -1509,6 +1554,12 @@ class emiAdmobPlugin : CordovaPlugin() {
1509
1554
  cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.impression');")
1510
1555
  }
1511
1556
 
1557
+ private fun getAdHeightInDp(adSize: AdSize, context: Context): Int {
1558
+ val heightInPixels = adSize.getHeightInPixels(context)
1559
+ val density = context.resources.displayMetrics.density
1560
+ return (heightInPixels / density).toInt()
1561
+ }
1562
+
1512
1563
 
1513
1564
  override fun onAdLoaded() {
1514
1565
  // Log.d(TAG, "onAdLoaded: Ad finished loading successfully.");
@@ -1523,9 +1574,38 @@ class emiAdmobPlugin : CordovaPlugin() {
1523
1574
  bannerOverlapping()
1524
1575
  }
1525
1576
 
1526
- val bannerHeight= adSize.height;
1527
1577
 
1528
- val bannerLoadEventData = String.format(Locale.US, "{\"height\": %d}", bannerHeight)
1578
+
1579
+
1580
+
1581
+
1582
+ val context = cordova.activity.applicationContext
1583
+ //val adType="fluid";
1584
+ // Get the AdSize object based on the type
1585
+ var currentAdSize = when (adType) {
1586
+ "banner" -> AdSize.BANNER
1587
+ "large_banner" -> AdSize.LARGE_BANNER
1588
+ "medium_rectangle" -> AdSize.MEDIUM_RECTANGLE
1589
+ "full_banner" -> AdSize.FULL_BANNER
1590
+ "leaderboard" -> AdSize.LEADERBOARD
1591
+
1592
+ //"fluid" -> AdSize.FLUID
1593
+ //"in_line_adaptive" -> AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(context, adWidth)
1594
+
1595
+ else -> adSize // Default fallback to the adaptive ad size
1596
+ }
1597
+
1598
+ // Calculate the height in dp
1599
+ val bannerHeightDp = getAdHeightInDp(currentAdSize, context)
1600
+
1601
+ //bannerHeight=currentAdSize;
1602
+
1603
+
1604
+ val bannerLoadEventData = String.format(Locale.US, "{\"height\": %d}", bannerHeightDp)
1605
+
1606
+
1607
+
1608
+
1529
1609
 
1530
1610
  cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.load', $bannerLoadEventData);")
1531
1611
 
@@ -1604,24 +1684,21 @@ class emiAdmobPlugin : CordovaPlugin() {
1604
1684
 
1605
1685
 
1606
1686
 
1607
- // fix https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/issues/26
1608
1687
  private fun bannerOverlapping() {
1609
1688
  if (bannerView != null && mActivity != null && cWebView != null) {
1610
1689
  mActivity!!.runOnUiThread {
1611
1690
  try {
1612
- // val bannerHeightInPx = bannerView!!.height
1691
+
1613
1692
  val displayMetrics = DisplayMetrics()
1614
1693
  mActivity!!.windowManager.defaultDisplay.getMetrics(displayMetrics)
1615
1694
  val screenHeightInPx = displayMetrics.heightPixels
1616
1695
 
1617
- // Adjust the WebView height to account for the banner ad
1618
- val webViewHeight = screenHeightInPx - (adSize.height + overlappingHeight)
1619
- val layoutParams = cWebView!!.view.layoutParams
1620
- layoutParams.height = webViewHeight
1621
- cWebView!!.view.layoutParams = layoutParams
1696
+ val webViewHeight = screenHeightInPx - (adSize.height + overlappingHeight)
1697
+ val layoutParams = cWebView!!.view.layoutParams
1698
+ layoutParams.height = webViewHeight
1699
+ cWebView!!.view.layoutParams = layoutParams
1622
1700
 
1623
- // Log for debugging
1624
- Log.d("BannerAdjustment", "Adjusted WebView height: $webViewHeight")
1701
+ // Log.d("BannerAdjustment", "Adjusted WebView height: $webViewHeight")
1625
1702
  } catch (e: Exception) {
1626
1703
  Log.e("AdmobPlugin", "Error adjusting WebView for banner: ${e.message}")
1627
1704
  }
@@ -2006,7 +2083,7 @@ class emiAdmobPlugin : CordovaPlugin() {
2006
2083
  }
2007
2084
  return sb.toString().uppercase(Locale.getDefault())
2008
2085
  } catch (ex: NoSuchAlgorithmException) {
2009
- ex.printStackTrace();
2086
+ ex.printStackTrace();
2010
2087
  return null
2011
2088
  }
2012
2089
  }
@@ -2279,4 +2356,4 @@ class emiAdmobPlugin : CordovaPlugin() {
2279
2356
  private const val LAST_ACCESS_SUFFIX = "_last_access"
2280
2357
  private const val EXPIRATION_TIME = 360L * 24 * 60 * 60 * 1000
2281
2358
  }
2282
- }
2359
+ }