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

Updating original project #453

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
fd391d2
Proposal: Targeting support
koenpunt Aug 2, 2017
214652c
updating master to remove code issue
DeveloperBeau Apr 3, 2018
a17ac27
test fix
DeveloperBeau Apr 3, 2018
f3d35a3
remove changes
DeveloperBeau Apr 3, 2018
6c47c1f
Merge branch 'master' into pr/2
DeveloperBeau Apr 3, 2018
d90cd06
added in pr
DeveloperBeau Apr 3, 2018
5e8c75f
Merge pull request #3 from FootballFederationAustralia/pr/2
DeveloperBeau Apr 3, 2018
1b8b28f
update android to accept custom targeting
DeveloperBeau Apr 3, 2018
27365a9
Merge pull request #4 from FootballFederationAustralia/feature/targeting
DeveloperBeau Apr 3, 2018
4271744
remove repetitive code
DeveloperBeau Apr 3, 2018
d429967
Merge branch 'feature/targeting'
DeveloperBeau Apr 3, 2018
17483d7
implemented required props
DeveloperBeau Apr 9, 2018
0317e77
added additional props
DeveloperBeau Apr 9, 2018
30f3540
adding in debugging tools
DeveloperBeau Apr 9, 2018
b04295b
key update
DeveloperBeau Apr 9, 2018
b68529d
removing the nslogs
DeveloperBeau Apr 10, 2018
5bf95be
Fix build bug
aurozhkov Apr 10, 2018
72fc14b
Merge pull request #5 from FootballFederationAustralia/buildFix
davidepalazzo Apr 11, 2018
bbff1e1
support custom targeting attributes
geastwood Dec 3, 2018
f29f073
Update RNAdMobBanner.js
silva-fj Jun 26, 2019
6b5ffc1
Update RNPublisherBanner.js
silva-fj Jun 26, 2019
9dfd668
implementing requiresMainQueueSetup
silva-fj Jun 26, 2019
2644626
Merge pull request #1 from InterNations/update-publisher-banner
adamterlson Jun 27, 2019
9086d7f
Merge pull request #2 from InterNations/update-admob-banner
adamterlson Jun 27, 2019
99a0b6f
Merge pull request #3 from InterNations/updating-code
adamterlson Jun 27, 2019
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
9 changes: 9 additions & 0 deletions Example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ export default class Example extends Component {
validAdSizes={['banner', 'largeBanner', 'mediumRectangle']}
adUnitID="/6499/example/APIDemo/AdSizes"
ref={el => (this._adSizesExample = el)}
targeting={{
customTargeting: { group: "users" },
categoryExclusions: ['media'],
gender: 'male',
birthday: new Date(1989, 6, 9),
childDirectedTreatment: true,
contentURL: 'admob://',
publisherProvidedID: 'abc123',
}}
/>
<Button
title="Reload"
Expand Down
2 changes: 1 addition & 1 deletion RNAdMobBanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AdMobBanner extends Component {
loadBanner() {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this._bannerView),
UIManager.RNGADBannerView.Commands.loadBanner,
UIManager.getViewManagerConfig('RNGADBannerView').Commands.loadBanner,
null,
);
}
Expand Down
157 changes: 119 additions & 38 deletions RNPublisherBanner.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,72 @@
import React, { Component } from 'react';
import React, { Component } from 'react'
import {
NativeModules,
requireNativeComponent,
UIManager,
findNodeHandle,
ViewPropTypes,
} from 'react-native';
import { string, func, arrayOf } from 'prop-types';

import { createErrorFromErrorData } from './utils';
} from 'react-native'
import {
string,
func,
arrayOf,
bool,
object,
shape,
instanceOf,
oneOf,
number,
} from 'prop-types'

import { createErrorFromErrorData } from './utils'

class PublisherBanner extends Component {

constructor() {
super();
this.handleSizeChange = this.handleSizeChange.bind(this);
this.handleAppEvent = this.handleAppEvent.bind(this);
this.handleAdFailedToLoad = this.handleAdFailedToLoad.bind(this);
super()
this.handleSizeChange = this.handleSizeChange.bind(this)
this.handleAdmobDispatchAppEvent = this.handleAdmobDispatchAppEvent.bind(
this,
)
this.handleDidFailToReceiveAdWithError = this.handleDidFailToReceiveAdWithError.bind(
this,
)
this.state = {
style: {},
};
}
}

componentDidMount() {
this.loadBanner();
this.loadBanner()
}

loadBanner() {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this._bannerView),
UIManager.RNDFPBannerView.Commands.loadBanner,
UIManager.getViewManagerConfig('RNDFPBannerView').Commands.loadBanner,
null,
);
)
}

handleSizeChange(event) {
const { height, width } = event.nativeEvent;
this.setState({ style: { width, height } });
const { height, width } = event.nativeEvent
this.setState({ style: { width, height } })
if (this.props.onSizeChange) {
this.props.onSizeChange({ width, height });
this.props.onSizeChange({ width, height })
}
}

handleAppEvent(event) {
if (this.props.onAppEvent) {
const { name, info } = event.nativeEvent;
this.props.onAppEvent({ name, info });
handleAdmobDispatchAppEvent(event) {
if (this.props.onAdmobDispatchAppEvent) {
const { name, info } = event.nativeEvent
this.props.onAdmobDispatchAppEvent({ name, info })
}
}

handleAdFailedToLoad(event) {
if (this.props.onAdFailedToLoad) {
this.props.onAdFailedToLoad(createErrorFromErrorData(event.nativeEvent.error));
handleDidFailToReceiveAdWithError(event) {
if (this.props.onDidFailToReceiveAdWithError) {
this.props.onDidFailToReceiveAdWithError(
createErrorFromErrorData(event.nativeEvent.error),
)
}
}

Expand All @@ -60,25 +76,25 @@ class PublisherBanner extends Component {
{...this.props}
style={[this.props.style, this.state.style]}
onSizeChange={this.handleSizeChange}
onAdFailedToLoad={this.handleAdFailedToLoad}
onAppEvent={this.handleAppEvent}
onDidFailToReceiveAdWithError={this.handleDidFailToReceiveAdWithError}
onAdmobDispatchAppEvent={this.handleAdmobDispatchAppEvent}
ref={el => (this._bannerView = el)}
/>
);
)
}
}

Object.defineProperty(PublisherBanner, 'simulatorId', {
get() {
return UIManager.RNDFPBannerView.Constants.simulatorId;
return NativeModules.RNDFPBannerViewManager.simulatorId
},
});
})

PublisherBanner.propTypes = {
...ViewPropTypes,

/**
* DFP iOS library banner size constants
* AdMob iOS library banner size constants
* (https://developers.google.com/admob/ios/banner)
* banner (320x50, Standard Banner for Phones and Tablets)
* largeBanner (320x100, Large Banner for Phones and Tablets)
Expand All @@ -98,7 +114,7 @@ PublisherBanner.propTypes = {
validAdSizes: arrayOf(string),

/**
* DFP ad unit ID
* AdMob ad unit ID
*/
adUnitID: string,

Expand All @@ -107,19 +123,84 @@ PublisherBanner.propTypes = {
*/
testDevices: arrayOf(string),

onSizeChange: func,

/**
* DFP library events
* AdMob iOS library events
*/
onSizeChange: func,
onAdViewDidReceiveAd: func,
onDidFailToReceiveAdWithError: func,
onAdViewWillPresentScreen: func,
onAdViewWillDismissScreen: func,
onAdViewDidDismissScreen: func,
onAdViewWillLeaveApplication: func,
onAdmobDispatchAppEvent: func,
onAdLeftApplication: func,
onAdLoaded: func,
onAdFailedToLoad: func,
onAdOpened: func,
onAdClosed: func,
onAdLeftApplication: func,
onAppEvent: func,
};

const RNDFPBannerView = requireNativeComponent('RNDFPBannerView', PublisherBanner);
targeting: shape({
/**
* Arbitrary object of custom targeting information.
*/
customTargeting: object,

/**
* Array of exclusion labels.
*/
categoryExclusions: arrayOf(string),

/**
* Array of keyword strings.
*/
keywords: arrayOf(string),

/**
* When using backfill or an SDK mediation creative, gender can be supplied
* in the ad request for targeting purposes.
*/
gender: oneOf(['unknown', 'male', 'female']),

/**
* When using backfill or an SDK mediation creative, birthday can be supplied
* in the ad request for targeting purposes.
*/
birthday: instanceOf(Date),

/**
* Indicate that you want Google to treat your content as child-directed.
*/
childDirectedTreatment: bool,

/**
* Applications that monetize content matching a webpage's content may pass
* a content URL for keyword targeting.
*/
contentURL: string,

/**
* You can set a publisher provided identifier (PPID) for use in frequency
* capping, audience segmentation and targeting, sequential ad rotation, and
* other audience-based ad delivery controls across devices.
*/
publisherProvidedID: string,

/**
* The user’s current location may be used to deliver more relevant ads.
*/
location: shape({
latitude: number,
longitude: number,
accuracy: number,
}),
}),
}

const RNDFPBannerView = requireNativeComponent(
'RNDFPBannerView',
PublisherBanner,
)

export default PublisherBanner;
export default PublisherBanner
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class RNAdMobRewardedVideoAdModule extends ReactContextBaseJavaModule imp
public static final String EVENT_AD_LEFT_APPLICATION = "rewardedVideoAdLeftApplication";
public static final String EVENT_REWARDED = "rewardedVideoAdRewarded";
public static final String EVENT_VIDEO_STARTED = "rewardedVideoAdVideoStarted";
public static final String EVENT_VIDEO_COMPLETED = "rewardedVideoAdVideoCompleted";

RewardedVideoAd mRewardedVideoAd;
String adUnitID;
Expand Down Expand Up @@ -80,6 +81,11 @@ public void onRewardedVideoAdClosed() {
sendEvent(EVENT_AD_CLOSED, null);
}

@Override
public void onRewardedVideoCompleted() {
sendEvent(EVENT_VIDEO_COMPLETED, null);
}

@Override
public void onRewardedVideoAdLeftApplication() {
sendEvent(EVENT_AD_LEFT_APPLICATION, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableNativeArray;
Expand All @@ -22,6 +23,9 @@
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.doubleclick.PublisherAdView;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -34,6 +38,7 @@ class ReactPublisherAdView extends ReactViewGroup implements AppEventListener {
AdSize[] validAdSizes;
String adUnitID;
AdSize adSize;
JSONObject customTargeting;

public ReactPublisherAdView(final Context context) {
super(context);
Expand Down Expand Up @@ -151,6 +156,23 @@ public void loadBanner() {
adRequestBuilder.addTestDevice(testDevices[i]);
}
}
if (this.customTargeting != null) {
try {
String corigin = (String) this.customTargeting.get("corigin");
String cresidency = (String) this.customTargeting.get("cresidency");
String gender = (String) this.customTargeting.get("gender");
String lc = (String) this.customTargeting.get("lc");
String isExpat = (Boolean) this.customTargeting.get("is_expat") ? "true" : "false";

adRequestBuilder.addCustomTargeting("corigin", corigin);
adRequestBuilder.addCustomTargeting("cresidency", cresidency);
adRequestBuilder.addCustomTargeting("gender", gender);
adRequestBuilder.addCustomTargeting("lc", lc);
adRequestBuilder.addCustomTargeting("isExpat", isExpat);
} catch (JSONException e) {
e.printStackTrace();
}
}
PublisherAdRequest adRequest = adRequestBuilder.build();
this.adView.loadAd(adRequest);
}
Expand All @@ -177,6 +199,10 @@ public void setValidAdSizes(AdSize[] adSizes) {
this.validAdSizes = adSizes;
}

public void setCustomTargeting(JSONObject customTargeting) {
this.customTargeting = customTargeting;
}

@Override
public void onAppEvent(String name, String info) {
WritableMap event = Arguments.createMap();
Expand All @@ -194,6 +220,7 @@ public class RNPublisherBannerViewManager extends ViewGroupManager<ReactPublishe
public static final String PROP_VALID_AD_SIZES = "validAdSizes";
public static final String PROP_AD_UNIT_ID = "adUnitID";
public static final String PROP_TEST_DEVICES = "testDevices";
public static final String PROP_TARGETING = "targeting";

public static final String EVENT_SIZE_CHANGE = "onSizeChange";
public static final String EVENT_AD_LOADED = "onAdLoaded";
Expand Down Expand Up @@ -272,6 +299,16 @@ public void setPropTestDevices(final ReactPublisherAdView view, final ReadableAr
view.setTestDevices(list.toArray(new String[list.size()]));
}

@ReactProp(name = PROP_TARGETING)
public void setPropTARGETING(final ReactPublisherAdView view, final ReadableMap targeting) {
try {
JSONObject jsonObject = ReactNativeJson.convertMapToJson(targeting);
view.setCustomTargeting((JSONObject) jsonObject.get("customTargeting"));
} catch (JSONException e) {

}
}

private AdSize getAdSizeFromString(String adSize) {
switch (adSize) {
case "banner":
Expand Down
Loading