מיקוד

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 Swift or Objective-C.

Download API Demo

Prerequisites

Complete the Get Started guide.

GADRequestConfiguration

GADRequestConfiguration is an object that collects targeting information to be applied globally through the GADMobileAds shared instance. It can be accessed with the following code:

Swift

let requestConfiguration = GADMobileAds.sharedInstance().requestConfiguration

Objective-C

GADRequestConfiguration requestConfiguration = GADMobileAds.sharedInstance.requestConfiguration;

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, Google takes steps to disable IBA and remarketing ads on that ad request. The setting options are as follows:

  • Set tagForChildDirectedTreatment to true to indicate that you want your content treated as child-directed for purposes of COPPA. This prevents the transmission of the Advertising Identifier, IDFA.
  • Set tagForChildDirectedTreatment to false to indicate that you don't want your content treated as child-directed for purposes of COPPA.
  • Don't set tagForChildDirectedTreatment if you don't want to indicate how you would like your content treated with respect to COPPA.

The following example indicates that you want your content to be treated as child-directed for purposes of COPPA:

Swift

GADMobileAds.sharedInstance().requestConfiguration.tagForChildDirectedTreatment = true

Objective-C

GADMobileAds.sharedInstance.requestConfiguration.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.

You can mark your ad requests to receive treatment for users in the European Economic Area (EEA) under the age of consent. This feature is designed to help facilitate compliance with the General Data Protection Regulation (GDPR). Note that you may have other legal obligations under GDPR. Review European Union guidance and consult with your own legal counsel. Note that Google's tools are designed to facilitate compliance and do not relieve any particular publisher of its obligations under the law. Learn more about how the GDPR affects publishers.

When using this feature, a Tag For Users under the Age of Consent in Europe (TFUA) parameter will be included in all future ad requests. This parameter disables personalized advertising, including remarketing, for that specific ad request. It also disables requests to third-party ad vendors, such as ad measurement pixels and third-party ad servers.

The setting can be used with all versions of the Google Mobile Ads SDK by setting the tagForUnderAgeOfConsent property on the GADMobileAds.requestConfiguration object and passing in true.

  • Set tagForUnderAgeOfConsent to true to indicate that you want ad requests to be handled in a manner suitable for users under the age of consent. This also prevents the transmission of the Advertising Identifier, IDFA.
  • Not setting tagForUnderAgeOfConsent indicates that you don't want ad requests to be handled in a manner suitable for users under the age of consent.

The following example indicates that you want TFUA included in your ad request:

Swift

GADMobileAds.sharedInstance().requestConfiguration.tagForUnderAgeOfConsent = true

Objective-C

GADMobileAds.sharedInstance.requestConfiguration.tagForUnderAgeOfConsent = @YES;

The tags to enable the child-directed setting and tagForUnderAgeOfConsent shouldn't both simultaneously be set to true. If they are, the child-directed setting takes precedence.

Ad content filtering

Apps can set a maximum ad content rating for all ad requests using the maxAdContentRating property of GADRequestConfiguration. This setting applies to all future ad requests for the remainder of the session. The possible values for this property are based on digital content label classifications, and should be one of the following constants:

  • GADMaxAdContentRatingGeneral
  • GADMaxAdContentRatingParentalGuidance
  • GADMaxAdContentRatingTeen
  • GADMaxAdContentRatingMatureAudience

The following code configures all ad requests to specify that ad content returned should correspond to a Digital Content Label designation no higher than GADMaxAdContentRatingGeneral.

Swift

GADMobileAds.sharedInstance().requestConfiguration.maxAdContentRating =
    GADMaxAdContentRatingGeneral

Objective-C

GADMobileAds.sharedInstance.requestConfiguration.maxAdContentRating =
    GADMaxAdContentRatingGeneral;

Publisher Privacy Treatment (Beta)

The Publisher Privacy Treatment (PPT) API is an optional tool that lets apps indicate whether to turn off ads personalization for all ad requests using the publisherPrivacyPersonalizationState property of GADRequestConfiguration. When using this feature, a publisher privacy treatment (PPT) parameter is included in all future ad requests for the remainder of the session.

By default, ad requests to Google are served personalized ads. The following code turns off ads personalization for all ad requests:

Swift

GADMobileAds.sharedInstance().requestConfiguration.publisherPrivacyPersonalizationState =
    .disabled

Objective-C

GADMobileAds.sharedInstance.requestConfiguration.publisherPrivacyPersonalizationState =
    GADPublisherPrivacyPersonalizationStateDisabled;

GAMRequest

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

Content URL

When requesting an ad, apps can 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 is requesting an ad while showing content from https://www.example.com, you can pass this URL to target relevant keywords:

Swift

let request = GAMRequest()
request.contentURL = "https://www.example.com"

Objective-C

GAMRequest *request = [GAMRequest request];
request.contentURL = @"https://www.example.com";

Custom targeting

Once you've configured key-value pairs in the Ad Manager UI, set custom targeting with the key values in an ad request. Line items that target those key values are then eligible to serve for that ad request. To target multiple values for one key, enter values as a comma-separated string.

Swift

let request = GAMRequest()
request.customTargeting = ["gender" : "male", "section" : "health,fitness"];

Objective-C

GAMRequest *request = [GAMRequest request];
request.customTargeting = @{@"gender" : @"male", @"section" : @"health,fitness"};

Brand safety (Beta)

Apps that display dynamic content intended for varying audiences can provide a short list of URLs through the neighboringContentURLs property. Neighboring content URLs differ from the contentURL property in that they are only used for brand safety.

Suppose your app displays content from four URLs in a feed that also contains ads. You can request ads which have a similar content rating to those URLs by passing them like so:

Swift

let request = GAMRequest()
request.neighboringContentURLs =
    ["https://www.example1.com", "https://www.example2.com",
    "https://www.example3.com", "https://www.example4.com"]

Objective-C

GAMRequest *request = [GAMRequest request];
request.neighboringContentURLs =
    @[@"https://www.example1.com", @"https://www.example2.com",
    @"https://www.example3.com", @"https://www.example4.com"];

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

Swift

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

Objective-C

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

See the Ad Manager PPID example for an implementation of publisher provided identifiers (PPID) in the iOS API Demo app:

Swift Objective-C

Publisher provided signals

You can send audience and contextual data as publisher provided signals (PPS) in ad requests. With PPS, you can use your user data to improve programmatic monetization by communicating your audience characteristics to bidders in all transaction types, using standard taxonomies, without the need to share user identifiers. Your audience characteristics can include behavioral and interest-based data ( IAB Audience Taxonomy 1.1) and contextual data ( IAB Content Taxonomy 2.2).

Swift

let extras = GADExtras()
extras.additionalParameters = [
    // Set the demographic to an audience with an "Age Range" of 30-34 and an
    // interest in mergers and acquisitions.
    "IAB_AUDIENCE_1_1": [6, 284],
    // Set the content to sedan, station wagon and SUV automotive values.
    "IAB_CONTENT_2_2": [4, 5, 6]
]

let request = GAMRequest()
request.register(extras)

Objective-C

GADExtras *extras = [[GADExtras alloc] init];
extras.additionalParameters = @{
    // Set the demographic to an audience with an "Age Range" of 30-34 and an
    // interest in mergers and acquisitions.
    @"IAB_AUDIENCE_1_1":@[@6, @284],
    // Set the content to sedan, station wagon and SUV automotive values.
    @"IAB_CONTENT_2_2":@[@4,@5,@6]
};

GAMRequest *request = [GAMRequest request];
[request registerAdNetworkExtras:extras];

FAQ

What targeting gets used when an ad automatically refreshes?
On ad refresh, the previously specified GAMRequest object is used for targeting again. To set new targeting, explicitly call loadRequest on GAMBannerView with a new GAMRequest object.
How do I pass extra targeting parameters to mediation networks?
See Mediation to find out how to send targeting to mediation networks.