diff --git a/src/admob/admob.android.ts b/src/admob/admob.android.ts index 23fa17fc..985eba7c 100644 --- a/src/admob/admob.android.ts +++ b/src/admob/admob.android.ts @@ -52,12 +52,12 @@ export function showBanner(arg: BannerOptions): Promise { firebase.admob.adView.loadAd(ad); const density = Utils.layout.getDisplayDensity(), - top = settings.margins.top * density, - bottom = settings.margins.bottom * density; + top = settings.margins.top * density, + bottom = settings.margins.bottom * density; const relativeLayoutParams = new android.widget.RelativeLayout.LayoutParams( - android.widget.RelativeLayout.LayoutParams.MATCH_PARENT, - android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT); + android.widget.RelativeLayout.LayoutParams.MATCH_PARENT, + android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT); if (bottom > -1) { relativeLayoutParams.bottomMargin = bottom; @@ -73,8 +73,8 @@ export function showBanner(arg: BannerOptions): Promise { adViewLayout.addView(firebase.admob.adView, relativeLayoutParams); const relativeLayoutParamsOuter = new android.widget.RelativeLayout.LayoutParams( - android.widget.RelativeLayout.LayoutParams.MATCH_PARENT, - android.widget.RelativeLayout.LayoutParams.MATCH_PARENT); + android.widget.RelativeLayout.LayoutParams.MATCH_PARENT, + android.widget.RelativeLayout.LayoutParams.MATCH_PARENT); // Wrapping it in a timeout makes sure that when this function is loaded from a Page.loaded event 'frame.Frame.topmost()' doesn't resolve to 'undefined'. // Also, in NativeScript 4+ it may be undefined anyway.. so using the appModule in that case. @@ -192,7 +192,16 @@ export function preloadRewardedVideoAd(arg: PreloadRewardedVideoAdOptions): Prom const settings = firebase.merge(arg, BANNER_DEFAULTS); const activity = Application.android.foregroundActivity || Application.android.startActivity; firebase.admob.rewardedAdVideoView = com.google.android.gms.ads.MobileAds.getRewardedVideoAdInstance(activity); - + + if (firebase.admob.rewardedAdVideoView) { + //https://developers.google.com/admob/android/ssv#ssv_callback_parameters + if (settings.userId) { + firebase.admob.rewardedAdVideoView.setUserId(settings.userId); + } + if (settings.customData) { + firebase.admob.rewardedAdVideoView.setCustomData(settings.customData); + } + } rewardedVideoCallbacks.onLoaded = resolve; rewardedVideoCallbacks.onFailedToLoad = reject; diff --git a/src/admob/admob.d.ts b/src/admob/admob.d.ts index 3a2887e4..f827c69d 100644 --- a/src/admob/admob.d.ts +++ b/src/admob/admob.d.ts @@ -131,6 +131,14 @@ export interface InterstitialOptions extends AdLifeCycleEvents { } export interface PreloadRewardedVideoAdOptions { + /** + * for user_id of https://developers.google.com/admob/ios/ssv#ssv_callback_parameters or https://developers.google.com/admob/android/ssv#ssv_callback_parameters + */ + userId?:string; + /** + * for custom_data of https://developers.google.com/admob/ios/ssv#ssv_callback_parameters or https://developers.google.com/admob/android/ssv#ssv_callback_parameters + */ + customData?:string; /** * When true you'll use googles testing iosAdPlacementId and androidAdPlacementId. */ diff --git a/src/admob/admob.ios.ts b/src/admob/admob.ios.ts index 8044e415..333038f4 100644 --- a/src/admob/admob.ios.ts +++ b/src/admob/admob.ios.ts @@ -35,9 +35,15 @@ export function showBanner(arg: BannerOptions): Promise { const originX = (view.frame.size.width - adWidth) / 2; const originY = settings.margins.top > -1 ? settings.margins.top : (settings.margins.bottom > -1 ? view.frame.size.height - adHeight - settings.margins.bottom : 0.0); - const origin = CGPointMake(originX, originY); - firebase.admob.adView = GADBannerView.alloc().initWithAdSizeOrigin(bannerType, origin); + //Fix for the smart banner size on NS7.0+, due to issue with initWithAdSizeOrigin response "Invalid ad width or height: (0, 0)" + if (settings.size === AD_SIZE.SMART_BANNER) { + const adFrameRec = CGRectMake(originX, originY, adWidth, Math.max(adHeight, 50)); // minimum height should be 50 for a ad banner + firebase.admob.adView = GADBannerView.alloc().initWithFrame(adFrameRec) + } else { + const origin = CGPointMake(originX, originY); + firebase.admob.adView = GADBannerView.alloc().initWithAdSizeOrigin(bannerType, origin); + } firebase.admob.adView.adUnitID = settings.iosBannerId; const adRequest = GADRequest.request(); @@ -218,10 +224,23 @@ export function preloadRewardedVideoAd(arg: PreloadRewardedVideoAdOptions): Prom firebase.admob.rewardedAdVideoView = GADRewardBasedVideoAd.sharedInstance(); firebase.admob.rewardedAdVideoView.delegate = _rewardBasedVideoAdDelegate; + const settings = firebase.merge(arg, BANNER_DEFAULTS); - const adRequest = GADRequest.request(); + + + if (firebase.admob.rewardedAdVideoView) { + //https://developers.google.com/admob/ios/ssv#ssv_callback_parameters + if (settings.userId) { + firebase.admob.rewardedAdVideoView.userIdentifier = settings.userId; + } + if (settings.customData) { + firebase.admob.rewardedAdVideoView.customRewardString = settings.customData; + } + } + const adRequest = GADRequest.request(); + if (settings.testing) { let testDevices: any = []; try { diff --git a/src/firebase.ios.ts b/src/firebase.ios.ts old mode 100755 new mode 100644