Custom Search Ads

Get the code for your custom search style

After you've created your search style, follow these steps to copy and paste the code into your search page:

  1. Sign in to your AdSense account.
  2. Click Ads for Search and then Custom search styles.
  3. Click Get code Embed.
  4. On the "Code generator" page:
    • In the "Your ad containers" section:
      1. 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.
      2. (Optional) Click +add container to add the HTML ID of another container.
    • In the "Now copy and paste the code" section:
      1. Copy and paste the first code snippet into the <head> tag of your search page.
      2. Copy and paste the second code snippet into the <body> tag of your search page.
  5. 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>
</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>
Was this article helpful?
How can we improve it?