限制 Google 自定义搜索中的广告数量
Limit number of ads in Google custom search
我正在考虑为我的网站使用 Google 自定义搜索。它似乎是非常可定制的,我可以匹配我网站的风格。唯一让我退缩的是我的结果上方显示的广告数量惊人 - 4.
查看此类似 Example 和下面的屏幕截图:
我找到的文档似乎表明我可以控制它
'maxTop' : 4
但我无法弄清楚我可以在哪里使用此设置,因为我包含的唯一代码如下所示:
<script async src="https://cse.google.com/cse.js?cx=e14513e5dxxxxxx"></script>
<div class="gcse-search"></div>
此外,重要的是自定义搜索是 Google 广告的一部分,我使用 Google 标签来包含所有-Google.
- 要限制广告数量,我认为您应该使用 'number' 参数。
我认为您需要添加如下内容:
<script type="text/javascript" charset="utf-8">
// Page level parameters
var pageOptions = {
"pubId": "clientId",
"styleId": "1234567890",
"query": myQuery
};
// Unit level parameters
var adblock1 = {
"container": "afscontainer1",
"number": 4
};
_googCsa('ads', pageOptions, adblock1);
</script>
您使用的是可编程搜索引擎,而不是您链接的文档中提到的 Adsense 搜索引擎。
见the difference between AdSense search engines and Programmable Search Engine
似乎要配置广告,您必须通过 your AdSense configuration (once you've connected your Programmable Search Engine to your AdSense account) or via the paid API 进行管理(以完全删除广告)
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 允许所有人免费删除广告 - 但现在不行了。
maxTop property that you are referring is basically for CSA. To use this, you need to connect your search engine to adsense。连接后,您可以使用 maxTop 或 number 属性。
number 和 maxTop 都将用作应在该块中显示的最大广告数。唯一的区别是它让系统知道页面顶部是哪个块,而 maxTop 只能在页面的第一个块中使用。如果您有多个块,请使用数字。下面是显示如何在 CSA 中设置 maxTop 的代码片段。
<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>
我正在考虑为我的网站使用 Google 自定义搜索。它似乎是非常可定制的,我可以匹配我网站的风格。唯一让我退缩的是我的结果上方显示的广告数量惊人 - 4.
查看此类似 Example 和下面的屏幕截图:
我找到的文档似乎表明我可以控制它
'maxTop' : 4
但我无法弄清楚我可以在哪里使用此设置,因为我包含的唯一代码如下所示:
<script async src="https://cse.google.com/cse.js?cx=e14513e5dxxxxxx"></script>
<div class="gcse-search"></div>
此外,重要的是自定义搜索是 Google 广告的一部分,我使用 Google 标签来包含所有-Google.
- 要限制广告数量,我认为您应该使用 'number' 参数。 我认为您需要添加如下内容:
<script type="text/javascript" charset="utf-8">
// Page level parameters
var pageOptions = {
"pubId": "clientId",
"styleId": "1234567890",
"query": myQuery
};
// Unit level parameters
var adblock1 = {
"container": "afscontainer1",
"number": 4
};
_googCsa('ads', pageOptions, adblock1);
</script>
您使用的是可编程搜索引擎,而不是您链接的文档中提到的 Adsense 搜索引擎。
见the difference between AdSense search engines and Programmable Search Engine
似乎要配置广告,您必须通过 your AdSense configuration (once you've connected your Programmable Search Engine to your AdSense account) or via the paid API 进行管理(以完全删除广告)
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 允许所有人免费删除广告 - 但现在不行了。
maxTop property that you are referring is basically for CSA. To use this, you need to connect your search engine to adsense。连接后,您可以使用 maxTop 或 number 属性。
number 和 maxTop 都将用作应在该块中显示的最大广告数。唯一的区别是它让系统知道页面顶部是哪个块,而 maxTop 只能在页面的第一个块中使用。如果您有多个块,请使用数字。下面是显示如何在 CSA 中设置 maxTop 的代码片段。
<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>