Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ AdMob.addListener(RewardAdPluginEvents.Rewarded, async () => {
* [`addListener(AppOpenAdPluginEvents.Opened, ...)`](#addlistenerappopenadplugineventsopened-)
* [`addListener(AppOpenAdPluginEvents.Closed, ...)`](#addlistenerappopenadplugineventsclosed-)
* [`addListener(AppOpenAdPluginEvents.FailedToShow, ...)`](#addlistenerappopenadplugineventsfailedtoshow-)
* [`addListener(AppOpenAdPluginEvents.AdImpression, ...)`](#addlistenerappopenadplugineventsadimpression-)
* [`showBanner(...)`](#showbanner)
* [`hideBanner()`](#hidebanner)
* [`resumeBanner()`](#resumebanner)
Expand All @@ -400,6 +401,7 @@ AdMob.addListener(RewardAdPluginEvents.Rewarded, async () => {
* [`addListener(InterstitialAdPluginEvents.Dismissed, ...)`](#addlistenerinterstitialadplugineventsdismissed-)
* [`addListener(InterstitialAdPluginEvents.FailedToShow, ...)`](#addlistenerinterstitialadplugineventsfailedtoshow-)
* [`addListener(InterstitialAdPluginEvents.Showed, ...)`](#addlistenerinterstitialadplugineventsshowed-)
* [`addListener(InterstitialAdPluginEvents.AdImpression, ...)`](#addlistenerinterstitialadplugineventsadimpression-)
* [`prepareRewardVideoAd(...)`](#preparerewardvideoad)
* [`showRewardVideoAd()`](#showrewardvideoad)
* [`addListener(RewardAdPluginEvents.FailedToLoad, ...)`](#addlistenerrewardadplugineventsfailedtoload-)
Expand All @@ -408,6 +410,7 @@ AdMob.addListener(RewardAdPluginEvents.Rewarded, async () => {
* [`addListener(RewardAdPluginEvents.Dismissed, ...)`](#addlistenerrewardadplugineventsdismissed-)
* [`addListener(RewardAdPluginEvents.FailedToShow, ...)`](#addlistenerrewardadplugineventsfailedtoshow-)
* [`addListener(RewardAdPluginEvents.Showed, ...)`](#addlistenerrewardadplugineventsshowed-)
* [`addListener(RewardAdPluginEvents.AdImpression, ...)`](#addlistenerrewardadplugineventsadimpression-)
* [`prepareRewardInterstitialAd(...)`](#preparerewardinterstitialad)
* [`showRewardInterstitialAd()`](#showrewardinterstitialad)
* [`addListener(RewardInterstitialAdPluginEvents.FailedToLoad, ...)`](#addlistenerrewardinterstitialadplugineventsfailedtoload-)
Expand All @@ -416,6 +419,7 @@ AdMob.addListener(RewardAdPluginEvents.Rewarded, async () => {
* [`addListener(RewardInterstitialAdPluginEvents.Dismissed, ...)`](#addlistenerrewardinterstitialadplugineventsdismissed-)
* [`addListener(RewardInterstitialAdPluginEvents.FailedToShow, ...)`](#addlistenerrewardinterstitialadplugineventsfailedtoshow-)
* [`addListener(RewardInterstitialAdPluginEvents.Showed, ...)`](#addlistenerrewardinterstitialadplugineventsshowed-)
* [`addListener(RewardInterstitialAdPluginEvents.AdImpression, ...)`](#addlistenerrewardinterstitialadplugineventsadimpression-)
* [Interfaces](#interfaces)
* [Type Aliases](#type-aliases)
* [Enums](#enums)
Expand Down Expand Up @@ -625,6 +629,22 @@ addListener(eventName: AppOpenAdPluginEvents.FailedToShow, listenerFunc: (error:
--------------------


### addListener(AppOpenAdPluginEvents.AdImpression, ...)

```typescript
addListener(eventName: AppOpenAdPluginEvents.AdImpression, listenerFunc: (data: AdMobRevenueData) => void) => Promise<PluginListenerHandle>
```

| Param | Type |
| ------------------ | ------------------------------------------------------------------------------------ |
| **`eventName`** | <code><a href="#appopenadpluginevents">AppOpenAdPluginEvents.AdImpression</a></code> |
| **`listenerFunc`** | <code>(data: <a href="#admobrevenuedata">AdMobRevenueData</a>) =&gt; void</code> |

**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>

--------------------


### showBanner(...)

```typescript
Expand Down Expand Up @@ -971,6 +991,22 @@ addListener(eventName: InterstitialAdPluginEvents.Showed, listenerFunc: () => vo
--------------------


### addListener(InterstitialAdPluginEvents.AdImpression, ...)

```typescript
addListener(eventName: InterstitialAdPluginEvents.AdImpression, listenerFunc: (data: AdMobRevenueData) => void) => Promise<PluginListenerHandle>
```

| Param | Type |
| ------------------ | ---------------------------------------------------------------------------------------------- |
| **`eventName`** | <code><a href="#interstitialadpluginevents">InterstitialAdPluginEvents.AdImpression</a></code> |
| **`listenerFunc`** | <code>(data: <a href="#admobrevenuedata">AdMobRevenueData</a>) =&gt; void</code> |

**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>

--------------------


### prepareRewardVideoAd(...)

```typescript
Expand Down Expand Up @@ -1101,6 +1137,22 @@ addListener(eventName: RewardAdPluginEvents.Showed, listenerFunc: () => void) =>
--------------------


### addListener(RewardAdPluginEvents.AdImpression, ...)

```typescript
addListener(eventName: RewardAdPluginEvents.AdImpression, listenerFunc: (data: AdMobRevenueData) => void) => Promise<PluginListenerHandle>
```

| Param | Type |
| ------------------ | ---------------------------------------------------------------------------------- |
| **`eventName`** | <code><a href="#rewardadpluginevents">RewardAdPluginEvents.AdImpression</a></code> |
| **`listenerFunc`** | <code>(data: <a href="#admobrevenuedata">AdMobRevenueData</a>) =&gt; void</code> |

**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>

--------------------


### prepareRewardInterstitialAd(...)

```typescript
Expand Down Expand Up @@ -1231,6 +1283,22 @@ addListener(eventName: RewardInterstitialAdPluginEvents.Showed, listenerFunc: ()
--------------------


### addListener(RewardInterstitialAdPluginEvents.AdImpression, ...)

```typescript
addListener(eventName: RewardInterstitialAdPluginEvents.AdImpression, listenerFunc: (data: AdMobRevenueData) => void) => Promise<PluginListenerHandle>
```

| Param | Type |
| ------------------ | ---------------------------------------------------------------------------------------------------------- |
| **`eventName`** | <code><a href="#rewardinterstitialadpluginevents">RewardInterstitialAdPluginEvents.AdImpression</a></code> |
| **`listenerFunc`** | <code>(data: <a href="#admobrevenuedata">AdMobRevenueData</a>) =&gt; void</code> |

**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>

--------------------


### Interfaces


Expand Down Expand Up @@ -1291,6 +1359,18 @@ https://developers.google.com/android/reference/com/google/android/gms/ads/AdErr
| **`message`** | <code>string</code> | Gets the message describing the error. |


#### AdMobRevenueData

| Prop | Type |
| ------------------ | ------------------------------------------------------------- |
| **`adUnitId`** | <code>string</code> |
| **`valueMicros`** | <code>number</code> |
| **`currencyCode`** | <code>string</code> |
| **`precision`** | <code><a href="#advalueprecision">AdValuePrecision</a></code> |
| **`networkName`** | <code>string</code> |
| **`impressionId`** | <code>string</code> |


#### BannerAdOptions

This interface extends <a href="#adoptions">AdOptions</a>
Expand Down Expand Up @@ -1436,6 +1516,17 @@ From T, pick a set of properties whose keys are in the union K
| **`Opened`** | <code>'appOpenAdOpened'</code> |
| **`Closed`** | <code>'appOpenAdClosed'</code> |
| **`FailedToShow`** | <code>'appOpenAdFailedToShow'</code> |
| **`AdImpression`** | <code>'appOpenAdImpression'</code> |


#### AdValuePrecision

| Members | Value |
| ----------------------- | -------------- |
| **`Unknown`** | <code>0</code> |
| **`Estimated`** | <code>1</code> |
| **`PublisherProvided`** | <code>2</code> |
| **`Precise`** | <code>3</code> |


#### BannerAdSize
Expand Down Expand Up @@ -1511,6 +1602,7 @@ From T, pick a set of properties whose keys are in the union K
| **`Showed`** | <code>'interstitialAdShowed'</code> | Emits when the Interstitial ad is visible to the user |
| **`FailedToShow`** | <code>'interstitialAdFailedToShow'</code> | Emits when the Interstitial ad is failed to show |
| **`Dismissed`** | <code>'interstitialAdDismissed'</code> | Emits when the Interstitial ad is not visible to the user anymore. |
| **`AdImpression`** | <code>'interstitialAdImpression'</code> | Emits when an impression-level ad revenue event is recorded |


#### RewardAdPluginEvents
Expand All @@ -1523,6 +1615,7 @@ From T, pick a set of properties whose keys are in the union K
| **`FailedToShow`** | <code>'onRewardedVideoAdFailedToShow'</code> | Emits when the AdReward video is failed to show |
| **`Dismissed`** | <code>'onRewardedVideoAdDismissed'</code> | Emits when the AdReward video is not visible to the user anymore. **Important**: This has nothing to do with the reward it self. This event will emits in this two cases: 1. The user starts the video ad but close it before the reward emit. 2. The user start the video and see it until end, then gets the reward and after that the ad is closed. |
| **`Rewarded`** | <code>'onRewardedVideoAdReward'</code> | Emits when user get rewarded from AdReward |
| **`AdImpression`** | <code>'onRewardedVideoAdImpression'</code> | Emits when an impression-level ad revenue event is recorded |


#### RewardInterstitialAdPluginEvents
Expand All @@ -1535,6 +1628,7 @@ From T, pick a set of properties whose keys are in the union K
| **`FailedToShow`** | <code>'onRewardedInterstitialAdFailedToShow'</code> | Emits when the AdReward video is failed to show |
| **`Dismissed`** | <code>'onRewardedInterstitialAdDismissed'</code> | Emits when the AdReward video is not visible to the user anymore. **Important**: This has nothing to do with the reward it self. This event will emits in this two cases: 1. The user starts the video ad but close it before the reward emit. 2. The user start the video and see it until end, then gets the reward and after that the ad is closed. |
| **`Rewarded`** | <code>'onRewardedInterstitialAdReward'</code> | Emits when user get rewarded from AdReward |
| **`AdImpression`** | <code>'onRewardedInterstitialAdImpression'</code> | Emits when an impression-level ad revenue event is recorded |

</docgen-api>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.Context
import com.google.android.gms.ads.AdError
import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.FullScreenContentCallback
import com.google.android.gms.ads.AdValue
import com.google.android.gms.ads.LoadAdError
import com.google.android.gms.ads.appopen.AppOpenAd

Expand All @@ -17,7 +18,7 @@ class AppOpenAdManager(val adUnitId: String) {
val isAdLoaded: Boolean
get() = appOpenAd != null

fun loadAd(context: Context, onLoaded: () -> Unit, onFailed: (LoadAdError?) -> Unit) {
fun loadAd(context: Context, onLoaded: () -> Unit, onFailed: (LoadAdError?) -> Unit, onPaidEvent: (AdValue, String, String) -> Unit) {
if (appOpenAd != null) {
onLoaded()
return
Expand All @@ -40,6 +41,11 @@ class AppOpenAdManager(val adUnitId: String) {
override fun onAdLoaded(ad: AppOpenAd) {
appOpenAd = ad
isLoadingAd = false
ad.setOnPaidEventListener { adValue ->
val networkName = ad.responseInfo?.mediationAdapterClassName ?: ""
val impressionId = ad.responseInfo?.responseId ?: ""
onPaidEvent(adValue, networkName, impressionId)
}
onLoaded()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.os.Looper
import com.getcapacitor.JSObject
import com.getcapacitor.PluginCall
import com.getcapacitor.community.admob.models.AdMobPluginError
import com.getcapacitor.community.admob.models.AdMobRevenueData

class AppOpenAdPlugin {

Expand Down Expand Up @@ -56,6 +57,10 @@ class AppOpenAdPlugin {
val errorCode = loadAdError?.code ?: -1
notifier.notify(AppOpenAdPluginEvents.FailedToLoad, AdMobPluginError(errorCode, errorMessage))
call.reject(errorMessage)
},
onPaidEvent = { adValue, networkName, impressionId ->
val revenueData = AdMobRevenueData(adValue, adUnitId, networkName, impressionId)
notifier.notify(AppOpenAdPluginEvents.AdImpression, revenueData)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ object AppOpenAdPluginEvents {
const val Opened = "appOpenAdOpened"
const val Closed = "appOpenAdClosed"
const val FailedToShow = "appOpenAdFailedToShow"
const val AdImpression = "appOpenAdImpression"
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.getcapacitor.community.admob.helpers.AdViewIdHelper;
import com.getcapacitor.community.admob.helpers.RequestHelper;
import com.getcapacitor.community.admob.models.AdMobPluginError;
import com.getcapacitor.community.admob.models.AdMobRevenueData;
import com.getcapacitor.community.admob.models.AdOptions;
import com.getcapacitor.community.admob.models.Executor;
import com.google.android.gms.ads.AdListener;
Expand Down Expand Up @@ -287,15 +288,22 @@ public void onAdClosed() {
notifyListeners(BannerAdPluginEvents.Closed.getWebEventName(), emptyObject);
super.onAdClosed();
}

@Override
public void onAdImpression() {
notifyListeners(BannerAdPluginEvents.AdImpression.getWebEventName(), emptyObject);
super.onAdImpression();
}
}
);

mAdView.setOnPaidEventListener((adValue) -> {
String networkName = "";
String impressionId = "";
if (mAdView.getResponseInfo() != null) {
networkName = mAdView.getResponseInfo().getMediationAdapterClassName();
if (networkName == null) networkName = "";
impressionId = mAdView.getResponseInfo().getResponseId();
if (impressionId == null) impressionId = "";
}
AdMobRevenueData revenueData = new AdMobRevenueData(adValue, mAdView.getAdUnitId(), networkName, impressionId);
notifyListeners(BannerAdPluginEvents.AdImpression.getWebEventName(), revenueData);
});

// Add AdViewLayout top of the WebView
mViewGroup.addView(mAdViewLayout);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.getcapacitor.JSObject
import com.getcapacitor.PluginCall
import com.getcapacitor.community.admob.helpers.FullscreenPluginCallback
import com.getcapacitor.community.admob.models.AdMobPluginError
import com.getcapacitor.community.admob.models.AdMobRevenueData
import com.google.android.gms.ads.LoadAdError
import com.google.android.gms.ads.interstitial.InterstitialAd
import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback
Expand All @@ -20,6 +21,14 @@ object InterstitialAdCallbackAndListeners {
ad.fullScreenContentCallback = FullscreenPluginCallback(InterstitialAdPluginPluginEvent, notifyListenersFunction)
ad.setImmersiveMode(immersiveMode ?: false)

ad.setOnPaidEventListener { adValue ->
val responseInfo = ad.responseInfo
val networkName = responseInfo?.mediationAdapterClassName ?: ""
val impressionId = responseInfo?.responseId ?: ""
val revenueData = AdMobRevenueData(adValue, ad.adUnitId, networkName, impressionId)
notifyListenersFunction.accept(InterstitialAdPluginPluginEvent.AdImpression, revenueData)
}

AdInterstitialExecutor.interstitialAd = ad

val adInfo = JSObject()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ object InterstitialAdPluginPluginEvent: LoadPluginEventNames {
override val Showed = "interstitialAdShowed"
override val FailedToShow = "interstitialAdFailedToShow"
override val Dismissed = "interstitialAdDismissed"
const val AdImpression = "interstitialAdImpression"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.getcapacitor.community.admob.models

import com.getcapacitor.JSObject
import com.google.android.gms.ads.AdValue

class AdMobRevenueData(adValue: AdValue, adUnitId: String, networkName: String, impressionId: String) : JSObject() {
init {
put("adUnitId", adUnitId)
put("valueMicros", adValue.valueMicros)
put("currencyCode", adValue.currencyCode)
put("precision", adValue.precisionType)
put("networkName", networkName)
put("impressionId", impressionId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ object RewardAdPluginEvents: LoadPluginEventNames {
override val Showed = "onRewardedVideoAdShowed"
override val FailedToShow = "onRewardedVideoAdFailedToShow"
override val Dismissed = "onRewardedVideoAdDismissed"
const val AdImpression = "onRewardedVideoAdImpression"
}
Loading