Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows to send an user identifier to be used in Validating Server-Side Verification (SSV) Callbacks #657

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
});
```
Expand Down Expand Up @@ -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() ##

Expand Down
10 changes: 9 additions & 1 deletion src/android/AdMobPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/ios/CDVAdMobPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#define OPT_CONTENTURL @"contentURL"
#define OPT_CUSTOMTARGETING @"customTargeting"
#define OPT_EXCLUDE @"exclude"
#define OPT_USER_ID @"userId"

@interface CDVAdMobPlugin()<GADBannerViewDelegate, GADInterstitialDelegate, GADRewardBasedVideoAdDelegate>

Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
Expand Down