AdSense for search (AFS)

Implement a custom search engine

To add a custom search engine to your site, you first generate the search box code in your AdSense account and then copy and paste that code into the HTML of your pages. You can either add the default search code to start providing search to your users right away, or spend some time customising your search engine before pasting the code.

Before you start

If you haven't already, add the AdSense for search product to your AdSense account:

  1. Sign in to your AdSense account.
  2. Click Ads.
  3. Click Other products.
  4. Under 'Search', click Get started with AdSense for search.

    When you see the Ads for Search option in your account, you're ready to create your first custom search engine.

Create a custom search engine

To create a new custom search engine for your site, follow these steps:

  1. Sign in to your AdSense account.
  2. Click Ads for Search.
  3. Click +New custom search engine.
  4. Give your search engine a name.
  5. (Optional) Customise your custom search engine:

    View customisation options

    1. Choose whether you want your search engine to search the entire web, or specific sites you list.
    2. Choose which keywords you'd like Google to use to make sure that we promote the most relevant ads and pages in your search engine's search results. Learn more about keywords for AdSense for search.
    3. Leave the tick box selected if you want to use Google SafeSearch. Google's SafeSearch screens for sites that contain pornography and explicit sexual content and eliminates them from search results. While no filter is 100% accurate, Google's filter uses advanced proprietary technology that checks keywords and phrases, URLs and Open Directory categories.
    4. Choose which country version of Google will be searched through for your search box. For example, your search results could come from,,, etc.
    5. Select the primary language of your site.
    6. Choose which encoding you want to use for your search engine. We suggest that you choose the search encoding that matches the encoding of your browser.
    7. Select your transliteration languages. Enabling transliteration for your search engine allows your site visitors to type a query phonetically in English and have that query appear in another language. Learn more about transliteration
    8. Choose whether you want to use popular queries. Popular queries is a feature that lets your users see what others have been searching for on your site. Popular queries are updated daily and dynamically show the most recent data.
    9. In the "Custom channels" section, set up a custom channel if you'd like to track the performance of your search engine. Find out more about custom channels.
    10. In the "Search box style" section, choose a style for the search box of your search engine.
    11. In the "Search results" section, choose how you'd like to display search results within a page on your site, e.g. on a Google page in the same window, on a Google page in a new window, etc.
  6. Click Save and get code.
  7. Copy the code from the "Search Box Code" window and paste it into the HTML of your pages where you want your search engine to appear.

    AFS code

If you'd like more details about adding ad code to your pages, see the Code Implementation Guide.

Was this helpful?
How can we improve it?

Need more help?

Sign in for additional support options to quickly solve your issue