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

To see ad targeting in action, download the Android API Demo app.

Download API Demo



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

Test ads

During development, it is recommended to utilize test ads to avoid generating false impressions. Additionally, you can always count on a test ad being available.

Set up test ads by passing your hashed Device ID to PublisherAdRequest.Builder.addTestDevice:

PublisherAdRequest adRequest = new PublisherAdRequest.Builder()
    .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)        // All emulators
    .addTestDevice("AC98C820A50B4AD8A2106EDE96FB87D4")  // My Galaxy Nexus test phone

Check logcat output for a device's MD5-hashed ID. Remember to add a test device ID for each device for which you want to request test ads.

Custom targeting

You can pass custom key-value pairs to target Google Ad Manager campaigns (line items) through PublisherAdRequest.Builder.addCustomTargeting:

// Example: Pass custom targeting "age=25".
PublisherAdRequest newRequest = new PublisherAdRequest.Builder()
    .addCustomTargeting("age", "25")

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"))

See 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 PublisherAdRequest.Builder:

// Example: Exclude "automobile" and "boat" categories.
PublisherAdRequest newRequest = new PublisherAdRequest.Builder()

See the Ad Manager Category Exclusions example for an implementation of category exclusions in the Android API Demo app.


If a user has granted your app location permissions, Ad Manager automatically passes this location data 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. You can specify location-targeting information in the PublisherAdRequest as follows:

PublisherAdRequest request = new PublisherAdRequest.Builder()

The user's location should be obtained by a suitable method.

Out of respect for user privacy, Google asks that you specify location only if that information is already being 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. The setting can be used with all versions of the Google Play services SDK, via AdRequest.Builder.tagForChildDirectedTreatment(boolean):

  • Setting tagForChildDirectedTreatment to true indicates that you want your content treated as child-directed for purposes of COPPA.
  • Setting tagForChildDirectedTreatment to false 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.

Here's how to set tagForChildDirectedTreatment

PublisherAdRequest request = new PublisherAdRequest.Builder()

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. Please review the European Union’s guidance and consult with your own legal counsel. Please remember 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 the ad request. 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 using the tag_for_under_age_of_consent network extra.

  • Set tag_for_under_age_of_consent to true to indicate that you want the ad request to be handled in a manner suitable for users under the age of consent.
  • Not setting tag_for_under_age_of_consent indicates that you don't want the ad request 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:


Bundle extras = new Bundle();
extras.putBoolean("tag_for_under_age_of_consent", true);

PublisherAdRequest request = new PublisherAdRequest.Builder()
        .addNetworkExtrasBundle(AdMobAdapter.class, extras)


val extras = Bundle()

extras.putBoolean("tag_for_under_age_of_consent", true)

val request = PublisherAdRequest.Builder()
        .addNetworkExtrasBundle(, extras)

The tags to enable the Child-directed setting and tag_for_under_age_of_consent should not both simultaneously be set to true. If they are, the child-directed setting takes precedence.

Request agent

We recommend that third-party libraries that reference the Mobile Ads SDK call setRequestAgent to denote the platform from which the ad request originated. For example, call this method with "CoolAds" if a third-party ad network called "CoolAds" mediates requests to the Mobile Ads SDK:

PublisherAdRequest newRequest = new PublisherAdRequest.Builder()

Loading an ad with targeting

Once your request targeting information is set, call loadAd on the PublisherAdView with your PublisherAdRequest instance.

PublisherAdRequest adRequest = new PublisherAdRequest.Builder()

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:

PublisherAdRequest adRequest = new PublisherAdRequest.Builder()

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

Content URL

To provide a URL for content related to your app, you can call PublisherAdRequest.Builder.setContentUrl when building a PublisherAdRequest:

PublisherAdRequest requestWithContent = new PublisherAdRequest.Builder()

Enviar comentarios sobre...

Mobile Ads SDK for Android
Mobile Ads SDK for Android
Si necesitas ayuda, visita nuestra página de asistencia.