Google AdSense JavaScript 导致多次页面加载?

发布于 2024-11-24 05:06:06 字数 5137 浏览 4 评论 0 原文

更新

好的 - 我现在知道多个页面加载来自哪里! (不过,谜团尚未解开)

似乎在向包含 AdSense 广告的网页发出请求后,Google 立即向完全相同的网址发出请求(一次或多次)强>

例如,这就是日志的样子(注意来自 Mediapartners-Google 的请求):(

2011-07-20 09:50:20 xxx.xxx.xxx.xxx GET /requestedURL/ 80 - xxx.xxx.xxx.xxx Mozilla/5.0+(Browserstring removed) 200 0 0 1140
2011-07-20 09:50:20 xxx.xxx.xxx.xxx GET /requestedURL/ 80 - 66.249.72.52 Mediapartners-Google 200 0 64 218
2011-07-20 09:50:22 xxx.xxx.xxx.xxx GET /requestedURL/ 80 - 66.249.72.52 Mediapartners-Google 200 0 0 171

我应该更多地关注 IIS 日志,而不是我自己的应用程序日志 - 我只是没有想到这些多个,相同的、同时的请求可能来自不同的来源)。这也解释了为什么我用WireShark分析请求时找不到任何奇怪的东西,以及为什么fiddler没有显示任何奇怪的东西。

因此,赏金的问题现在变成:

  • 为什么谷歌在请求页面后如此快地提出这些请求?(我知道他们需要评估页面的内容,但是立即之后,并且多次对我来说像是虐待。)
  • 我能做什么来阻止这种情况?

并且出于兴趣:

  • 还有其他人吗他们的日志中似乎有类似的内容? (或者我的 AdSense 帐户有什么奇怪的地方)

好的,我会提前为篇幅表示歉意!...

此问题涉及 此问题,涉及 Google Adsense Javascript 代码导致错误。 (格式为 Unable to post message to googleads.g.doubleclick.net. Recipient has origin Something.com

我不会在那里复制所有信息,但结论似乎是AdSense JS 有问题。 (如果您有时间,请阅读问题背景)。 我知道这个问题有一段时间了,但决定忍受 JS 错误,而不是从网站上删除 AdSense。

但是最近我注意到在我的 ASP.NET MVC2 应用程序中,控制器操作似乎每个页面请求被调用两次(有时甚至 3 次)。奇怪的是,这只是发生在生产服务器上。 经过一番思考后,我意识到开发环境和生产环境之间的一个区别是 AdSense javscript 仅在生产环境中有效。

为了测试这一点,我从其中一个生产页面中删除了所有 AdSense 代码,结果发现,多页面加载问题消失了!

我认为也许是页面上存在一般的 JS 错误导致了问题,因此为了测试这一点,我在自己的 JS 代码中引入了一些简单的错误,但是这并没有导致多页面- 加载问题再次出现。

<罢工> 一种已知的情况是,每个请求可以多次调用页面,即图像标记为空src 属性,或具有空 src 属性的外部资源引用。至关重要的是,AdSense JS Bug 问题获得最多支持的答案指出:

“本次调用中的 targetOrigin 参数,this.la 设置为 http://googleads.g.doubleclick.net。然而,新的 iframe 是 其 src 设置为 about:blank 编写。”

这看起来与空 src 问题出奇地相似.... 这似乎太巧合了,目前我认为这就是问题所在。 [编辑:这是一个转移注意力的事情]

但是,我不知道我们要从这里开始。这些多个操作调用正在导致真正的问题(我我不得不使用代码阻塞、序列化事务和各种令人讨厌的黑客来限制不利影响)。当然,我可能完全找错了——我很困惑,鉴于 AdSense 的普遍存在以及问题的本质,我找不到任何其他对此的参考(但话又说回来,AdSense 的结论JS Bug问题也令人惊讶)。我希望这对我来说是一个愚蠢的错误,所以我需要进行健全性检查。

我想询问社区:

  • 还有其他人遇到过这个问题吗?或者使用 AdSense 的人可以复制并确认这个问题吗? [请参阅下面的注释]
  • 假设问题确实如此,我能做什么? (当然,除了取消 AdSense 之外)
  • 如果不是,那么可能是什么原因造成的?

总结一下: - 每个页面请求我的操作被执行 2(有时 3)次。

  • 仅当存在 GOOGLE ADSENSE 广告时才会发生这种情况
  • 我删除了所有 AdSense JS 并在我自己的 JS 中引入了一个错误:操作仅被调用一次...
  • 当页面上存在空 src 属性时,可能会发生类似的问题
  • 对上一个问题的回答总结道,AdSense JS 在iFrame
  • 我得出的结论是,AdSense 代码中的 src="about:blank" 最有可能是问题的根源。
  • 如果我禁用浏览器上的 JavaScript,问题就消失了

只是为了记录我已经排除的事情:

  • 这种情况发生在浏览器上:Chrome(12)、Firefox(5) 和 IE(8)。
  • 我已禁用浏览器上的所有插件(YSlow、Firebug 等...)
  • 图像没有空 src (src=""/src="#"),或我的代码中的 html 中的其他外部资源
  • css 中没有空的 url 引用 ( url('') )
  • 这不太可能是服务器端代码/配置问题,因为它不会发生在开发(以及开发和生产之间的一些区别是开发中缺少 AdSence JS)

注意:对于任何想要复制这一点的人来说,应该注意的是,奇怪的是,当发生多个操作调用时,Fiddler 仅显示一个请求正在发送到服务器。我不知道为什么会出现这种情况,但服务器日志记录不会说谎:)也许以前有过因 img 标签中的空 src 属性引起的问题的人可以说他们是否在 Fiddler 中看到过相同的行为。


请求的额外信息

HTML (@Ivan)

以下是我实现 Adsense 的方式(已删除 ID)

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<div class="ad">
<%if (!HttpContext.Current.IsDebuggingEnabled) { %>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-xxxxxxxxxxxxxxx";
/* xxxxxxxxxxxxxxx */
google_ad_slot = "xxxxxxxxx";
google_ad_width = 728;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>                     
<%} else { %>
<img src="/Content/images/googleAdMock728x15_4_e.gif" width="728" height="15" />
<%} %>
</div>

这是由视图中的 RenderPartial 插入的:

<% Html.RenderPartial("AdSense_XXXXXX"); %>

TCP 日志记录 (@Tomas)

到目前为止,我已经完成了wireshark捕获:

  1. 出现问题
  2. 客户端上请求生产上的页面时,在客户端上请求生产上的页面时 没有问题(即Adsense 已删除)

我真的看不出两者之间有什么显着差异(尽管我的网络技能不太好)。需要注意的一件事是,它们似乎都在初始请求之后立即对 HTTP 请求进行了 TCP 重传 - 我不知道其意义。我可以确认,在情况 1 中,服务器日志报告了 2 次执行,而在情况 2 中,仅报告了 1 次执行。

接下来我将在这两种情况下尝试在服务器端进行 TCP 日志记录,并在此处发布结果。

Update

Ok - I now know where the multiple page loads are coming from! (However, the mystery is not yet solved).

It seems that immediately after a request is made to a page containing AdSense ads, Google makes a request for exactly the same URL (one or more times)

e.g. this is what the logs look like (note requests from Mediapartners-Google):

2011-07-20 09:50:20 xxx.xxx.xxx.xxx GET /requestedURL/ 80 - xxx.xxx.xxx.xxx Mozilla/5.0+(Browserstring removed) 200 0 0 1140
2011-07-20 09:50:20 xxx.xxx.xxx.xxx GET /requestedURL/ 80 - 66.249.72.52 Mediapartners-Google 200 0 64 218
2011-07-20 09:50:22 xxx.xxx.xxx.xxx GET /requestedURL/ 80 - 66.249.72.52 Mediapartners-Google 200 0 0 171

(I should have paid more attention to the IIS logs, rather than my own application logs - it just didn't occur to me that these multiple, identical, simultaneous request could have been coming from different sources). This also explains why I couldn't find anything strange when analysing the request with WireShark, and why fiddler didn't show anything strange.

So the question for the bounty now becomes:

  • Why is google making these requests so quickly after the page is requested? (I know they need to asses the page for content, but immediately after, and multiple times sees like abuse to me.)
  • What can I do to stop this?

And out of interest:

  • Has anyone else seem something similar in their logs? (or is this something weird with my AdSense account)

Ok, I'll apologise in advance for the length!...

This question is realted to this one, regarding Google Adsense Javascript code causing errors. (of the form Unable to post message to googleads.g.doubleclick.net. Recipient has origin something.com)

I won't duplicate all of the information there, but the conclusion seems to be that the AdSense JS is buggy. (please read the question for background if you have time).
I knew about this problem for some time, but decided to live with the JS errors rather than pulling AdSense from the site.

However, Recently I noticed that in my ASP.NET MVC2 application, Controller Actions seemed to be called twice per page request (sometimes even 3 times). Odly, it was only happening on the production server. After some thought I relalised that one difference between the Dev and Production environments was that the AdSense javscript was only active in production.

To test this I removed all adsense code from one of the production pages, and lone behold, the multiple-page-load problem went away!

I thought that perhaps it was the fact that there were general JS errors on the page that was causing the problem, so to test this I introduced some simple errors into my own JS code, however this did not cause the multiple-page-load problem to reappear.


One known situation where pages can be called multiple times per request is when there are image tags with empty src attributes, or external resource references with empty src attributes. Crucially, The most upvoted answer to the AdSense JS Bug question notes that:

"The targetOrigin argument in this call, this.la is set to
http://googleads.g.doubleclick.net. However, the new iframe was
written with its src set to about:blank."

This seems eerily similar to the empty src issue.... This seems too much of a co-incidence, and currently I'm of the opinion that this is the problem.
[EDIT: This was a red herring]

However, I've no idea wehre to go from here. These multiple action calls are causing real problems (I'm having to use code blocking, serialised transactions, and all sorts of nasty hacks to limit adverse effects). Of course, I could be barking up the wrong tree entirely - I'm puzzled that I can't find any other references to this, given the ubiquity of AdSense, and the nature of the problem (but then again the conclusions of the AdSense JS Bug question are also surprising). I would love this to turn out to be a stupid mistake on my part, so I need a sanity check.

I'd like to ask the community:

  • Has anyone else experienced this problem?, or can anyone who is using AdSense replicate and confirm it? [See note below]
  • Assuming the problem is what it seems, what can I do? (other than pulling AdSense of course)
  • If not, then what might be causing this?

To Sumarise:
- My actions are being executed 2 (sometimes 3) times per page request.

  • THIS ONLY HAPPENS WHEN GOOGLE ADSENSE ADS ARE PRESENT
  • I removed all AdSense JS and introduced an error into my own JS : Actions are called only once...
  • A similar problem can happen when empty src properties are present on the page
  • An answer to a previous question sumarises that the AdSense JS sets a src="about:blank" on an iFrame
  • I have come to the conclusion that the src="about:blank" from the AdSense code is the most likely source of the problem.
  • If I disable JavaScript on the browser, the problem goes away

Just to document the things I have ruled out:

  • This is happening across browsers: Chrome(12) Firefox(5) and IE(8).
  • I have dissabled all plugins on browsers (YSlow, Firebug etc...)
  • There are no empty src (src=""/src="#") for images, or other external resources in the html in my code
  • There are no empty url references in the css ( url('') )
  • It's unlikely to be server side code/config problem, as it doesn't happen in Dev (and of the few differences between dev and production is the absence of AdSence JS in Dev)

Note: For anyone looking to replicate this, it should be noted that, strangely, when the multiple action calls happen Fiddler shows only one request being sent to the server. I have no idea why this should be the case, but the server logging doesn't lie :) Perhaps someone who has prior experience with this problem when caused by empty src attributes in img tags can say whether they have seen the same behaviour with Fiddler.


Requested extra information

HTML (@Ivan)

Here's how I'm implementing the Adsense (ids removed)

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<div class="ad">
<%if (!HttpContext.Current.IsDebuggingEnabled) { %>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-xxxxxxxxxxxxxxx";
/* xxxxxxxxxxxxxxx */
google_ad_slot = "xxxxxxxxx";
google_ad_width = 728;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>                     
<%} else { %>
<img src="/Content/images/googleAdMock728x15_4_e.gif" width="728" height="15" />
<%} %>
</div>

This is being inserted by a RenderPartial in the View:

<% Html.RenderPartial("AdSense_XXXXXX"); %>

TCP Logging (@Tomas)

So far I have done a wireshark capture:

  1. on client when requesting page on production with problem
  2. on client when requesting page on production without problem (i.e. Adsense Removed)

I can't really see a significant difference between the two (although my network skills are not great). One thing to note is that they both seem to have a TCP retransmittion of the HTTP request immediately after the initial request - I don't know the significance of that. I can confirm though that in case 1 the server logs reported 2 executions, and in case 2 only one execution.

Next I will try TCP logging on the server side in both cases, and post results here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

滥情稳全场 2024-12-01 05:06:38

除了 AdSense 代码本身的嵌入之外,与 AdSense 相关的两件事在您的两个测试用例中也有所不同:

  1. !HttpContext.Current.IsDebuggingEnabled 时还会发生什么?这似乎是事实上的生产标志;也许某个地方正在发生一些其他细微差别,这些细微差别取决于同一个标志。

  2. Html.RenderPartial("AdSense_XXXXXX") 是否有可能以某种方式导致您的控制器跳回执行开始处?

从您的描述来看,服务器上似乎执行了两次,但客户端只发送了一个请求。这意味着服务器出现错误,这两行是 AdSense 触发的关键。要进一步缩小范围,请尝试直接嵌入 AdSense 部分,而不是调用 Html.RenderPartial()。如果这不会改变结果,则可能值得对 HttpContext.Current.IsDebuggingEnabled 上的其他开关进行健全性检查。

否则,了解服务器端日志记录是在收到请求时、发送响应之前还是发送响应之后可能会有所帮助。

Aside from the embedding of the AdSense code itself, there are two things related to AdSense that differ in your two test cases:

  1. What else happens when !HttpContext.Current.IsDebuggingEnabled? This appears to be the de-facto production flag; maybe there is some other nuance somewhere that is happening that depends on this same flag.

  2. Is it possible that Html.RenderPartial("AdSense_XXXXXX") is somehow causing your Controller to jump back to the beginning of its execution?

From your description, it seems like the execution is happening twice on the server but only one request is being sent from the client. This implies a server error, and these two lines are the crux of your AdSense triggering. To further narrow it down, try embedding the AdSense partial directly instead of calling Html.RenderPartial(). If that doesn't change the result, it might be worth a sanity check on what else switches on HttpContext.Current.IsDebuggingEnabled.

Failing that, it might be helpful to know whether your server-side logging takes place as the request is received, before the response is sent, or after the response is sent.

逆蝶 2024-12-01 05:06:38

是的,我刚刚在与我的合作伙伴进行 TeamView 会话时发现了这一点。在我的盒子上,我的主页仅针对我的网站按请求加载一次。

然后巧合的是,在使用 Fiddler 时,我的合作伙伴收到了 4 个对示例页面的请求。这是一个 1.5 MB 的页面,包含大脚本和许多其他依赖项,所以这确实是一个 WTF 时刻,因为我在 15 年的 Web 开发中从未见过这样的事情。

如果谷歌正在这样做,我必须说他们应该意识到今天的网站可能拥有非常大的页面和非常大的受众。这可能意味着他们将每个请求的带宽提升了 4 倍。就像我说的,WTF????

我希望这个问答有一个更明确的解决方案。
我确实使用谷歌翻译小部件,但这仅发生在他的盒子和主页上。其他页面也使用翻译小部件,我确实通过 google CDN 请求我的 JQUERY。谷歌可能会这样做吗?

Yes, I just detected this during a TeamView session with my partner. On my box my main page ONLY for my site loads once per request.

Then by coincidence while using Fiddler my partner is getting 4 requests to the sample page. It is a 1.5 MB page with big scripts and lotsa other dependencies so this was truly a WTF moment as I have never seen anything like this in 15 years of web development.

If google is doing this I must say they should realize today's sites might have very big pages and very big audiences. That could mean they are jacking bandwidth by a factor of 4 per request. Like I said, WTF?????

I wish this Q&A had a more definitive resolution.
I do use Google Translate widget but this is only occurring on his box and for the main page. The other pages also use the translate widget and I do request my JQUERY via the google CDN. Could anything Google be doing this.

尾戒 2024-12-01 05:06:37

鉴于您观察到的行为似乎难以避免,我们是否可以专注于解决方法?

能否根据UserAgent区分请求,从而过滤掉请求。
这对你来说是一个可行的方法吗?
如果是这样,那么您可能可以基于这种方法: http://blog.flipbit.co.uk/2009/07/writing-iphone-sites-with-aspnet-mvc.html
在这里,他们检测 iPhone,但 Mediapartners-Google 机器人的概念是相同的。

Given that the behaviour that you are observing appear to be hard to avoid, can we rather focus on workarounds?

Can you differentiate requests based on UserAgent, and thus filter out requests.
Could that be a viable approach for you?
If so then you could probably base upon this approach: http://blog.flipbit.co.uk/2009/07/writing-iphone-sites-with-aspnet-mvc.html
Here they detect iPhones, but the consept is the same for Mediapartners-Google bot.

鸠书 2024-12-01 05:06:36

Mediabot 是 Google 用于抓取网页以分析网页的网络抓取工具的名称。内容,以便 Google AdSense 可以向该页面投放上下文相关的广告。

根据我的经验,这是不可预测的,是的,它可能非常烦人

如果您不希望 Mediapartner 机器人访问特定页面,您可以在 robots.txt 中通过以下方式禁止它:

#
# disallow adsense bot
#
User-agent: Mediapartners-Google
Disallow: path to your specific page

这会带来从该特定页面投放非定位广告的缺点。

如果您在同一页面上始终看到此模式具有不同的查询字符串,请添加 canonicalrel 可以缓解痛苦。

如果您无法解决此问题,并且将其视为滥用行为,请立即在 Google 抓取索引和排名支持

Mediabot is the name given to the web crawler that Google uses to crawl webpages for purposes of analysing the content so Google AdSense can serve contextually relevant advertising to the page.

In my experience, it is impredictable and, yes , it can be pretty heavy and annoying.

If you don't want Mediapartner bot to access a specific page, you can disallow it in your robots.txt with:

#
# disallow adsense bot
#
User-agent: Mediapartners-Google
Disallow: path to your specific page

This will have the drawback of service untargeted ads from that specific page.

If you are seeing this pattern always on the same page with different query string, adding the canonical rel could ease the pain.

If you can't resolve this issue, and you see it as an abuse, don't esitate to ask help in the Crawling Indexing and Ranking Google support.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文