ajax 使用 Google AdSense 的 400 错误请求

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19139171/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 11:06:36  来源:igfitidea点击:

400 Bad Request with Google AdSense

javascriptajaxadsense

提问by user276289

I am running a website that uses AJAX requests and history.pushState for navigation.

我正在运行一个使用 AJAX 请求和 history.pushState 进行导航的网站。

The requested content code contains Google's asynchronus AdSense code:

请求的内容代码包含 Google 的异步 AdSense 代码:

<ins class="adsbygoogle"
     style="display:inline-block;width:468px;height:60px"
     data-ad-client="ca-pub-xxxxx"
     data-ad-slot="xxxxxx"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

The head tag contains the adsbygoogle.js:

head 标签包含 adsbygoogle.js:

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

This setup is working for one dynamically loaded pageview. After that, ads don't show up anymore. The error console shows:

此设置适用于一个动态加载的网页浏览。之后,广告不再出现。错误控制台显示:

400 (Bad Request) in expansion_embed.js:188

The expansion_embed.js requests the ad from http://googleads.g.doubleclick.net/pagead/ads. The requestet url contains lots of parameters.

expand_embed.js 从http://googleads.g.doubleclick.net/pagead/ads请求广告。requestet url 包含很多参数。

Now, every time the ad doesshow up, the prev_fmtsparameter has a value of 468x60. If the ad fails to load, this parameter's value is 486x60%2C468x60.

现在,每一个广告的时间露面,prev_fmts参数的值468x60。如果广告加载失败,则此参数的值为486x60%2C468x60

What is causing this parameter to change? Is it possible that this change is causing the 400 Bad Request errors?

是什么导致此参数发生变化?此更改是否可能导致 400 Bad Request 错误?

回答by Robert Sinclair

You just need to wait, when you first implement Adsense it will give this error. It took until next morning for Adsense to start displaying ads. I implemented their Responsive ad type.

您只需要等待,当您第一次实施 Adsense 时,它​​会出现此错误。直到第二天早上 Adsense 才开始展示广告。我实现了他们的响应式广告类型。

回答by Balram Singh

I was also getting same error when I added adsense code first time in my website. In my case, it started working simply after reloading page.

当我第一次在我的网站上添加 adsense 代码时,我也遇到了同样的错误。就我而言,它在重新加载页面后就开始工作。

回答by pau.moreno

I had the same problem, and after some research, I've seen it's a problem of incompatibility between Google Adsens and AJAX sites.

我遇到了同样的问题,经过一些研究,我发现这是 Google Adsens 和 AJAX 站点之间不兼容的问题。

See Google's announcementand these twothreadsin Google's forums.

在 Google 的论坛中查看Google 的公告和这两个主题

I've tried to artifically mangle the prev_fmtsparameter, but I couldn't find my way through the obfuscated JS. Anyway, I guess that doing this would go against Google Adsense TOS.

我试图人为地修改prev_fmts参数,但我无法通过混淆的 JS 找到我的方法。无论如何,我想这样做会违反 Google Adsense TOS。

回答by Eyal

Adblock was blocking the ads. I Enabled the site to solved it.

Adblock 正在阻止广告。我启用了网站来解决它。