diff --git a/src/android/AdMobConfig.java b/src/android/AdMobConfig.java index c8144c5c..b0124b50 100644 --- a/src/android/AdMobConfig.java +++ b/src/android/AdMobConfig.java @@ -13,6 +13,7 @@ public class AdMobConfig { /* options */ + private static final String OPT_USER_ID = "userId"; private static final String OPT_PUBLISHER_ID = "publisherId"; private static final String OPT_INTERSTITIAL_AD_ID = "interstitialAdId"; private static final String OPT_REWARD_VIDEO_ID = "rewardVideoId"; @@ -76,6 +77,7 @@ public class AdMobConfig { // Reward Video private static final String TEST_REWARDED_VIDEO_ID = "ca-app-pub-3940256099942544/5224354917"; private String rewardVideoId = ""; + private String userId = ""; public void setOptions(JSONObject options) { @@ -119,7 +121,10 @@ public void setOptions(JSONObject options) { if (options.has(OPT_AUTO_SHOW_INTERSTITIAL)) { this.autoShowInterstitial = options.optBoolean(OPT_AUTO_SHOW_INTERSTITIAL); } - + if (options.has(OPT_USER_ID)) { + this.userId = options.optString(OPT_USER_ID); + } + if (options.has(OPT_LOCATION)) { JSONArray location = options.optJSONArray(OPT_LOCATION); if (location != null) { @@ -175,6 +180,7 @@ public void setInterstitialOptions(JSONObject options) { public void setRewardVideoOptions(JSONObject options) { try { this.autoShowRewardVideo = (Boolean) options.remove(OPT_AUTO_SHOW); + this.userId = (String) options.remove(OPT_USER_ID); } catch (NullPointerException ignored) { } this.setOptions(options); @@ -243,6 +249,10 @@ public String getRewardedVideoAdUnitId() { return rewardVideoId; } + public String getUserId() { + return userId; + } + private static boolean isEmptyAdUnitId(String adId) { return adId.length() == 0 || adId.indexOf("xxxx") > 0; } diff --git a/src/android/rewardvideo/RewardVideoExecutor.java b/src/android/rewardvideo/RewardVideoExecutor.java index 60eeb2a2..3caffd93 100644 --- a/src/android/rewardvideo/RewardVideoExecutor.java +++ b/src/android/rewardvideo/RewardVideoExecutor.java @@ -46,7 +46,9 @@ public void run() { rewardedVideoAd = MobileAds.getRewardedVideoAdInstance(cordova.getActivity()); rewardedVideoAd.setRewardedVideoAdListener(new RewardVideoListener(RewardVideoExecutor.this)); + rewardedVideoAd.setUserId(plugin.config.getUserId()); Log.w("rewardedvideo", plugin.config.getRewardedVideoAdUnitId()); + Log.w("rewardedvideo:userId", plugin.config.getUserId()); synchronized (rewardedVideoLock) { if (!isRewardedVideoLoading) { diff --git a/src/ios/CDVAdMob.h b/src/ios/CDVAdMob.h index 140175d6..e396d0ce 100644 --- a/src/ios/CDVAdMob.h +++ b/src/ios/CDVAdMob.h @@ -59,6 +59,7 @@ @property (nonatomic, retain) NSString* gender; @property (nonatomic, retain) NSString* forChild; +@property(nonatomic, copy, nullable) NSString *userId; - (void) setOptions:(CDVInvokedUrlCommand *)command; diff --git a/src/ios/CDVAdMob.m b/src/ios/CDVAdMob.m index abb970ba..bd9fc125 100644 --- a/src/ios/CDVAdMob.m +++ b/src/ios/CDVAdMob.m @@ -33,7 +33,7 @@ @implementation CDVAdMob @synthesize publisherId, interstitialAdId, rewardVideoId, adSize; @synthesize bannerAtTop, bannerOverlap, offsetTopBar; -@synthesize isTesting, adExtras; +@synthesize isTesting, adExtras, userId; @synthesize bannerIsVisible, bannerIsInitialized; @synthesize bannerShow, autoShow, autoShowBanner, autoShowInterstitial, autoShowRewardVideo; @@ -47,7 +47,8 @@ @implementation CDVAdMob #define DEFAULT_INTERSTITIAL_ID @"ca-app-pub-3940256099942544/4411468910" #define DEFAULT_REWARD_VIDEO_ID @"ca-app-pub-3940256099942544/1712485313" -#define OPT_PUBLISHER_ID @"publisherId" +#define OPT_USER_ID @"userId" +#define OPT_BANNER_AD_ID @"bannerAdId" #define OPT_INTERSTITIAL_ADID @"interstitialAdId" #define OPT_REWARD_VIDEO_ID @"rewardVideoId" #define OPT_AD_SIZE @"adSize" @@ -98,6 +99,7 @@ - (void)pluginInitialize { gender = nil; forChild = nil; + userId = @""; isRewardedVideoLoading = false; rewardedVideoLock = nil; @@ -404,6 +406,8 @@ - (void) __cycleRewardVideo { self.rewardVideoView = [GADRewardBasedVideoAd sharedInstance]; self.rewardVideoView.delegate = self; + NSLog(@"userId for rewardedVideo is %@", self.userId); + [GADRewardBasedVideoAd sharedInstance].userIdentifier = self.userId; [self.rewardVideoView loadRequest:[GADRequest request] withAdUnitID:self.rewardVideoId]; } } @@ -463,7 +467,7 @@ - (void) __setOptions:(NSDictionary*) options { NSString* str = nil; - str = [options objectForKey:OPT_PUBLISHER_ID]; + str = [options objectForKey:OPT_BANNER_AD_ID]; if (str && [str length] > 0) { publisherId = str; } @@ -507,7 +511,12 @@ - (void) __setOptions:(NSDictionary*) options { if (dict) { adExtras = dict; } - + + str = [options objectForKey:OPT_USER_ID]; + if (str) { + userId = str; + } + str = [options objectForKey:OPT_AUTO_SHOW]; if (str) { autoShow = [str boolValue];