After you've created your search style , follow these steps to copy and paste the code into your search page:
- Sign in to your AdSense account.
- Click Ads for search, then Search styles.
- Click Generate code.
- On the "Code generator" page:
- In the "Step 1: Create your containers" section:
- Add the HTML DIV ID of the ad container on your search page. Alternatively you can keep the default container names (e.g., afscontainer1 ) and update the DIV IDs on your page to match.
- (Optional) Click Add containerto add the HTML ID of another container.
- In the "Step 2: Copy and paste your code" section:
- Copy and paste the first code snippet into the
<head>
tag of your search page. - Copy and paste the second code snippet into the
<body>
tag of your search page.
- Copy and paste the first code snippet into the
- In the "Step 1: Create your containers" section:
- When you're finished, click I'm done.
Code example
Here's an example of a search results page with both code snippets added.
Note: Do not copy the code from this example or your search ads won't work. Make sure you copy and paste the code directly from your AdSense account.
<html>
<head>
<script async="async" src="https://www.google.com/adsense/search/ads.js"></script>
<!-- other head elements from your page -->
<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>
</head>
<body>
<div id="afscontainer1"></div>
<div id="afscontainer2"></div>
<script type="text/javascript" charset="utf-8">
var pageOptions = {
"pubId": "partner-pub-1234567891234567", // Make sure this is the correct client ID
"styleId": "1234567891", // Make sure this is the correct style id
"query": "" // Make sure the correct query is placed here
};
var adblock1 = {
"container": "afscontainer1",
};
var adblock2 = {
"container": "afscontainer2",
};
_googCsa('ads', pageOptions, adblock1, adblock2);
</script>
</body>
</html>
<head>
<script async="async" src="https://www.google.com/adsense/search/ads.js"></script>
<!-- other head elements from your page -->
<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>
</head>
<body>
<div id="afscontainer1"></div>
<div id="afscontainer2"></div>
<script type="text/javascript" charset="utf-8">
var pageOptions = {
"pubId": "partner-pub-1234567891234567", // Make sure this is the correct client ID
"styleId": "1234567891", // Make sure this is the correct style id
"query": "" // Make sure the correct query is placed here
};
var adblock1 = {
"container": "afscontainer1",
};
var adblock2 = {
"container": "afscontainer2",
};
_googCsa('ads', pageOptions, adblock1, adblock2);
</script>
</body>
</html>