Open workspace

Implementation guide

Search ads

Search ads (AdSense for Search / Programmable Search Engine)

Ads that appear in your site's search results, tied to what the person typed, through AdSense for search or Programmable Search.

  • AdSense
  • mobile and desktop (on the site's search results page)
Desktop
Mobile

Understand it in 1 minute

What search ads are

You know when you search for something on Google and some sponsored results appear? Search ads bring that idea inside your site. When someone uses the site's search box and types, for example, flowers, the results page can show ads related to flowers. It is like the information desk at a mall: the person asks where a store is, gets the answer and, next to it, sees an offer that matches the question.

Google offers two paths. The first is AdSense for search, called AFS. It is not open to everyone: those who think their site fits need to talk to the account manager, and Google reviews the site first. With AFS, you create a search style in AdSense, generate the code and place it on your results page. The second path is Programmable Search Engine, Google's programmable search engine. You create a unit of the type Search engine in AdSense, place the search on your site and receive a share when someone clicks an ad.

The rules are very specific. The ad can only appear on a results page that came from a real search made by the person. The search box cannot come pre-filled, and you cannot create links with ready-made search terms. The ads must be easy to tell apart from the results and cannot outnumber them. Nobody can be rewarded for searching or for viewing ads. And there is a limit of units per page, different for computers and for mobile.

Google created this format because the most useful ad is the one that answers what the person is looking for at that moment. It makes the most sense on sites with a heavily used internal search, such as stores, portals and directories. For sites with little search, it may not be worth the work, and Google itself requires a minimum volume of search ad impressions for the account to keep access to AFS.

Step by step

How to implement

  1. Choose the path and ask for accessFor AFS, talk to your account manager, because sign-up is not automatic. For Programmable Search Engine, you need an AdSense account activated through the confirmation email.
  2. Create the search style (AFS)In AdSense, click Search ads and then Search styles. Create a search style that matches your results page.
  3. Generate and paste the codeUnder Search styles, click Get code. In Step 1: create your containers, enter the div ID for each unit, or keep the default name afscontainer1. Paste the first snippet in the head and the second in the body of the results page, and click Done.
  4. Check the valuesIn the code, check your publisher ID, the style ID and the search field, which must carry exactly what the person searched for on that page.
  5. Or use Programmable Search EngineIn AdSense, create an ad unit of the type Search engine and place the search element on your own site, with a layout that is not the one hosted by Google.

Implemented example

The code and how it looks on screen

The first snippet goes in the head and the second in the body of the search results page; in practice, always copy the code generated in your AdSense account.
<!-- No <head> da página de resultados da busca -->
<script async="async"
  src="https://www.google.com/adsense/search/ads.js"></script>
<script type="text/javascript" charset="utf-8">
(function(g,o){g[o]=g[o]||function(){(g[o]['q']=g[o]['q']||[]).push(
  arguments)},g[o]['t']=1*new Date})(window,'_googCsa');
</script>

<!-- No <body>, onde os anúncios devem aparecer -->
<div id="afscontainer1"></div>
<script type="text/javascript" charset="utf-8">
  var pageOptions = {
    'pubId': 'seu-id-de-cliente', // Coloque aqui o seu ID de cliente
    'query': 'flores',            // O que a pessoa buscou nesta página
    'styleId': '0000000000'       // O ID do seu estilo de pesquisa
  };

  var adblock1 = {
    'container': 'afscontainer1',
    'width': 700
  };

  _googCsa('ads', pageOptions, adblock1);
</script>
On desktopIt appears on the site's search results page, in units above, below or beside the results. Units above or below have up to 5 ads, and those on the side up to 8.
On mobileIt appears on the results page, with at most 2 units per page, up to 3 ads in the top unit and 3 in the bottom one. Only one unit can be visible at a time.

What Google recommends

Do and don't

Allowed

  • Show search ads on desktop and mobile sites.
  • Have up to 3 search ad units per page on desktop, and up to 2 on mobile and tablet.
  • Place several units with a single ad request. Each extra unit only needs its own div.
  • Make a new request when the person scrolls the page and loads more results, as in infinite scroll.
  • Using alternative search queries, as long as they follow Google's own policy for them.

Not allowed

  • Leave the search box pre-filled or create links with ready-made search terms.
  • Place search ad units outside the search results page.
  • Pay or reward the person to search or to view ads.
  • Show more ads than search results.
  • Hide, move or tamper with the units, request more units than you will show, or build your own lazy loading.

Tips

To do it right

Watch out

Common errors

Copying the sample code

Google warns that the sample code does not work as is. Copy the code straight from your AdSense account.

Container with a different name

The name given in the unit must match the ID of the div where the ads will appear.

More than one request per page

Making several ad requests on the same page goes against Google's guidance, which asks for a single request, except with infinite scroll.

Layout hosted by Google

In Programmable Search Engine, the layout hosted by Google does not share revenue. There is also no revenue share on the engine's public address, or when the person leaves through the Search on Google links.

Frequently asked questions

Can any site use AFS?

No. Sign-up is not automatic: you talk to your account manager and Google reviews the site. To keep access, the account needs a minimum volume of impressions.

Can I use search ads in an app?

No. Google says that search ad implementations are not supported in mobile apps.

Can I fill the empty spaces with other ads?

No. Search ads cannot be backfilled with AdSense for content, Ad Manager or AdMob ads.

On which results pages can they not appear?

In general, on pages whose results are mainly videos, images, news aggregation, people or music, unless Google approves in writing.

Library

Official Google source

Everything on this page follows Google's official documentation. Read it straight from the source:

Does your site use this format the right way?

The audit reads the site as a visitor would, without clicking anything, and shows what to fix.

Run an audit