From 1be0bfff56328dbca17bdb54b7390a6179e5c0f0 Mon Sep 17 00:00:00 2001 From: gladiuscode Date: Wed, 12 Jun 2024 14:26:37 +0200 Subject: [PATCH 1/4] feat(js): setup javascript layer with new property servePersonalizedAds --- src/CTKAdManagerAdaptiveBanner.tsx | 2 ++ src/CTKAdManagerBanner.tsx | 37 +++++++++++++++++++----------- src/CTKAdManagerInterstitial.ts | 15 ++++++++---- src/native-ads/withNativeAd.tsx | 9 ++++++-- 4 files changed, 43 insertions(+), 20 deletions(-) diff --git a/src/CTKAdManagerAdaptiveBanner.tsx b/src/CTKAdManagerAdaptiveBanner.tsx index b20a336..0c8a750 100644 --- a/src/CTKAdManagerAdaptiveBanner.tsx +++ b/src/CTKAdManagerAdaptiveBanner.tsx @@ -44,6 +44,8 @@ interface IAdManagerAdaptiveBannerPropsBase extends ViewProps { testDevices?: string[]; targeting?: IAdManagerTargeting; + + servePersonalizedAds?: boolean; } interface IAdManagerAdaptiveBannerProps diff --git a/src/CTKAdManagerBanner.tsx b/src/CTKAdManagerBanner.tsx index d3130cb..7dafef3 100644 --- a/src/CTKAdManagerBanner.tsx +++ b/src/CTKAdManagerBanner.tsx @@ -5,8 +5,8 @@ import { ViewProps, findNodeHandle, NativeSyntheticEvent, - DeviceEventEmitter, - EventSubscription + DeviceEventEmitter, + EventSubscription, } from 'react-native'; import { createErrorFromErrorData } from './utils'; import type { @@ -52,10 +52,12 @@ interface IAdManagerBannerPropsBase extends ViewProps { testDevices?: string[]; targeting?: IAdManagerTargeting; + + servePersonalizedAds?: boolean; } interface IAdManagerBannerProps extends IAdManagerBannerPropsBase { - // onError is a callback function sent from parent RN component of your RN app, aka: the error handler. + // onError is a callback function sent from parent RN component of your RN app, aka: the error handler. // so if your RN App wants to handle the error, please pass in the "onError" function. onError?: (eventData: Error) => void; /** @@ -92,7 +94,9 @@ interface IAdManagerBannerNativeProps extends IAdManagerBannerPropsBase { onAppEvent?: (event: NativeSyntheticEvent) => void; onAdOpened?: (event: NativeSyntheticEvent) => void; onAdClosed?: (event: NativeSyntheticEvent) => void; - onAdRecordImpression?: (event: NativeSyntheticEvent) => void; + onAdRecordImpression?: ( + event: NativeSyntheticEvent + ) => void; } const ComponentName = 'CTKBannerView'; @@ -113,7 +117,10 @@ export class Banner extends React.Component< constructor(props: IAdManagerBannerProps) { super(props); - this.hasOnErrorFromParent = Object.prototype.hasOwnProperty.call(props, 'onError'); + this.hasOnErrorFromParent = Object.prototype.hasOwnProperty.call( + props, + 'onError' + ); this.handleSizeChange = this.handleSizeChange.bind(this); this.state = { style: {}, @@ -137,21 +144,24 @@ export class Banner extends React.Component< } componentDidMount() { - this.customListener= DeviceEventEmitter.addListener('onError',eventData=>{ - this.setState({ error: eventData }); - if (this.hasOnErrorFromParent && this.props.onError) { - this.props.onError(eventData); + this.customListener = DeviceEventEmitter.addListener( + 'onError', + (eventData) => { + this.setState({ error: eventData }); + if (this.hasOnErrorFromParent && this.props.onError) { + this.props.onError(eventData); + } } - }); + ); this.loadBanner(); } - + componentWillUnmount() { if (this.customListener) { this.customListener.remove(); } } - + loadBanner() { UIManager.dispatchViewManagerCommand( findNodeHandle(this), @@ -191,7 +201,8 @@ export class Banner extends React.Component< this.props.onAdClosed && this.props.onAdClosed(event.nativeEvent) } onAdRecordImpression={(event) => - this.props.onAdRecordImpression && this.props.onAdRecordImpression(event.nativeEvent) + this.props.onAdRecordImpression && + this.props.onAdRecordImpression(event.nativeEvent) } /> ); diff --git a/src/CTKAdManagerInterstitial.ts b/src/CTKAdManagerInterstitial.ts index b2ab9ac..ec4490a 100644 --- a/src/CTKAdManagerInterstitial.ts +++ b/src/CTKAdManagerInterstitial.ts @@ -101,17 +101,21 @@ const setTargeting = (targeting: IAdManagerTargeting) => { CTKInterstitial.setTargeting(targeting); }; +const setServePersonalizedAds = (servePersonalizedAds: boolean) => { + CTKInterstitial.setServePersonalizedAds(servePersonalizedAds); +}; + const requestAd = (): Promise => { return CTKInterstitial.requestAd(); -} +}; const showAd = (): Promise => { return CTKInterstitial.showAd(); -} +}; const isReady = (callback: (isReady: boolean) => void): Promise => { return CTKInterstitial.isReady(callback); -} +}; export default { addEventListener, @@ -123,5 +127,6 @@ export default { setTargeting, requestAd, showAd, - isReady -} + setServePersonalizedAds, + isReady, +}; diff --git a/src/native-ads/withNativeAd.tsx b/src/native-ads/withNativeAd.tsx index fef346b..544f701 100644 --- a/src/native-ads/withNativeAd.tsx +++ b/src/native-ads/withNativeAd.tsx @@ -37,6 +37,7 @@ interface INativeAdPropsBase extends ViewProps { validAdTypes?: ('banner' | 'native' | 'template')[]; customClickTemplateIds?: string[]; targeting?: IAdManagerTargeting; + servePersonalizedAds?: boolean; } interface INativeAdNativeProps extends INativeAdPropsBase { @@ -60,7 +61,9 @@ interface INativeAdNativeProps extends INativeAdPropsBase { onAdCustomClick?: ( event: NativeSyntheticEvent ) => void; - onAdRecordImpression?: (event: NativeSyntheticEvent) => void; + onAdRecordImpression?: ( + event: NativeSyntheticEvent + ) => void; } interface INativeAdProps extends INativeAdPropsBase { @@ -276,11 +279,13 @@ export default (Component: JSXElementConstructor) => this.props.onAdCustomClick(event.nativeEvent) } onAdRecordImpression={(event) => - this.props.onAdRecordImpression && this.props.onAdRecordImpression(event.nativeEvent) + this.props.onAdRecordImpression && + this.props.onAdRecordImpression(event.nativeEvent) } targeting={this.props.targeting} customClickTemplateIds={this.props.customClickTemplateIds} adsManager={adsManager.toJSON()} + servePersonalizedAds={this.props.servePersonalizedAds} > {this.renderAdComponent(rest)} From 89ba77349e7c573f2a2231cf45cd87f4716649c9 Mon Sep 17 00:00:00 2001 From: gladiuscode Date: Wed, 12 Jun 2024 15:41:53 +0200 Subject: [PATCH 2/4] feat(iOS): setup iOS native layer with new property servePersonalizedAds --- ios/RNAdManageNativeManager.m | 1 + ios/RNAdManageNativeView.h | 1 + ios/RNAdManageNativeView.m | 21 +++++++++++++++++---- ios/RNAdManagerAdaptiveBannerView.h | 1 + ios/RNAdManagerAdaptiveBannerView.m | 20 +++++++++++++++++--- ios/RNAdManagerAdaptiveBannerViewManager.m | 1 + ios/RNAdManagerBannerView.h | 1 + ios/RNAdManagerBannerView.m | 19 ++++++++++++++++--- ios/RNAdManagerBannerViewManager.m | 1 + ios/RNAdManagerInterstitial.m | 14 ++++++++++++++ 10 files changed, 70 insertions(+), 10 deletions(-) diff --git a/ios/RNAdManageNativeManager.m b/ios/RNAdManageNativeManager.m index b8ec4dd..2eb6acb 100644 --- a/ios/RNAdManageNativeManager.m +++ b/ios/RNAdManageNativeManager.m @@ -180,6 +180,7 @@ - (UIView *)view RCT_EXPORT_VIEW_PROPERTY(validAdSizes, NSArray) RCT_EXPORT_VIEW_PROPERTY(targeting, NSDictionary) RCT_EXPORT_VIEW_PROPERTY(correlator, NSString) +RCT_EXPORT_VIEW_PROPERTY(servePersonalizedAds, BOOL) RCT_EXPORT_VIEW_PROPERTY(onSizeChange, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onAppEvent, RCTBubblingEventBlock) diff --git a/ios/RNAdManageNativeView.h b/ios/RNAdManageNativeView.h index dfcfd91..3fd6201 100644 --- a/ios/RNAdManageNativeView.h +++ b/ios/RNAdManageNativeView.h @@ -33,6 +33,7 @@ @property (nonatomic, copy) NSArray *validAdSizes; @property (nonatomic, copy) NSDictionary *targeting; @property (nonatomic, copy) NSString *correlator; +@property (nonatomic) BOOL servePersonalizedAds; @property (nonatomic, copy) RCTBubblingEventBlock onSizeChange; @property (nonatomic, copy) RCTBubblingEventBlock onAppEvent; diff --git a/ios/RNAdManageNativeView.m b/ios/RNAdManageNativeView.m index bdcd22c..ffef3c0 100644 --- a/ios/RNAdManageNativeView.m +++ b/ios/RNAdManageNativeView.m @@ -143,10 +143,17 @@ - (void)reloadAd { if (_correlator == nil) { _correlator = getCorrelator(_adUnitID); } - extras.additionalParameters = [[NSDictionary alloc] initWithObjectsAndKeys: - _correlator, @"correlator", - nil]; - + + NSMutableDictionary *additionalParams = [[NSMutableDictionary alloc] initWithObjectsAndKeys: + _correlator, @"correlator", + nil]; + if (_servePersonalizedAds == NO) { + [additionalParams setObject:[NSNumber numberWithInt:1] forKey:@"npa"]; + } + + // Set the dictionary to extras.additionalParameters + extras.additionalParameters = [NSDictionary dictionaryWithDictionary:additionalParams]; + [request registerAdNetworkExtras:extras]; if (_targeting != nil) { @@ -237,6 +244,12 @@ - (void)setCorrelator:(NSString *)correlator _correlator = correlator; } +- (void)setServePersonalizedAds:(BOOL)servePersonalizedAds +{ + _servePersonalizedAds = servePersonalizedAds; +} + + #pragma mark GADAdLoaderDelegate implementation /// Tells the delegate an ad request failed.UnifiedNativeAdView diff --git a/ios/RNAdManagerAdaptiveBannerView.h b/ios/RNAdManagerAdaptiveBannerView.h index feb6f25..ee93f65 100644 --- a/ios/RNAdManagerAdaptiveBannerView.h +++ b/ios/RNAdManagerAdaptiveBannerView.h @@ -9,6 +9,7 @@ @property (nonatomic, copy) NSNumber *maxHeight; @property (nonatomic, strong) NSString *adUnitID; @property (nonatomic, copy) NSString *correlator; +@property (nonatomic) BOOL servePersonalizedAds; @property (nonatomic, copy) RCTBubblingEventBlock onSizeChange; @property (nonatomic, copy) RCTBubblingEventBlock onAppEvent; diff --git a/ios/RNAdManagerAdaptiveBannerView.m b/ios/RNAdManagerAdaptiveBannerView.m index f919e41..e323d7b 100644 --- a/ios/RNAdManagerAdaptiveBannerView.m +++ b/ios/RNAdManagerAdaptiveBannerView.m @@ -53,6 +53,12 @@ - (void)setCorrelator:(NSString *)correlator _correlator = correlator; } +- (void)setServePersonalizedAds:(BOOL)servePersonalizedAds +{ + _servePersonalizedAds = servePersonalizedAds; +} + + // Initialise BannerAdView as soon as all the props are set - (void)createViewIfCan { @@ -110,9 +116,17 @@ - (void)createViewIfCan if (_correlator == nil) { _correlator = getCorrelator(_adUnitID); } - extras.additionalParameters = [[NSDictionary alloc] initWithObjectsAndKeys: - _correlator, @"correlator", - nil]; + + NSMutableDictionary *additionalParams = [[NSMutableDictionary alloc] initWithObjectsAndKeys: + _correlator, @"correlator", + nil]; + if (_servePersonalizedAds == NO) { + [additionalParams setObject:[NSNumber numberWithInt:1] forKey:@"npa"]; + } + + // Set the dictionary to extras.additionalParameters + extras.additionalParameters = [NSDictionary dictionaryWithDictionary:additionalParams]; + [request registerAdNetworkExtras:extras]; if (_targeting != nil) { diff --git a/ios/RNAdManagerAdaptiveBannerViewManager.m b/ios/RNAdManagerAdaptiveBannerViewManager.m index 0118f4e..a276856 100644 --- a/ios/RNAdManagerAdaptiveBannerViewManager.m +++ b/ios/RNAdManagerAdaptiveBannerViewManager.m @@ -40,6 +40,7 @@ - (UIView *)view RCT_EXPORT_VIEW_PROPERTY(correlator, NSString) RCT_EXPORT_VIEW_PROPERTY(testDevices, NSArray) RCT_EXPORT_VIEW_PROPERTY(targeting, NSDictionary) +RCT_EXPORT_VIEW_PROPERTY(servePersonalizedAds, BOOL) RCT_EXPORT_VIEW_PROPERTY(onSizeChange, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onAppEvent, RCTBubblingEventBlock) diff --git a/ios/RNAdManagerBannerView.h b/ios/RNAdManagerBannerView.h index e2ec2cb..d86d1f3 100644 --- a/ios/RNAdManagerBannerView.h +++ b/ios/RNAdManagerBannerView.h @@ -9,6 +9,7 @@ @property (nonatomic, copy) NSString *adSize; @property (nonatomic, strong) NSString *adUnitID; @property (nonatomic, copy) NSString *correlator; +@property (nonatomic) BOOL servePersonalizedAds; @property (nonatomic, copy) RCTBubblingEventBlock onSizeChange; @property (nonatomic, copy) RCTBubblingEventBlock onAppEvent; diff --git a/ios/RNAdManagerBannerView.m b/ios/RNAdManagerBannerView.m index a92d69a..4e1144f 100644 --- a/ios/RNAdManagerBannerView.m +++ b/ios/RNAdManagerBannerView.m @@ -64,6 +64,11 @@ - (void)setCorrelator:(NSString *)correlator _correlator = correlator; } +- (void)setServePersonalizedAds:(BOOL)servePersonalizedAds +{ + _servePersonalizedAds = servePersonalizedAds; +} + // Initialise BannerAdView as soon as all the props are set - (void)createViewIfCan { @@ -97,9 +102,17 @@ - (void)createViewIfCan if (_correlator == nil) { _correlator = getCorrelator(_adUnitID); } - extras.additionalParameters = [[NSDictionary alloc] initWithObjectsAndKeys: - _correlator, @"correlator", - nil]; + + NSMutableDictionary *additionalParams = [[NSMutableDictionary alloc] initWithObjectsAndKeys: + _correlator, @"correlator", + nil]; + if (_servePersonalizedAds == NO) { + [additionalParams setObject:[NSNumber numberWithInt:1] forKey:@"npa"]; + } + + // Set the dictionary to extras.additionalParameters + extras.additionalParameters = [NSDictionary dictionaryWithDictionary:additionalParams]; + [request registerAdNetworkExtras:extras]; if (_targeting != nil) { diff --git a/ios/RNAdManagerBannerViewManager.m b/ios/RNAdManagerBannerViewManager.m index 0e7c50d..7a698ca 100644 --- a/ios/RNAdManagerBannerViewManager.m +++ b/ios/RNAdManagerBannerViewManager.m @@ -45,6 +45,7 @@ - (UIView *)view RCT_EXPORT_VIEW_PROPERTY(validAdSizes, NSArray) RCT_EXPORT_VIEW_PROPERTY(testDevices, NSArray) RCT_EXPORT_VIEW_PROPERTY(targeting, NSDictionary) +RCT_EXPORT_VIEW_PROPERTY(servePersonalizedAds, BOOL) RCT_EXPORT_VIEW_PROPERTY(onSizeChange, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onAppEvent, RCTBubblingEventBlock) diff --git a/ios/RNAdManagerInterstitial.m b/ios/RNAdManagerInterstitial.m index ea69e41..74ff963 100644 --- a/ios/RNAdManagerInterstitial.m +++ b/ios/RNAdManagerInterstitial.m @@ -15,6 +15,7 @@ @implementation RNAdManagerInterstitial NSString *_adUnitID; NSArray *_testDevices; NSDictionary *_targeting; + BOOL _servePersonalizedAds; RCTPromiseResolveBlock _requestAdResolve; RCTPromiseRejectBlock _requestAdReject; @@ -60,6 +61,11 @@ + (BOOL)requiresMainQueueSetup _targeting = targeting; } +RCT_EXPORT_METHOD(setServePersonalizedAds:(BOOL) servePersonalizedAds) +{ + _servePersonalizedAds = servePersonalizedAds; +} + RCT_EXPORT_METHOD(requestAd:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { _requestAdResolve = nil; @@ -72,6 +78,14 @@ + (BOOL)requiresMainQueueSetup GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = _testDevices; GAMRequest *request = [GAMRequest request]; + + if (_servePersonalizedAds == NO) { + GADExtras *extras = [[GADExtras alloc] init]; + extras.additionalParameters = [[NSDictionary alloc] initWithObjectsAndKeys: + [NSNumber numberWithInt:1], @"npa", + nil]; + [request registerAdNetworkExtras:extras]; + } if (_targeting != nil) { NSDictionary *customTargeting = [_targeting objectForKey:@"customTargeting"]; From a5c41128747215c4bf8bec627df930a7b639467e Mon Sep 17 00:00:00 2001 From: gladiuscode Date: Wed, 12 Jun 2024 16:01:03 +0200 Subject: [PATCH 3/4] feat(android): setup Android native layer with new property servePersonalizedAds --- .../matejdr/admanager/AdaptiveBannerAdView.java | 9 +++++++++ .../java/com/matejdr/admanager/BannerAdView.java | 14 ++++++++++++++ .../matejdr/admanager/NativeAdViewContainer.java | 11 ++++++++++- .../RNAdManagerAdaptiveBannerViewManager.java | 6 ++++++ .../admanager/RNAdManagerBannerViewManager.java | 6 ++++++ .../matejdr/admanager/RNAdManagerInterstitial.java | 13 +++++++++++++ .../admanager/RNAdManagerNativeViewManager.java | 7 +++++++ 7 files changed, 65 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/matejdr/admanager/AdaptiveBannerAdView.java b/android/src/main/java/com/matejdr/admanager/AdaptiveBannerAdView.java index 3929753..8ebbffa 100644 --- a/android/src/main/java/com/matejdr/admanager/AdaptiveBannerAdView.java +++ b/android/src/main/java/com/matejdr/admanager/AdaptiveBannerAdView.java @@ -48,6 +48,7 @@ class AdaptiveBannerAdView extends ReactViewGroup implements AppEventListener, L String publisherProvidedID; Location location; String correlator; + Boolean servePersonalizedAds = true; int top; int left; @@ -207,6 +208,10 @@ public void loadBanner() { Bundle bundle = new Bundle(); bundle.putString("correlator", correlator); + if (!servePersonalizedAds) { + bundle.putInt("npa", 1); + } + adRequestBuilder.addNetworkExtrasBundle(AdMobAdapter.class, bundle); // Targeting @@ -308,6 +313,10 @@ public void setCorrelator(String correlator) { this.correlator = correlator; } + public void setServePersonalizedAds(Boolean servePersonalizedAds) { + this.servePersonalizedAds = servePersonalizedAds; + } + @Override public void onAppEvent(String name, String info) { WritableMap event = Arguments.createMap(); diff --git a/android/src/main/java/com/matejdr/admanager/BannerAdView.java b/android/src/main/java/com/matejdr/admanager/BannerAdView.java index 348a7b6..4467dc9 100644 --- a/android/src/main/java/com/matejdr/admanager/BannerAdView.java +++ b/android/src/main/java/com/matejdr/admanager/BannerAdView.java @@ -50,6 +50,8 @@ class BannerAdView extends ReactViewGroup implements AppEventListener, Lifecycle Location location; String correlator; + Boolean servePersonalizedAds = true; + int top; int left; int width; @@ -283,6 +285,10 @@ public void loadBanner() { Bundle bundle = new Bundle(); bundle.putString("correlator", correlator); + if (!servePersonalizedAds) { + bundle.putInt("npa", 1); + } + adRequestBuilder.addNetworkExtrasBundle(AdMobAdapter.class, bundle); // Targeting @@ -447,6 +453,14 @@ public void setCorrelator(String correlator) { } } + public void setServePersonalizedAds(Boolean servePersonalizedAds) { + try { + this.servePersonalizedAds = servePersonalizedAds; + } catch (Exception e) { + sendErrorEvent("Error found at ad manager when setServePersonalizedAds(): " + e.getMessage() + "!"); + } + } + @Override public void onAppEvent(String name, String info) { try { diff --git a/android/src/main/java/com/matejdr/admanager/NativeAdViewContainer.java b/android/src/main/java/com/matejdr/admanager/NativeAdViewContainer.java index fc99289..50e532d 100644 --- a/android/src/main/java/com/matejdr/admanager/NativeAdViewContainer.java +++ b/android/src/main/java/com/matejdr/admanager/NativeAdViewContainer.java @@ -76,6 +76,7 @@ public class NativeAdViewContainer extends ReactViewGroup implements AppEventLis String publisherProvidedID; Location location; String correlator; + Boolean servePersonalizedAds = true; List customClickTemplateIds; /** @@ -267,6 +268,10 @@ public void run() { Bundle bundle = new Bundle(); bundle.putString("correlator", correlator); + if (!servePersonalizedAds) { + bundle.putInt("npa", 1); + } + adRequestBuilder.addNetworkExtrasBundle(AdMobAdapter.class, bundle); Bundle fbExtras = new FacebookExtras() @@ -313,7 +318,7 @@ public void run() { } // setLocation() became obsolete since GMA SDK version 21.0.0, link reference below: - // https://developers.google.com/admob/android/rel-notes + // https://developers.google.com/admob/android/rel-notes //if (location != null) { // adRequestBuilder.setLocation(location); //} @@ -639,6 +644,10 @@ public void setCorrelator(String correlator) { this.correlator = correlator; } + public void setServePersonalizedAds(Boolean servePersonalizedAds) { + this.servePersonalizedAds = servePersonalizedAds; + } + public void setCustomClickTemplateIds(String[] customClickTemplateIds) { this.customClickTemplateIds = Arrays.asList(customClickTemplateIds); } diff --git a/android/src/main/java/com/matejdr/admanager/RNAdManagerAdaptiveBannerViewManager.java b/android/src/main/java/com/matejdr/admanager/RNAdManagerAdaptiveBannerViewManager.java index 3bbf879..2750c06 100644 --- a/android/src/main/java/com/matejdr/admanager/RNAdManagerAdaptiveBannerViewManager.java +++ b/android/src/main/java/com/matejdr/admanager/RNAdManagerAdaptiveBannerViewManager.java @@ -32,6 +32,7 @@ public class RNAdManagerAdaptiveBannerViewManager extends ViewGroupManager getCommandsMap() { diff --git a/android/src/main/java/com/matejdr/admanager/RNAdManagerBannerViewManager.java b/android/src/main/java/com/matejdr/admanager/RNAdManagerBannerViewManager.java index ebe4d31..7722a93 100644 --- a/android/src/main/java/com/matejdr/admanager/RNAdManagerBannerViewManager.java +++ b/android/src/main/java/com/matejdr/admanager/RNAdManagerBannerViewManager.java @@ -34,6 +34,7 @@ public class RNAdManagerBannerViewManager extends ViewGroupManager public static final String PROP_TEST_DEVICES = "testDevices"; public static final String PROP_TARGETING = "targeting"; public static final String PROP_CORRELATOR = "correlator"; + public static final String PROP_SERVE_PERSONALIZED_ADS = "servePersonalizedAds"; public static final String EVENT_SIZE_CHANGE = "onSizeChange"; public static final String EVENT_AD_LOADED = "onAdLoaded"; @@ -190,6 +191,11 @@ public void setCorrelator(final BannerAdView view, final String correlator) { view.setCorrelator(correlator); } + @ReactProp(name = PROP_SERVE_PERSONALIZED_ADS) + public void setServePersonalizedAds(final BannerAdView view, final Boolean servePersonalizedAds) { + view.setServePersonalizedAds(servePersonalizedAds); + } + @Nullable @Override public Map getCommandsMap() { diff --git a/android/src/main/java/com/matejdr/admanager/RNAdManagerInterstitial.java b/android/src/main/java/com/matejdr/admanager/RNAdManagerInterstitial.java index 5cbf131..57dcecd 100644 --- a/android/src/main/java/com/matejdr/admanager/RNAdManagerInterstitial.java +++ b/android/src/main/java/com/matejdr/admanager/RNAdManagerInterstitial.java @@ -60,6 +60,7 @@ public class RNAdManagerInterstitial extends ReactContextBaseJavaModule { ReactApplicationContext reactContext; private Promise mRequestAdPromise; + private Boolean servePersonalizedAds = true; public RNAdManagerInterstitial(ReactApplicationContext reactContext) { super(reactContext); @@ -142,6 +143,11 @@ public void setTargeting(ReadableMap targetingObjects) { } } + @ReactMethod + public void setServePersonalizedAds(Boolean servePersonalizedAds) { + this.servePersonalizedAds = servePersonalizedAds; + } + private AdManagerAdRequest buildAdRequest() { AdManagerAdRequest.Builder adRequestBuilder = new AdManagerAdRequest.Builder(); @@ -203,6 +209,13 @@ private AdManagerAdRequest buildAdRequest() { // adRequestBuilder.setLocation(location); //} + Bundle bundle = new Bundle(); + if (!servePersonalizedAds) { + bundle.putInt("npa", 1); + } + + adRequestBuilder.addNetworkExtrasBundle(AdMobAdapter.class, bundle); + adRequest = adRequestBuilder.build(); this.adRequest = adRequest; diff --git a/android/src/main/java/com/matejdr/admanager/RNAdManagerNativeViewManager.java b/android/src/main/java/com/matejdr/admanager/RNAdManagerNativeViewManager.java index 334d36c..ea91528 100644 --- a/android/src/main/java/com/matejdr/admanager/RNAdManagerNativeViewManager.java +++ b/android/src/main/java/com/matejdr/admanager/RNAdManagerNativeViewManager.java @@ -36,6 +36,8 @@ public class RNAdManagerNativeViewManager extends ViewGroupManager Date: Wed, 12 Jun 2024 17:14:18 +0200 Subject: [PATCH 4/4] fix(android): missing bundle and admobadapter imports --- .../java/com/matejdr/admanager/RNAdManagerInterstitial.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/android/src/main/java/com/matejdr/admanager/RNAdManagerInterstitial.java b/android/src/main/java/com/matejdr/admanager/RNAdManagerInterstitial.java index 57dcecd..ee3553b 100644 --- a/android/src/main/java/com/matejdr/admanager/RNAdManagerInterstitial.java +++ b/android/src/main/java/com/matejdr/admanager/RNAdManagerInterstitial.java @@ -2,6 +2,7 @@ import android.app.Activity; import android.location.Location; +import android.os.Bundle; import android.os.Handler; import android.os.Looper; @@ -19,6 +20,7 @@ import com.facebook.react.bridge.ReadableNativeArray; import com.facebook.react.bridge.WritableMap; import com.facebook.react.modules.core.DeviceEventManagerModule; +import com.google.ads.mediation.admob.AdMobAdapter; import com.google.android.gms.ads.AdError; import com.google.android.gms.ads.FullScreenContentCallback; import com.google.android.gms.ads.LoadAdError;