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 DFP 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 DFP 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 DFP Category Exclusions example for an implementation of category exclusions in the Android API Demo app.


If a user has granted your app location permissions, DFP 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.

Designed for Families setting

If you have opted your app in to Google Play's Designed for Families program and you show ads in your app, you need to ensure those ads comply with the Designed for Families program requirements and ad policies.

Ad requests can be tagged as designed for families by setting the is_designed_for_families parameter to true in the extras:

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

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

This setting is separate from the Children's Online Privacy Protection Act (COPPA) "tag for child directed treatment" setting. For COPPA-related compliance, see the child-directed setting.

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.

    PublisherAdRequest request = new PublisherAdRequest.Builder() .tagForChildDirectedTreatment(true) .build();

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.

It may take some time for this designation to take effect in applicable Google services.

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()
    .setBirthday(new GregorianCalendar(1985, 1, 1).getTime())

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 DFP 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()

Send feedback about...

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