Skip to content

Commit

Permalink
Adds nonPersonalizedAds option to MobileAdTargetingInfo for firebase_…
Browse files Browse the repository at this point in the history
…admob (flutter#638)

* Adds nonPersonalizedAds option to MobileAdTargetingInfo

* Formats code

* Bump version
  • Loading branch information
mmmeri authored and kroikie committed Aug 24, 2018
1 parent d447c4a commit c9c4016
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 10 deletions.
4 changes: 4 additions & 0 deletions packages/firebase_admob/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.0

* Add nonPersonalizedAds option to MobileAdTargetingInfo

## 0.5.7

* Bumped mockito dependency to pick up Dart 2 support.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

package io.flutter.plugins.firebaseadmob;

import android.os.Bundle;
import android.util.Log;
import com.google.ads.mediation.admob.AdMobAdapter;
import com.google.android.gms.ads.AdRequest;
import java.util.ArrayList;
import java.util.Date;
Expand Down Expand Up @@ -115,6 +117,14 @@ AdRequest.Builder createAdRequestBuilder() {
String requestAgent = getTargetingInfoString("requestAgent", targetingInfo.get("requestAgent"));
if (requestAgent != null) builder.setRequestAgent(requestAgent);

Boolean nonPersonalizedAds =
getTargetingInfoBoolean("nonPersonalizedAds", targetingInfo.get("nonPersonalizedAds"));
if (nonPersonalizedAds != null && nonPersonalizedAds) {
Bundle extras = new Bundle();
extras.putString("npa", "1");
builder.addNetworkExtrasBundle(AdMobAdapter.class, extras);
}

return builder;
}
}
1 change: 1 addition & 0 deletions packages/firebase_admob/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class _MyAppState extends State<MyApp> {
birthday: new DateTime.now(),
childDirected: true,
gender: MobileAdGender.male,
nonPersonalizedAds: true,
);

BannerAd _bannerAd;
Expand Down
9 changes: 9 additions & 0 deletions packages/firebase_admob/ios/Classes/FLTRequestFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#import "FLTRequestFactory.h"
#import "FirebaseAdMobPlugin.h"
#import "GoogleMobileAds/GADExtras.h"
#import "GoogleMobileAds/GoogleMobileAds.h"

@implementation FLTRequestFactory
Expand Down Expand Up @@ -120,6 +121,14 @@ - (GADRequest *)createRequest {
request.requestAgent = requestAgent;
}

NSNumber *nonPersonalizedAds =
[self targetingInfoBoolForKey:@"nonPersonalizedAds" info:_targetingInfo];
if (nonPersonalizedAds != nil && [nonPersonalizedAds boolValue]) {
GADExtras *extras = [[GADExtras alloc] init];
extras.additionalParameters = @{@"npa" : @"1"};
[request registerAdNetworkExtras:extras];
}

return request;
}

Expand Down
21 changes: 12 additions & 9 deletions packages/firebase_admob/lib/firebase_admob.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ typedef void MobileAdListener(MobileAdEvent event);
/// This class's properties mirror the native AdRequest API. See for example:
/// [AdRequest.Builder for Android](https://firebase.google.com/docs/reference/android/com/google/android/gms/ads/AdRequest.Builder).
class MobileAdTargetingInfo {
const MobileAdTargetingInfo({
this.keywords,
this.contentUrl,
this.birthday,
this.gender,
this.designedForFamilies,
this.childDirected,
this.testDevices,
});
const MobileAdTargetingInfo(
{this.keywords,
this.contentUrl,
this.birthday,
this.gender,
this.designedForFamilies,
this.childDirected,
this.testDevices,
this.nonPersonalizedAds});

final List<String> keywords;
final String contentUrl;
Expand All @@ -56,6 +56,7 @@ class MobileAdTargetingInfo {
final bool designedForFamilies;
final bool childDirected;
final List<String> testDevices;
final bool nonPersonalizedAds;

Map<String, dynamic> toJson() {
final Map<String, dynamic> json = <String, dynamic>{
Expand All @@ -66,6 +67,8 @@ class MobileAdTargetingInfo {
assert(keywords.every((String s) => s != null && s.isNotEmpty));
json['keywords'] = keywords;
}
if (nonPersonalizedAds != null)
json['nonPersonalizedAds'] = nonPersonalizedAds;
if (contentUrl != null && contentUrl.isNotEmpty)
json['contentUrl'] = contentUrl;
if (birthday != null) json['birthday'] = birthday.millisecondsSinceEpoch;
Expand Down
2 changes: 1 addition & 1 deletion packages/firebase_admob/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: firebase_admob
description: Firebase AdMob plugin for Flutter applications.
author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_admob
version: 0.5.7
version: 0.6.0

flutter:
plugin:
Expand Down

0 comments on commit c9c4016

Please sign in to comment.