From 962a4c9e01b9f3296ae728bc857b71c5de5113c6 Mon Sep 17 00:00:00 2001 From: Alireza Asadi Date: Wed, 29 Apr 2020 18:01:56 +1000 Subject: [PATCH 1/4] Set userId for rewardedVideo --- src/android/AdMobConfig.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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; } From 58f2ac939948f23c796fb2649cf84f188665b51c Mon Sep 17 00:00:00 2001 From: Alireza Asadi Date: Wed, 29 Apr 2020 18:03:39 +1000 Subject: [PATCH 2/4] Set userId for rewardedVideo --- src/android/rewardvideo/RewardVideoExecutor.java | 2 ++ 1 file changed, 2 insertions(+) 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) { From efd3785dc3ffd201478d31f26fd60572a07a755e Mon Sep 17 00:00:00 2001 From: Alireza Asadi Date: Wed, 29 Apr 2020 18:41:20 +1000 Subject: [PATCH 3/4] Add userId for rewardedVideo server verification on ios --- src/ios/CDVAdMob.m | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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]; From 343f31256058d0bebee0ab6c91c18f5581d44cdf Mon Sep 17 00:00:00 2001 From: Alireza Asadi Date: Wed, 29 Apr 2020 18:42:11 +1000 Subject: [PATCH 4/4] add userId for rewardedVideo server verification --- src/ios/CDVAdMob.h | 1 + 1 file changed, 1 insertion(+) 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;