javascriptgoogle-custom-search

Limit number of ads in Google custom search


I am considering using Google Custom Search for my site. It seem to be pretty customizable and I can match my site's style. The only thing that holds e back is obscene number of ads shown above my results - 4.

check out this similar Example and screenshot below:

screenshot

I found documentation that seems to indicate that I can control this

'maxTop' : 4

but I can't figure out for the world where I could use this setting since the only code I include looks like:

<script async src="https://cse.google.com/cse.js?cx=e14513e5dxxxxxx"></script>
<div class="gcse-search"></div>

Google documentation

Also, important fact is that the Custom Search is a part of Google Ads and I utilize Google Tag to include all-Google.


Solution

  • Google CSE differs from CSA - (CSE - Custom Search Engine / Programmable Search Engine, CSA - Custom Search Ads). You can remove ads from your Programmable Search Engine by configuring it with your Adsense account or by using paid API. You can also get it for free - Nonprofit organizations, accredited educational institutions, and government agencies. As people suggest, Google CSE had option for everyone to remove ads for free - but not anymore. Google CSE

    maxTop property that you are referring is basically for CSA. To use this, you need to connect your search engine to adsense. Once connected, you can either use maxTop or number properties.

    Both number and maxTop will act as the max number of ads that should be shown in that block. The only difference is that it lets the system know which block is on the top of the page, and maxTop can only be used in the first block of the page. If you have multiple blocks, use number. Below is the code-snippet showing how to set maxTop in CSA.

    <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",
        "maxTop": 2
      };
      var adblock2 = {
        "container": "afscontainer2",
        "maxTop": 4
      };
      _googCsa('ads', pageOptions, adblock1, adblock2);
    </script>
    </body>
    </html>