javascript - 谷歌广告不刷新

标签 javascript jquery ajax

因此,我使用 Google 提供的默认系统,在我的 Ajax 主题网站上每 30 秒刷新一次广告。当我使用 adblock 时,广告会通过,我可以看到页面上的广告计数正在更新,因此它会刷新它们,但由于某种原因它们根本不会显示在页面上。

<script>

// Load GPT asynchronously
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
  var gads = document.createElement("script");
  gads.async = true;
  gads.type = "text/javascript";
  var useSSL = "https:" == document.location.protocol;
  gads.src = (useSSL ? "https:" : "http:") +
  "//www.googletagservices.com/tag/js/gpt.js";
  var node = document.getElementsByTagName("script")[0];
  node.parentNode.insertBefore(gads, node);
})();
</script>

<script>

googletag.cmd.push(function() {

// Define the ad slot
var slot1 = googletag.defineSlot("/6931143405/Sound", [728, 90], "leaderboard").
 setTargeting("Sound", "refresh").
 addService(googletag.pubads());

// Start ad fetching
googletag.enableServices();
googletag.display("leaderboard");

// Set timer to refresh slot every 10 seconds
setInterval(function(){googletag.pubads().refresh([slot1]);}, 10000);
});
</script>

使用上面的 javascript,我几乎可以肯定,使用下面的 div 应该刷新广告或至少在 div 中显示广告。

<center><div id="leaderboard" style="width:728px; height:90px;"></div></center>

它说的地方

defineSlot("/XXXX/sound"

XXXX 应更改为

data-ad-slot="XXXX"

Google AdSenses 默认代码中的这一行正确吗?

最佳答案

我发现您的代码没有任何问题,广告正在调用并刷新,但调用的网址失败 (404)。您确定您的网络ID正确吗?也许这个标签组合受到速率限制?

http://pubads.g.doubleclick.net/gampad/ads?gdfp_req=1&correlator=2597499592245248&output=json_html&callback=callbackProxy&impl=fif&fif_to=1&sfv=1-0-2&iu=%2F6931143405%2FSound&sz=728x90&scp=Sound%3Drefresh&eri=1&cookie_enabled=1&lmt=1426955251&dt=1426955251200&cc=100&frm=20&biw=1869&bih=495&oid=3&adx=496&ady=1254&adk=1526223150&gut=v2&ifi=37&u_tz=-240&u_his=9&u_java=true&u_h=1080&u_w=1920&u_ah=1050&u_aw=1920&u_cd=24&u_nplug=10&u_nmime=52&u_sd=1&flash=17.0.0&url=http%3A%2F%2Fstackoverflow.com%2Fquestions%2F27495188%2Fgoogle-ads-are-not-refreshing&ref=http%3A%2F%2Fstackoverflow.com%2Fsearch%3Ftab%3Dnewest%26q%3D%255bjavascript%255d%2520googletag&vrg=58&vrp=58&ga_vid=953776431.1420416155&ga_sid=1426954906&ga_hid=728666356

关于javascript - 谷歌广告不刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27495188/

相关文章:

javascript - 在多个对象中查找相同的键

html - 从ajax更新页面时如何避免闪烁

javascript - 等待所有ajax回调被执行的最佳解决方案

javascript - 如何将变量从 iframe 传递到页面?

javascript - Chart.js - 千位分隔符、工具提示中的货币、X 和 Y 轴标签

javascript - 如何获取部分CSS代码到JavaScript/jQuery?

javascript - Microsoft JScript 运行时错误 : Member not found

php - 如何通过 jQuery 将文件发送到 php?

javascript - 如何对数组中的相同对象求和

通过 javascript 和下拉菜单的 PHP/mySQL 输出