Search Ads for Mobile Apps

Read the updated version.

This guide is provided for Apps developers who want to enhance monetization on their apps' search results pages. With this service, apps can target ads based on users' search queries, access Google's AdWords inventory, and help users find what they're looking for.

The implementation is very similar to that of the existing AdMob ads. The main difference is that a search term is also supplied to the SDK when an ad call is placed.

Search ads does not support the tagForChildDirectedTreatment: method. Requests will fail if tagForChildDirectedTreatment is set.

These steps provide the setup for the basic service:

  1. Incorporate the SDK into your app making sure to add all the needed declarations in AndroidManifest.xml.

  2. Create a new AdView specifying an adequate ad size and your AdSense Publisher ID.

    Note: Attempting to request search ads with your AdMob ID will not work.

    SearchAdView adView = new SearchAdView(this);
    adView.setAdUnitId("MY_ADSENSE_ID");
    adView.setAdSize(new AdSize(320, 60));
    
  3. Create a SearchAdRequest object and set your query in it:

    SearchAdRequest request = new SearchAdRequest.Builder()
      .setQuery("flower")
      .build();
    
  4. Finally, request adView to load the ad:

    adView.loadAd(request);
    

Ad Controls

You have control over the appearance of the ad including:

  • Background color/gradient
  • Border color/type/thickness
  • URL text colors (header/description/visible)
  • Ad font
  • Ad header text (from which description and visible URL text sizes are determined)

When setting the text size, the size of the ad container should be taken into account for a proper fit.

The above controls can be found in com.google.android.gms.ads.search.SearchAdRequest.

com.google.android.gms.ads.search.SearchAdRequest

setAnchorTextColor
Sets the color of the ad URL. Transparency is not supported. rgb(int, int, int) can be used to specify this color.
Parameters:
anchorTextColor - the color to be set.
setBackgroundColor
Sets the background color of the ad. Calling this method will override any previous calls to setBackgroundColor(int) or setBackgroundGradient(int, int). Transparency is not supported. rgb(int, int, int) can be used to specify this color.
Parameters:
backgroundColor - the solid background color of the ad.
setBackgroundGradient
Sets a gradient for the ad background. Calling this method will override any previous calls to setBackgroundColor(int) or setBackgroundGradient(int, int). Transparency is not supported. rgb(int, int, int) can be used to specify these colors.
Parameters:
top - The color of the gradient at the top of the ad.
bottom - The color of the gradient at the bottom of the ad.
setBorderColor
Sets the border color of the ad container. Transparency is not supported. rgb(int, int, int) can be used to specify this color. This setting is ignored if setBorderType(int) is set to SearchAdRequest.BORDER_TYPE_NONE.
Parameters:
borderColor - the color to set as the border.
setBorderThickness
Sets the thickness of the border in pixels around the ad container. This setting is ignored if setBorderType(int) is set to SearchAdRequest.BORDER_TYPE_NONE.
Parameters:
borderThickness - the thickness of the border.
setBorderType
Sets the type of border around the ad container.
Parameters:
borderType - the type of the border.
setCustomChannels
Sets custom channels for the ad request. Custom channels allow publishers to track the performance of specific groups of ads. These custom channels need to be created on the AdSense website. Reports can then be created based on the channels.
Parameters:
channelIds - list of channel IDs separated by '+'.
setDescriptionTextColor
Sets the color of the ad description. Transparency is not supported. rgb(int, int, int) can be used to specify this color.
Parameters:
descriptionTextColor - the color to be set.
setFontFace
Sets the font to render the ad. The same font is used in the header, description, and anchor. Fonts are specified using the same value that would be used in CSS (e.g., "arial").
Parameters:
fontFace - name of the font to be used to render the ad.
setHeaderTextColor
Sets the text color of the ad header. Transparency is not supported. rgb(int, int, int) can be used to specify this color.
Parameters:
headerTextColor - the header text color to set.
setHeaderTextSize
Sets the font size of the header text in pixels. The font sizes for description and anchor are determined from the header size.
Parameters:
headerTextSize - the header text size to set.