Targeting

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

Prerequisite

AdRequest

The AdRequest 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 AdRequest.Builder.addTestDevice():

AdRequest request = new AdRequest.Builder()
        .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)        // All emulators
        .addTestDevice("AC98C820A50B4AD8A2106EDE96FB87D4")  // An example device ID
        .build();

Remember to add a test device ID for each device that should request test ads. Device IDs are written to the system log by the Mobile Ads SDK, so you can find your device's ID by running your app and checking logcat.

The Mobile Ads SDK uses the tag "Ads" when writing to logcat. In Android Studio's logcat viewer, you can filter for that tag when you View the system log. This makes it easier to find your device's ID.

Be sure to remove the code that sets these test device IDs before you release your app.

Gender

If your app already knows a user's gender, it can provide that information in the ad request for targeting purposes. The information is also forwarded to ad network mediation adapters if mediation is enabled.

AdRequest request = new AdRequest.Builder()
        .setGender(AdRequest.GENDER_FEMALE)
        .build();

Birthday

If your app already knows a user's birthday, it can provide that information in the ad request for targeting purposes. This information is also forwarded to ad network mediation adapters if mediation is enabled.

AdRequest request = new AdRequest.Builder()
        .setBirthday(new GregorianCalendar(1985, 1, 1).getTime())
        .build();

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

AdRequest request = new AdRequest.Builder()
        .addNetworkExtrasBundle(AdMobAdapter.class, extras)
        .build();

For more information on implementing this setting, check out the Designed for Families help center article.

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

  • Set tagForChildDirectedTreatment to true to indicate that you want your content treated as child-directed for purposes of COPPA.
  • Set tagForChildDirectedTreatment to false to indicate that you don't want your content treated as child-directed for purposes of COPPA.
  • Do not set tagForChildDirectedTreatment if you do not wish 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:

AdRequest request = new AdRequest.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.

Load an ad with targeting

Once your request targeting information is set, call loadAd() on the AdView with your AdRequest instance.

AdRequest request = new AdRequest.Builder()
        .setGender(AdRequest.GENDER_FEMALE)
        .setBirthday(new GregorianCalendar(1985, 1, 1).getTime())
        .tagForChildDirectedTreatment(true)
        .build();
adView.loadAd(request);

See the AdMob Ad Targeting example for an implementation of ad targeting in the Android API Demo app.

Send feedback about...

AdMob for Android
AdMob for Android
Need help? Visit our support page.