Targeting

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.

Download API Demo

Prerequisites

DFPRequest

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

Custom targeting

To set page level custom targeting, set the CustomTargeting property on a DFPRequest with a dictionary of custom targeting information. A key can be assigned multiple values, as in section here:

Swift

let request = DFPRequest()
request.customTargeting = ["gender": "male", "section": ["sports", "finance"]]

Objective-C

DFPRequest *request = [DFPRequest request];
request.customTargeting = @{@"gender" : @"male", @"section" : @[ @"sports", @"finance"]};

See the DFP Custom Targeting example for an implementation of custom targeting in the iOS API Demo app.

Objective-C Swift

Category exclusions

To set page-level ad category exclusions, set the categoryExclusions property on a DFPRequest with an array of exclusion labels.

Swift

let request = DFPRequest()
request.categoryExclusions = ["cars", "pets"]

Objective-C

DFPRequest *request = [DFPRequest request];
request.categoryExclusions = @[@"cars", @"pets"];

See the DFP Category Exclusions example for an implementation of category exclusions in the iOS API Demo app.

Objective-C Swift

Gender

When using backfill or an SDK mediation creative, gender can be supplied in the ad request for targeting purposes. This information is also forwarded to ad network mediation adapters.

Swift

let request = DFPRequest()
request.gender = .male

Objective-C

DFPRequest *request = [DFPRequest request];
request.gender = kGADGenderMale;

See the GADGender enum in GADRequest.h for a full list of gender options.

Birthday

When using backfill or an SDK mediation creative, birthday can be supplied in the ad request for targeting purposes. This information is also forwarded to ad network mediation adapters.

Swift

let request = DFPRequest()
var components = DateComponents()
components.month = 3
components.day = 13
components.year = 1976
request.birthday = Calendar.current.date(from: components)

Objective-C

DFPRequest *request = [DFPRequest request];
NSDateComponents *components = [[NSDateComponents alloc] init];
components.month = 3;
components.day = 13;
components.year = 1976;
request.birthday = [[NSCalendar currentCalendar] dateFromComponents:components];

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 will take steps to disable IBA and remarketing ads on that ad request.

  • If you set tagForChildDirectedTreatment to YES or 'true', you will indicate that your content should be treated as child-directed for purposes of COPPA.
  • If you set tagForChildDirectedTreatment to NO or 'false', you will indicate that your content should not be treated as child-directed for purposes of COPPA.
  • If you do not set tagForChildDirectedTreatment, ad requests will include no indication of how you would like your content treated with respect to COPPA.

Swift

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

Objective-C

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

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 application 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:

Swift

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

Objective-C

DFPRequest *request = [DFPRequest request];
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 DFPBannerView with your DFPRequest instance.

Swift

let request = DFPRequest()
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/2013/10/upgrade-to-new-google-admob.html"
adView.load(request)

Objective-C

DFPRequest *request = [DFPRequest 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/2013/10/upgrade-to-new-google-admob.html";
[self.adView loadRequest:request];

Publisher provided identifiers

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.

Setting the PPID is done through DFPRequest:

Swift

let request = DFPRequest()
request.publisherProvidedID = "AB123456789"

Objective-C

DFPRequest *request = [DFPRequest request];
request.publisherProvidedID = @"AB123456789";

See the DFP PPID example for an implementation of publisher provided identifiers (PPID) 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 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 DFPRequest object is used for targeting again. To set new targeting, explicitly call loadRequest on DFPBannerView with a new DFPRequest object.
How do I pass extra targeting parameters to mediation networks?
Specify additional request parameters describes how to send targeting to mediation networks.

Send feedback about...

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