AdSense Custom Search Ads

Implementation Guide

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.

Example

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

<html>
<head>

<script type="text/javascript" charset="utf-8">
(function(G,o,O,g,L,e){G[g]=G[g]||function(){(G[g]['q']=G[g]['q']||[]).push(
arguments)},G[g]['t']=1*new Date;L=o.createElement(O),e=o.getElementsByTagName(
O)[0];L.async=1;L.src='//www.google.com/adsense/search/async-ads.js';
e.parentNode.insertBefore(L,e)})(window,document,'script','_googCsa');
</script>

</head>

<body>

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

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

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

var adblock2 = {
'container' : 'adcontainer2',
'width' : 700
};

_googCsa('ads', pageOptions, adblock1, adblock2);
</script>

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

<div id="adcontainer2"></div>
</body>
</html>

Authentication required

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

Signing you in...

Google Developers needs your permission to do that.