This guide explains how to provide targeting information to the Google Mobile Ads SDK.
For a working example, download the Android API Demo app.Prerequisite
- Complete the Get started guide.
RequestConfiguration
RequestConfiguration
collects targeting information applied globally to every ad request. For
available targeting tags, refer to the
RequestConfiguration.Builder
documentation.
To update the request configuration, obtain a builder from the existing configuration, perform any desired updates, and set it as follows:
Kotlin
val requestConfiguration = MobileAds.getRequestConfiguration()
.toBuilder()
.build()
MobileAds.setRequestConfiguration(requestConfiguration)
Java
RequestConfiguration requestConfiguration = MobileAds.getRequestConfiguration()
.toBuilder()
.build();
MobileAds.setRequestConfiguration(requestConfiguration);
Child-directed setting
For purposes of the Children's Online Privacy Protection Act (COPPA), there is a setting called "tag for child-directed treatment". 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.
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.
You can apply the child-directed setting through
setTagForChildDirectedTreatment()
:
Call
setTagForChildDirectedTreatment
withTAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE
to indicate that you want your content treated as child-directed for purposes of COPPA. This prevents the transmission of the Android advertising identifier (AAID).Call
setTagForChildDirectedTreatment
withTAG_FOR_CHILD_DIRECTED_TREATMENT_FALSE
to indicate that you don't want your content treated as child-directed for purposes of COPPA.Call
setTagForChildDirectedTreatment
withTAG_FOR_CHILD_DIRECTED_TREATMENT_UNSPECIFIED
if you don't want to indicate how you would like your content treated with respect to COPPA in ad requests.
The following example indicates that you want your content treated as child-directed for purposes of COPPA:
Kotlin
val requestConfiguration = MobileAds.getRequestConfiguration()
.toBuilder()
.setTagForChildDirectedTreatment(RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE)
.build()
MobileAds.setRequestConfiguration(requestConfiguration)
Java
RequestConfiguration requestConfiguration = MobileAds.getRequestConfiguration()
.toBuilder()
.setTagForChildDirectedTreatment(RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE)
.build();
MobileAds.setRequestConfiguration(requestConfiguration);
Users under the age of consent
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 is included in the ad request. This parameter disables personalized advertising, including remarketing, for all ad requests. It also disables requests to third-party ad vendors, such as ad measurement pixels and third-party ad servers.
Like child-directed settings, there is a method in
RequestConfiguration.Builder
for setting the TFUA parameter:
setTagForUnderAgeOfConsent()
,
with the following options.
Call
setTagForUnderAgeOfConsent()
withTAG_FOR_UNDER_AGE_OF_CONSENT_TRUE
to indicate that you want the ad request to receive treatment for users in the European Economic Area (EEA) under the age of consent. This also prevents the transmission of the Android advertising identifier (AAID).Call
setTagForUnderAgeOfConsent()
withTAG_FOR_UNDER_AGE_OF_CONSENT_FALSE
to indicate that you want the ad request to not receive treatment for users in the European Economic Area (EEA) under the age of consent.Call
setTagForUnderAgeOfConsent()
withTAG_FOR_UNDER_AGE_OF_CONSENT_UNSPECIFIED
to indicate that you have not specified whether the ad request should receive treatment for users in the European Economic Area (EEA) under the age of consent.
The following example indicates that you want TFUA included in your ad requests:
Kotlin
val requestConfiguration = MobileAds.getRequestConfiguration()
.toBuilder()
.setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_TRUE)
.build()
MobileAds.setRequestConfiguration(requestConfiguration)
Java
RequestConfiguration requestConfiguration = MobileAds.getRequestConfiguration()
.toBuilder()
.setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_TRUE)
.build();
MobileAds.setRequestConfiguration(requestConfiguration);
The tags to enable the Child-directed setting
and setTagForUnderAgeOfConsent()
should not both simultaneously be set to true
.
If they are, the child-directed setting takes precedence.
Ad content filtering
To comply with Google Play's Inappropriate Ads Policy that includes associated offers within an ad, all ads and their associated offers shown within your app must be appropriate for the content rating of your app, even if the content by itself is otherwise compliant with Google Play's policies.
Tools like maximum ad content rating can help you have more control over the content of the ads shown to your users. You can set a maximum content rating to help compliance with platform policies.
Apps can set a maximum ad content rating for their ad requests using the
setMaxAdContentRating
method. AdMob ads returned when this is configured have a content rating at or
below that level. The possible values for this network extra are based on
digital content label classifications, and must be one of the following
strings:
MAX_AD_CONTENT_RATING_G
MAX_AD_CONTENT_RATING_PG
MAX_AD_CONTENT_RATING_T
MAX_AD_CONTENT_RATING_MA
The following code configures an RequestConfiguration
object to specify that
ad content returned should correspond to a digital content label designation no
higher than G
:
Kotlin
val requestConfiguration = MobileAds.getRequestConfiguration()
.toBuilder()
.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_G)
.build()
MobileAds.setRequestConfiguration(requestConfiguration)
Java
RequestConfiguration requestConfiguration = MobileAds.getRequestConfiguration()
.toBuilder()
.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_G)
.build();
MobileAds.setRequestConfiguration(requestConfiguration);
Learn more about:
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
setPublisherPrivacyPersonalizationState()
method.
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:
Kotlin
val requestConfiguration = MobileAds.getRequestConfiguration()
.toBuilder()
.setPublisherPrivacyPersonalizationState(PublisherPrivacyPersonalizationState.DISABLED)
.build()
MobileAds.setRequestConfiguration(requestConfiguration)
Java
RequestConfiguration requestConfiguration = MobileAds.getRequestConfiguration()
.toBuilder()
.setPublisherPrivacyPersonalizationState(PublisherPrivacyPersonalizationState.DISABLED)
.build();
MobileAds.setRequestConfiguration(requestConfiguration);
Ad request
The AdManagerAdRequest
object collects targeting
information to be sent with an ad request.
Custom targeting
You can pass custom key-value pairs to target Google Ad Manager campaigns (line
items) through AdManagerAdRequest.Builder.addCustomTargeting()
:
Kotlin
// Example: Pass custom targeting "age=25".
val newRequest = AdManagerAdRequest.Builder()
.addCustomTargeting("age", "25")
.build()
Java
// Example: Pass custom targeting "age=25".
AdManagerAdRequest newRequest = new AdManagerAdRequest.Builder()
.addCustomTargeting("age", "25")
.build();
You can pass multiple values for a key as a list of strings. For example, to target individuals in their mid-twenties rather than just 25 year olds.
.addCustomTargeting("age", Arrays.asList("24", "25", "26"))
Check out the Ad Manager Custom Targeting example for an implementation of custom targeting in the Android API Demo app.
Category exclusions
You can add a slot-level category exclusion level to a request by using the
addCategoryExclusion()
method provided by AdManagerAdRequest.Builder
:
Kotlin
// Example: Exclude "automobile" and "boat" categories.
val newRequest = AdManagerAdRequest.Builder()
.addCategoryExclusion("automobile")
.addCategoryExclusion("boat")
.build()
Java
// Example: Exclude "automobile" and "boat" categories.
AdManagerAdRequest newRequest = new AdManagerAdRequest.Builder()
.addCategoryExclusion("automobile")
.addCategoryExclusion("boat")
.build();
Check out the Ad Manager Category Exclusions example for an implementation of category exclusions in the Android API Demo app.
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.
Here's an example of setting the PPID:
Kotlin
val adRequest = AdManagerAdRequest.Builder()
.setPublisherProvidedId("AB123456789")
.build()
Java
AdManagerAdRequest adRequest = new AdManagerAdRequest.Builder()
.setPublisherProvidedId("AB123456789")
.build();
Check out the Ad Manager PPID example for an implementation of publisher provided identifiers (PPID) in the Android API Demo app.
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).
Kotlin
val extras = Bundle()
// Set the demographic to an audience with an "Age Range" of 30-34 and an
// interest in mergers and acquisitions.
extras.putIntegerArrayList("IAB_AUDIENCE_1_1", arrayListOf(6,284))
// Set the content to sedan, station wagon and SUV automotive values.
extras.putIntegerArrayList("IAB_CONTENT_2_2", arrayListOf(4,5,6))
val request = AdRequest.Builder()
.addNetworkExtrasBundle(AdMobAdapter::class.java, extras)
.build()
Java
Bundle extras = new Bundle();
// Set the demographic to an audience with an "Age Range" of 30-34 and an
// interest in mergers and acquisitions.
extras.putIntegerArrayList("IAB_AUDIENCE_1_1", arrayListOf(6,284));
// Set the content to sedan, station wagon and SUV automotive values.
extras.putIntegerArrayList("IAB_CONTENT_2_2", arrayListOf(4,5,6));
AdManagerAdRequest request = new AdManagerAdRequest.Builder()
.addNetworkExtrasBundle(AdMobAdapter.class, extras)
.build()
Content URL
To provide a content URL for content-targeted ads and brand safety, you can call
setContentUrl()
when building an AdManagerAdRequest
:
Kotlin
val builder = AdManagerAdRequest.Builder()
builder.setContentUrl("https://www.example.com")
val request = builder.build()
Java
AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
builder.setContentUrl("https://www.example.com");
AdManagerAdRequest request = builder.build();
Brand safety (Beta)
Applications that display dynamic content intended for varying audiences are
able to provide a short list of URLs using the
setNeighboringContentUrls()
method when building an AdManagerAdRequest
:
Kotlin
val urls = mutableListOf("https://www.mycontenturl1.com", "https://www.mycontenturl2.com",
"https://www.mycontenturl3.com", "https://www.mycontenturl4.com")
val requestWithContent = AdManagerAdRequest.Builder()
.setNeighboringContentUrls(urls)
.build()
Java
ArrayList<String> urls = new ArrayList<String>();
urls.add("https://www.mycontenturl1.com");
urls.add("https://www.mycontenturl2.com");
urls.add("https://www.mycontenturl3.com");
urls.add("https://www.mycontenturl4.com");
AdManagerAdRequest requestWithContent = new AdManagerAdRequest.Builder()
.setNeighboringContentUrls(urls)
.build();
.setNeighboringContentUrls()
differs from .setContentUrl()
in that it's only
used for brand safety.