This guide explains how to provide targeting information to an ad request.
To see ad targeting in action, download the iOS API Demo app in Objective-C or Swift.
Prerequisites
Complete the Get Started guide.
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. 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.
Be sure to remove the code that sets these test device IDs before you release your app.
Gender
If your app already knows user's gender, it can be supplied in the ad request for targeting purposes. This information is also forwarded to ad network mediation adapters.
Objective-C
GADRequest *request = [GADRequest request];
request.gender = kGADGenderMale;
Swift
let request = GADRequest()
request.gender = .male
See the GADGender enum in GADRequest.h for a full list of gender options.
Birthday
If your app already knows user's birthday, it can be supplied in the ad request for targeting purposes. This information is also forwarded to ad network mediation adapters.
Objective-C
GADRequest *request = [GADRequest request];
NSDateComponents *components = [[NSDateComponents alloc] init];
components.month = 3;
components.day = 13;
components.year = 1976;
request.birthday = [[NSCalendar currentCalendar] dateFromComponents:components];
Swift
let request = DFPRequest()
var components = DateComponents()
components.month = 3
components.day = 13
components.year = 1976
request.birthday = Calendar.current.date(from: components)
Child-directed setting
For purposes of the Children's Online Privacy Protection Act
(COPPA),
there is a setting called tagForChildDirectedTreatment.
As an app developer, you can indicate whether you want Google to treat your content as child-directed when you make an ad request. When 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. The setting options are as follows:
- Set
tagForChildDirectedTreatmenttoYESto indicates that you want your content treated as child-directed for purposes of COPPA. - Set
tagForChildDirectedTreatmenttoNOto indicate that you don't want your content treated as child-directed for purposes of COPPA. - Do not set
tagForChildDirectedTreatmentif you do not wish to indicate 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
When requesting an ad, apps may pass the URL of the content they are serving. This enables keyword targeting to match the ad with the content.
For example, if your app serves blog articles and is requesting an ad while showing content from the article http://googleadsdeveloper.blogspot.com/2016/03/rewarded-video-support-for-admob.html, then you can pass this URL to target relevant keywords:
Objective-C
GADRequest *request = [GADRequest request];
request.contentURL = @"http://googleadsdeveloper.blogspot.com/2016/03/rewarded-video-support-for-admob.html";
Swift
let request = GADRequest()
request.contentURL = "http://googleadsdeveloper.blogspot.com/2016/03/rewarded-video-support-for-admob.html"
Load 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.gender = kGADGenderMale;
NSDateComponents *components = [[NSDateComponents alloc] init];
components.month = 3;
components.day = 13;
components.year = 1976;
request.birthday = [[NSCalendar currentCalendar] dateFromComponents:components];
[request tagForChildDirectedTreatment:YES];
request.contentURL = @"http://googleadsdeveloper.blogspot.com/2016/03/rewarded-video-support-for-admob.html";
[self.adView loadRequest:request];
Swift
let request = GADRequest()
request.gender = .male
var components = DateComponents()
components.month = 3
components.day = 13
components.year = 1976
request.birthday = Calendar.current.date(from: components)
request.tag(forChildDirectedTreatment: true)
request.contentURL = "http://googleadsdeveloper.blogspot.com/2016/03/rewarded-video-support-for-admob.html"
adView.loadRequest(request)
See the AdMob Ad Targeting example for an implementation of ad targeting in the iOS API Demo app.
FAQ
- Can I release my app with request.testDevices?
- Yes. Test ads are only shown on specific devices that you specify, so all of your users will still 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
loadRequestonGADBannerViewwith a newGADRequestobject. - How do I pass extra targeting parameters to mediation networks?
- See Mediation to find out how to send targeting to mediation networks.

