Copying the sample code
Google warns that the sample code does not work as is. Copy the code straight from your AdSense account.
Implementation guide
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.
Understand it in 1 minute
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
Implemented example
<!-- 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>What Google recommends
Tips
Watch out
Google warns that the sample code does not work as is. Copy the code straight from your AdSense account.
The name given in the unit must match the ID of the div where the ads will appear.
Making several ad requests on the same page goes against Google's guidance, which asks for a single request, except with infinite scroll.
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.
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.
No. Google says that search ad implementations are not supported in mobile apps.
No. Search ads cannot be backfilled with AdSense for content, Ad Manager or AdMob ads.
In general, on pages whose results are mainly videos, images, news aggregation, people or music, unless Google approves in writing.
Library
Everything on this page follows Google's official documentation. Read it straight from the source:
The audit reads the site as a visitor would, without clicking anything, and shows what to fix.