Ad Request Settings

This guide explains how to provide targeting information to an ad request.

Prerequisites

GADRequest

The GADRequest object collects targeting information to be sent with an ad request.

Test ads

During development, we recommend using test ads to avoid generating false impressions. Moreover, you can always count on a test ad being available.

Test ads can be enabled by setting the testDevices property on GADRequest with an array of hashed device identifiers:

Objective-C

GADRequest *request = [GADRequest request];
request.testDevices = @[@"2077ef9a63d2b398840261c8221a0c9b"];

Swift

let request = GADRequest()
request.testDevices = ["2077ef9a63d2b398840261c8221a0c9b"]

For devices, check the logs in Xcode when running your app and making an ad request. You'll get a log that looks like this:

<Google> To get test ads on this device, call: request.testDevices = @[
@"2077ef9a63d2b398840261c8221a0c9b" ];

Remember to add a test device ID for each device for which you want to request test ads.

Location

If a user has granted your app location permissions, location data is automatically passed to the SDK. The SDK uses this data to improve ad targeting without requiring any code changes in your app. You can, of course, enable or disable location data for ads.

Autopopulated location information is not forwarded to mediation networks and it may also be disabled entirely. Therefore, the SDK provides the ability to set location manually.

After getting the user's location, you can specify location-targeting information in the GADRequest as follows:

Swift

let request = GADRequest()
if let currentLocation = locationManager.location {
  request.setLocationWithLatitude(CGFloat(currentLocation.coordinate.latitude),
      longitude: CGFloat(currentLocation.coordinate.longitude),
      accuracy: CGFloat(currentLocation.horizontalAccuracy))
}

Objective-C

GADRequest *request = [GADRequest request];
CLLocation *currentLocation = locationManager.location;
if (currentLocation) {
  [request setLocationWithLatitude:currentLocation.coordinate.latitude
                         longitude:currentLocation.coordinate.longitude
                          accuracy:currentLocation.horizontalAccuracy];
}

Out of respect for user privacy, Google asks that you only specify location if that information is already used by your app.

Child-directed setting

For purposes of the Children's Online Privacy Protection Act (COPPA), there is a setting called "tag for child directed treatment".

As an app developer, you can indicate whether you want Google to treat your content as child-directed when you make an ad request. If you indicate that you want Google to treat your content as child-directed, we take steps to disable IBA and remarketing ads on that ad request.

  • Setting tagForChildDirectedTreatment to YES indicates that you want your content treated as child-directed for purposes of COPPA.
  • Setting tagForChildDirectedTreatment to NO indicates that you don't want your content treated as child-directed for purposes of COPPA.
  • Not setting tagForChildDirectedTreatment provides no indication of how you would like your content treated with respect to COPPA.

Objective-C

GADRequest *request = [GADRequest request];
[request tagForChildDirectedTreatment:YES];

Swift

let request = GADRequest()
request.tag(forChildDirectedTreatment: true)

By setting this tag, you certify that this notification is accurate and you are authorized to act on behalf of the owner of the app. You understand that abuse of this setting may result in termination of your Google account.

Content URL

Applications that monetize content matching a webpage's content may pass a content URL for keyword targeting.

For example, if your app serves blog articles and is requesting an ad while showing content from the article http://googleadsdeveloper.blogspot.com/2013/10/upgrade-to-new-google-mobile-ads-sdk.html, then you can pass this URL to target relevant keywords:

Objective-C

GADRequest *request = [GADRequest request];
request.contentURL = @"http://googleadsdeveloper.blogspot.com/2013/10/upgrade-to-new-google-mobile-ads-sdk.html";

Swift

let request = GADRequest()
request.contentURL = "http://googleadsdeveloper.blogspot.com/2013/10/upgrade-to-new-google-mobile-ads-sdk.html"

Loading an ad with targeting

Once all of your request targeting information is set, call loadRequest on GADBannerView with your GADRequest instance.

Objective-C

GADRequest *request = [GADRequest request];
[request tagForChildDirectedTreatment:YES];
request.contentURL = @"http://googleadsdeveloper.blogspot.com/2013/10/upgrade-to-new-google-mobile-ads-sdk.html";
[self.adView loadRequest:request];

Swift

let request = GADRequest()
request.tag(forChildDirectedTreatment: true)
request.contentURL = "http://googleadsdeveloper.blogspot.com/2013/10/upgrade-to-new-google-mobile-ads-sdk.html"
adView.load(request)

See the Ad Targeting example for an implementation of ad targeting in the iOS API Demo app.

Objective-C Swift

FAQ

Can I release my app with request.testDevices?
Yes. Test ads are only shown on the devices that you specify. So even if you release your app with request.testDevices, all of your users—who are not using those specified devices—receive production ads.
What targeting gets used when an ad automatically refreshes?
On ad refresh, the previously specified GADRequest object is used for targeting again. To set new targeting, explicitly call loadRequest on GADBannerView with a new GADRequest object.

Send feedback about...

SDK for AdX Users on iOS
Need help? Visit our support page.