Google Mobile Ads SDK

Search Ads for Mobile Apps

This feature is available by invitation only.

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 for Mobile Apps is available for iOS and Android.

Android (Google Play)

These steps provide the setup for the basic service:

  1. Follow all the steps in Getting Started to incorporate the SDK into your app. This includes adding the 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 tocreated 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.
Android (6.4.1 and earlier SDKs)

These steps provide the setup for the basic service:

  1. Follow all the steps in Getting Started to incorporate the SDK into your app. This includes adding the 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.

    AdView adView = new AdView(this, new AdSize(320, 60), MY_ADSENSE_ID);
  3. Create a SearchAdRequest object and set your query in it:
    SearchAdRequest request = new SearchAdRequest();
    request.setQuery("flower");
  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.ads.searchads.SearchAdRequest.

com.google.ads.searchads.SearchAdRequest

setAnchorTextColor
Sets the color of the ad URL. The color must be a solid RGB color (alpha = 0xFF). The method Color.rgb(int, int, int) can be used to specify this color.
Parameters:
descriptionTextColor - the color to be set.
setBackgroundColor
Sets the solid color as the background of the ad. The ad background can either be a solid color or a gradient. If both of them are set, only the latter takes in effect. The color's alpha must be 0xFF.
Parameters:
backgroundColor - the solid background color of the ad.
setBackgroundGradient
Sets a gradient to render the ad background. Only a solid color, or a linear gradient can be set as the background. If both are set, only the latter will be considered. Each of the colors, defining the gradient must be solid colors with alpha = 0xFF.
Parameters:
from - The color to start the gradient.
to - The color where the gradient ends.
setBorderColor
The border color to render the ad container. This color must be a solid color (alpha = 0xFF). Color.rgb(int, int, int) can be used to specify this color. This parameter is ignored if border type is set to SearchAdRequest.BorderType.NONE.
Parameters:
borderColor - the color to set as the border.
setBorderThickness
Sets the thickness of the border around the ad container. This must be specified in pixels. This parameter is ignored if border type is set to SearchAdRequest.BorderType.NONE.
Parameters:
borderThickness - the thickness of the border.
setBorderType
Sets the border type to render the ad.
Parameters:
borderType - the type of the border.
setCustomChannels
Add channel information to the ad request.
Parameters:
channelIds - list of channel IDs separated by '+'.
setDescriptionTextColor
Sets the color of the ad description. The color must be a solid RGB color (alpha = 0xFF). The method Color.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.
Parameters:
fontFace - name of the font to be used to render the ad.
setHeaderTextColor
Sets the ad header text color. The color must be a solid RGB color (alpha = 0xFF). The method Color.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 URL are determined from the header size.
Parameters:
headerTextSize - the header text size to set.
iOS

These steps provide the setup for the basic service:

  1. Make sure you have downloaded the latest SDK, which contains in its "Add-ons" folder all the necessary header files.

  2. Follow the steps in Banner Ads I to create a GADSearchBannerView in the same way you would create a GADBannerView, except use your AdSense Publisher ID in place of your AdMob ID.

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

    GADSearchBannerView *banner = [[GADSearchBannerView alloc]
                                  initWithAdSize:GADAdSizeFromCGSize(CGSizeMake(320,60))
                                  origin:CGPointMake(0,0)];
  3. Create a new GADSearchRequest object and set the query:

    GADSearchRequest *adRequest = [[GADSearchRequest alloc] init];
                                  [adRequest setQuery:@"flower"];
  4. Call GADBannerView loadRequest:GADRequest to show the ad:

    [banner loadRequest:[adRequest request]];

Ad Controls

You can manipulate the ad's appearance with these controls:

  • Background color/gradient
  • Ad header/description/visible URL color
  • Border type/color/thickness
  • Ad font
  • Font size of the ad header—this determines the description and visible URL sizes. Verify that your container is big enough to show the ad.

More details about controls can be found in the class GADSearchRequest. These controls must be set before requesting ads.

GADSearchRequest

Properties

query
The query for requesting search ads. If this is not set, the user won't get any ads.
backgroundColor
The background color for the ad. This should be set using the setBackgroundSolid: method.
gradientFrom
The color to start the background gradient. This should be set using the setBackgroundGradientFrom:toColor: method.
gradientTo
The color to end the background gradient. This should be set using the setBackgroundGradientFrom:toColor: method.
headerColor
The ad header text color.
descriptionTextColor
The ad description text color.
anchorTextColor
The ad URL text color.
fontFamily
The font used to render the ad.
headerTextSize
The font size of the header text.
borderColor
The border color to render the ad container. This property is ignored if border type is set to kGADSearchBorderTypeNone.
borderType
The border type to render the ad.
borderThickness
The thickness of the border around the ad container.
customChannels
Adds channel information to the ad request. This should contain a list of channel IDs separated by '+'.

Methods

(void)setBackgroundSolid:(UIColor *)color;
Sets a solid background color for rendering the ad.
(void)setBackgroundGradientFrom:(UIColor *)from toColor:(UIColor *)toColor;
Sets a linear gradient background color for rendering the ad.

Note: If both setBackgroundSolid: and setBackgroundGradientFrom:toColor: are set, only the latter is considered.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.