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

RFC: Targeting support #166

Open
wants to merge 2 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
6 changes: 6 additions & 0 deletions Example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ 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'],
contentURL: 'admob://',
publisherProvidedID: 'abc123',
}}
/>
<Button
title="Reload"
Expand Down
2 changes: 1 addition & 1 deletion Example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5171,7 +5171,7 @@ react-is@^16.8.1, react-is@^16.8.4, react-is@^16.8.6:
integrity sha512-tJBzzzIgnnRfEm046qRcURvwQnZVXmuCbscxUO5RWrGTXpon2d4c8mI0D8WE6ydVIm29JiLB6+RslkIvym9Rjw==

"react-native-admob@file:..":
version "2.0.0-beta.5"
version "2.0.0-beta.6"
dependencies:
prop-types "^15.7.2"

Expand Down
3 changes: 3 additions & 0 deletions RNAdMobRequestConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { NativeModules } from 'react-native';

export default NativeModules.RNAdMobRequestConfig;
51 changes: 50 additions & 1 deletion RNPublisherBanner.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import { arrayOf, func, string } from 'prop-types';
import {
arrayOf,
bool,
func,
instanceOf,
number,
object,
oneOf,
shape,
string,
} from 'prop-types';
import React, { Component } from 'react';
import {
findNodeHandle,
Expand Down Expand Up @@ -114,6 +124,45 @@ PublisherBanner.propTypes = {
onAdClosed: func,
onAdLeftApplication: func,
onAppEvent: func,

targeting: shape({
/**
* Arbitrary object of custom targeting information.
*/
customTargeting: object,

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

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

/**
* 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(
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/* eslint-disable global-require */
module.exports = {
get AdMobRequestConfig() {
return require('./RNAdMobRequestConfig').default;
},
get AdMobBanner() {
return require('./RNAdMobBanner').default;
},
Expand Down
8 changes: 8 additions & 0 deletions ios/RCTConvert+GADMaxAdContentRating.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#import <React/RCTConvert.h>
@import GoogleMobileAds;

@interface RCTConvert (GoogleMobileAds)

+ (GADMaxAdContentRating)GADMaxAdContentRating:(id)json;

@end
19 changes: 19 additions & 0 deletions ios/RCTConvert+GADMaxAdContentRating.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#import "RCTConvert+GADMaxAdContentRating.h"

@implementation RCTConvert (GoogleMobileAds)

+ (GADMaxAdContentRating)GADMaxAdContentRating:(id)json
{
NSString *rating = [self NSString:json];
if ([rating isEqualToString:@"parentalGuidance"]) {
return GADMaxAdContentRatingParentalGuidance;
} else if ([rating isEqualToString:@"teen"]) {
return GADMaxAdContentRatingTeen;
} else if ([rating isEqualToString:@"matureAudience"]) {
return GADMaxAdContentRatingMatureAudience;
} else {
return GADMaxAdContentRatingGeneral;
}
}

@end
6 changes: 6 additions & 0 deletions ios/RNAdMobManager.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
0CB8C04E1D9143A6002BC3EF /* RNDFPBannerViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 0CB8C04D1D9143A6002BC3EF /* RNDFPBannerViewManager.m */; };
5E2419841FE11E0F00C6B738 /* RNAdMobUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E2419831FE11E0F00C6B738 /* RNAdMobUtils.m */; };
5E86A6471F126FCE008013EB /* RCTConvert+GADAdSize.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E86A6461F126FCE008013EB /* RCTConvert+GADAdSize.m */; };
5EE0EED01F327DFD0045CC2C /* RCTConvert+GADGender.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EE0EECF1F327DFD0045CC2C /* RCTConvert+GADGender.m */; };
A90F2F8C1D50AEF200F2A2E3 /* RNAdMobRewarded.m in Sources */ = {isa = PBXBuildFile; fileRef = A90F2F8B1D50AEF200F2A2E3 /* RNAdMobRewarded.m */; };
A962C2531CB27DBD00E508A1 /* RNAdMobInterstitial.m in Sources */ = {isa = PBXBuildFile; fileRef = A962C2521CB27DBD00E508A1 /* RNAdMobInterstitial.m */; };
A96DA7841C146DA600FC639B /* RNGADBannerView.m in Sources */ = {isa = PBXBuildFile; fileRef = A96DA7811C146DA600FC639B /* RNGADBannerView.m */; };
Expand Down Expand Up @@ -38,6 +39,8 @@
5E2419851FE11F1200C6B738 /* RNAdMobUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNAdMobUtils.h; sourceTree = SOURCE_ROOT; };
5E86A6451F126FCE008013EB /* RCTConvert+GADAdSize.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RCTConvert+GADAdSize.h"; sourceTree = SOURCE_ROOT; };
5E86A6461F126FCE008013EB /* RCTConvert+GADAdSize.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+GADAdSize.m"; sourceTree = SOURCE_ROOT; };
5EE0EECE1F327DFD0045CC2C /* RCTConvert+GADGender.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RCTConvert+GADGender.h"; sourceTree = SOURCE_ROOT; };
5EE0EECF1F327DFD0045CC2C /* RCTConvert+GADGender.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+GADGender.m"; sourceTree = SOURCE_ROOT; };
A90F2F8A1D50AEF200F2A2E3 /* RNAdMobRewarded.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNAdMobRewarded.h; sourceTree = SOURCE_ROOT; };
A90F2F8B1D50AEF200F2A2E3 /* RNAdMobRewarded.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNAdMobRewarded.m; sourceTree = SOURCE_ROOT; };
A962C2511CB27DBD00E508A1 /* RNAdMobInterstitial.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNAdMobInterstitial.h; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -95,6 +98,8 @@
A90F2F8B1D50AEF200F2A2E3 /* RNAdMobRewarded.m */,
5E86A6451F126FCE008013EB /* RCTConvert+GADAdSize.h */,
5E86A6461F126FCE008013EB /* RCTConvert+GADAdSize.m */,
5EE0EECE1F327DFD0045CC2C /* RCTConvert+GADGender.h */,
5EE0EECF1F327DFD0045CC2C /* RCTConvert+GADGender.m */,
);
path = RNAdMobManager;
sourceTree = "<group>";
Expand Down Expand Up @@ -164,6 +169,7 @@
5E2419841FE11E0F00C6B738 /* RNAdMobUtils.m in Sources */,
5E86A6471F126FCE008013EB /* RCTConvert+GADAdSize.m in Sources */,
0CB8C04E1D9143A6002BC3EF /* RNDFPBannerViewManager.m in Sources */,
5EE0EED01F327DFD0045CC2C /* RCTConvert+GADGender.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
9 changes: 9 additions & 0 deletions ios/RNAdMobRequestConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#import <React/RCTBridgeModule.h>

NS_ASSUME_NONNULL_BEGIN

@interface RNAdMobRequestConfig : NSObject <RCTBridgeModule>

@end

NS_ASSUME_NONNULL_END
36 changes: 36 additions & 0 deletions ios/RNAdMobRequestConfig.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#import <React/RCTUtils.h>

#import "RNAdMobRequestConfig.h"

@import GoogleMobileAds;

@implementation RNAdMobRequestConfig

RCT_EXPORT_MODULE();

+ (BOOL)requiresMainQueueSetup
{
return NO;
}

RCT_EXPORT_METHOD(setMaxAdContentRating:(GADMaxAdContentRating)maxAdContentRating)
{
[GADMobileAds.sharedInstance.requestConfiguration
setMaxAdContentRating:maxAdContentRating];
}

RCT_EXPORT_METHOD(tagForChildDirectedTreatment:(BOOL)value)
{
[GADMobileAds.sharedInstance.requestConfiguration
tagForChildDirectedTreatment:value];
}

RCT_EXPORT_METHOD(tagForUnderAgeOfConsent:(BOOL)value)
{
[GADMobileAds.sharedInstance.requestConfiguration
tagForUnderAgeOfConsent:value];
}



@end
1 change: 1 addition & 0 deletions ios/RNDFPBannerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

@property (nonatomic, copy) NSArray *validAdSizes;
@property (nonatomic, copy) NSArray *testDevices;
@property (nonatomic, copy) NSDictionary *targeting;

@property (nonatomic, copy) RCTBubblingEventBlock onSizeChange;
@property (nonatomic, copy) RCTBubblingEventBlock onAppEvent;
Expand Down
33 changes: 32 additions & 1 deletion ios/RNDFPBannerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,39 @@ - (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex
#pragma clang diagnostic pop

- (void)loadBanner {
GADRequest *request = [GADRequest request];
DFPRequest *request = [DFPRequest request];
request.testDevices = _testDevices;

if (_targeting != nil) {
NSDictionary *customTargeting = [_targeting objectForKey:@"customTargeting"];
if (customTargeting != nil) {
request.customTargeting = customTargeting;
}
NSArray *categoryExclusions = [_targeting objectForKey:@"categoryExclusions"];
if (categoryExclusions != nil) {
request.categoryExclusions = categoryExclusions;
}
NSArray *keywords = [_targeting objectForKey:@"keywords"];
if (keywords != nil) {
request.keywords = keywords;
}
NSString *contentURL = [_targeting objectForKey:@"contentURL"];
if (contentURL != nil) {
request.contentURL = contentURL;
}
NSString *publisherProvidedID = [_targeting objectForKey:@"publisherProvidedID"];
if (publisherProvidedID != nil) {
request.publisherProvidedID = publisherProvidedID;
}
NSDictionary *location = [_targeting objectForKey:@"location"];
if (location != nil) {
CGFloat latitude = [[location objectForKey:@"latitude"] doubleValue];
CGFloat longitude = [[location objectForKey:@"longitude"] doubleValue];
CGFloat accuracy = [[location objectForKey:@"accuracy"] doubleValue];
[request setLocationWithLatitude:latitude longitude:longitude accuracy:accuracy];
}
}

[_bannerView loadRequest:request];
}

Expand Down
1 change: 1 addition & 0 deletions ios/RNDFPBannerViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ - (UIView *)view
RCT_REMAP_VIEW_PROPERTY(adUnitID, _bannerView.adUnitID, NSString)
RCT_EXPORT_VIEW_PROPERTY(validAdSizes, NSArray)
RCT_EXPORT_VIEW_PROPERTY(testDevices, NSArray)
RCT_EXPORT_VIEW_PROPERTY(targeting, NSDictionary)

RCT_EXPORT_VIEW_PROPERTY(onSizeChange, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onAppEvent, RCTBubblingEventBlock)
Expand Down