Skip to content
This repository has been archived by the owner on May 19, 2021. It is now read-only.

Set userId for rewardedVideo server side verification #425

Open
wants to merge 5 commits 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
12 changes: 11 additions & 1 deletion src/android/AdMobConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/android/rewardvideo/RewardVideoExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/ios/CDVAdMob.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@

@property (nonatomic, retain) NSString* gender;
@property (nonatomic, retain) NSString* forChild;
@property(nonatomic, copy, nullable) NSString *userId;

- (void) setOptions:(CDVInvokedUrlCommand *)command;

Expand Down
17 changes: 13 additions & 4 deletions src/ios/CDVAdMob.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"
Expand Down Expand Up @@ -98,6 +99,7 @@ - (void)pluginInitialize {

gender = nil;
forChild = nil;
userId = @"";

isRewardedVideoLoading = false;
rewardedVideoLock = nil;
Expand Down Expand Up @@ -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];
}
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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];
Expand Down