Web Implementation

Important: Read the Terms and Conditions before using this code

To use this code you must have an AdSense account with active permission to use AdSense Custom Search Ads.

Implementing AdSense Custom Search Ads on your site is a 3 step process:

Step 1: Customize page and ad unit options using the CSA Code Generator

The code generator makes it easy to customize the look, feel, and behavior of your ads. First configure page-level options. These options apply to all of the ad units on your page. Next, configure options for individual ad units. These settings configure the look and feel (colors, font size, etc) for individual ad units on the page.

Key Parameters:

Name Parameter Description
Pub-ID pubId This should be in the format 'pub-xxxxxxxxxxxxxxxx'.
Query query This should be dynamic based on your page. This variable targets the ads and therefore should always match what the user on your site has just performed a search for.

Note: By leaving the default for some settings, you will automatically receive future optimizations to maximize performance.

Step 2: Configure additional page and unit level options

The most commonly used features are supplied in the code generator, but some additional parameters are available in the reference section. The reference section contains all page level options, which apply to all ad units on the page, as well as all unit level options, which apply to individual ad units.

Step 3: Implement the code

Copy the code from the code generator and paste it on your page, remembering to update the query parameter. The code generated in the head tag should be placed in the head tag on your site for the ads to load properly. The code for ad unit 1 will contain the settings for all ad units on the page. Additional ad units will only require placing the corresponding ad unit <div> on the page where ads should appear.


A full, working example is shown below. You may open this example in new tab here. Remember to put your own pubId.


<script async="async" src="https://www.google.com/adsense/search/ads.js"></script>

<script type="text/javascript" charset="utf-8">
arguments)},g[o]['t']=1*new Date})(window,'_googCsa');



<div id="afscontainer1"></div>
<script type="text/javascript" charset="utf-8">

var pageOptions = {
'pubId' : 'pub-9616389000213823',// Enter your own pubId here!
'query' : 'flowers'

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

var adblock2 = {
'container' : 'afscontainer2',
'width' : 700

_googCsa('ads', pageOptions, adblock1, adblock2);

<p>Search result 1</p>
<p>Search result 2</p>
<p>Search result 3</p>

<div id="afscontainer2"></div>