From 24ac2caf9ace8e5bf19daf20f3f81a3aa03cc501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Esqui=C3=A7ato?= Date: Wed, 19 Aug 2020 22:55:34 +0100 Subject: [PATCH] add user id config to be used in adreward validation --- docs/README.md | 2 ++ src/android/AdMobPlugin.java | 10 +++++++++- src/ios/CDVAdMobPlugin.m | 8 ++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 91fd384..45a4b17 100644 --- a/docs/README.md +++ b/docs/README.md @@ -241,6 +241,7 @@ AdMob.setOptions({ job: "sailor", age: "23", interest: ["boats","ports"], + userId: "YOUR_USER_IDENTIFIER" // necessary if you plan to use some kind of server validation to reward-videos https://developers.google.com/admob/android/rewarded-video-ssv }, }); ``` @@ -379,6 +380,7 @@ Extra key/value for param **options** - **error**, *function*, call back when fail. > Note: it will take some time to get Ad resource before it can be showed. You may buffer the Ad by calling **prepareRewardVideoAd**, and show it later. +> Note #2: if you plan to use some kind of server-side validation to reward your users, please use the setConfig method to provide identifier of the user seeing the video before prepare any video. Ref.: https://developers.google.com/admob/android/rewarded-video-ssv. ## AdMob.showRewardVideoAd() ## diff --git a/src/android/AdMobPlugin.java b/src/android/AdMobPlugin.java index 310be72..bdb216c 100644 --- a/src/android/AdMobPlugin.java +++ b/src/android/AdMobPlugin.java @@ -64,7 +64,8 @@ public class AdMobPlugin extends GenericAdPlugin { public static final String OPT_FORFAMILY = "forFamily"; public static final String OPT_CONTENTURL = "contentUrl"; public static final String OPT_CUSTOMTARGETING = "customTargeting"; - public static final String OPT_EXCLUDE = "exclude"; + public static final String OPT_EXCLUDE = "exclude"; + public static final String OPT_USER_ID = "userId"; protected String mGender = null; protected String mForChild = null; @@ -140,6 +141,9 @@ public void setOptions(JSONObject options) { } if(options.has(OPT_EXCLUDE)) { mExclude = options.optJSONArray(OPT_EXCLUDE); + } + if(options.has(OPT_USER_ID)) { + mUserId = options.optString(OPT_USER_ID); } } @@ -310,6 +314,10 @@ protected Object __prepareRewardVideoAd(String adId) { RewardedVideoAd ad = MobileAds.getRewardedVideoAdInstance(getActivity()); ad.setRewardedVideoAdListener(new RewardVideoListener()); + // if an useId is set, provide it to admob and it will be sent in server callback verification + if(mUserId != null) + ad.setUserId(mUserId); + synchronized (mLock) { if (!mIsRewardedVideoLoading) { mIsRewardedVideoLoading = true; diff --git a/src/ios/CDVAdMobPlugin.m b/src/ios/CDVAdMobPlugin.m index 35f50d6..344ba80 100644 --- a/src/ios/CDVAdMobPlugin.m +++ b/src/ios/CDVAdMobPlugin.m @@ -34,6 +34,7 @@ #define OPT_CONTENTURL @"contentURL" #define OPT_CUSTOMTARGETING @"customTargeting" #define OPT_EXCLUDE @"exclude" +#define OPT_USER_ID @"userId" @interface CDVAdMobPlugin() @@ -122,6 +123,10 @@ - (void) parseOptions:(NSDictionary *)options arr = [options objectForKey:OPT_EXCLUDE]; if(arr != nil) { self.mExclude = arr; + } + str = [options objectForKey:OPT_USER_ID]; + if(str != nil){ + self.mUserId = str; } } @@ -339,6 +344,9 @@ - (void) __destroyInterstitial:(NSObject*)interstitial { - (NSObject*) __prepareRewardVideoAd:(NSString*)adId { [GADRewardBasedVideoAd sharedInstance].delegate = self; + if (self.mUserId) { + [GADRewardBasedVideoAd sharedInstance].userIdentifier = self.mUserId; + } [[GADRewardBasedVideoAd sharedInstance] loadRequest:[GADRequest request] withAdUnitID:adId]; return nil;