刷新其中包含 Google 广告的 Div

发布于 2024-07-11 19:56:37 字数 576 浏览 10 评论 0原文

我有一个包含 Google 广告的

。 我的网站主要是 AJAX,不需要刷新浏览器。 这意味着我的广告也不会刷新,这并不理想,因为用户整天盯着一个广告。

所以我想要一种方法来刷新页面上的特定

。 我找到了很多解决方案,但它们都不起作用。 例如,使用JQuery的html功能:

$("#ads").html("google ad script here");

这设法刷新整个页面,不知道如何。 我还可以向包含 Google 广告的 HTML 页面发出 AJAX 请求,但我猜测它会具有与上述尝试相同的效果。

我不想使用 iFrame。

我还有其他选择吗? 我的豌豆脑子已经想不起来了。 :)

编辑:

这是允许的,因为只有当用户单击链接时我才会启动刷新。

一个典型的例子是 Yahoo Mail - 他们的新 AJAX 邮箱使用相同的方法,当用户单击链接时,就会显示一个新广告。

I have a <div> that holds a google ad. My website is mostly AJAX and there is no need for a browser refresh. That means my ads will not refresh either, which isn't ideal, a user staring at one ad all day.

So I wanted a way to refresh a particular <div> on a page. I found many solutions but they didn't work. For example, using JQuery's html function:

$("#ads").html("google ad script here");

This managed to refresh the whole page no idea how. I can also make an AJAX request to a HTML page that contains the Google ad but I am guessing it will have the same effect as the above attempt.

I do not want to use iFrames.

Is there any other option open to me? My pea brain can not think of anymore. :)

EDIT:

It is allowed since I will be initiating the refresh only when a user clicks a link.

A prime example is Yahoo Mail - their new AJAX mailbox uses this same method, when a user clicks a link then a new ad is shown.

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

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

发布评论

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

评论(7

℡寂寞咖啡 2024-07-18 19:56:38

正如其他两个答案所述,不允许自动刷新您的 AdSense 广告。 据我了解,您只想刷新广告以响应用户操作,但仍然不允许,尽管应该这样做!

请记住,您想要更新广告的原因是为了展示新广告。 显示广告称为“印象”。 当您使用代码刷新广告时,您将自动生成广告展示次数。

AdSense 计划政策< /a> 状态(强调我的):

无效点击和展示

Google 广告的点击必须源于真正的用户兴趣。 严格禁止任何人为地在您的 Google 广告上产生点击或展示的方法。这些被禁止的方法包括但不限于重复手动点击或展示、使用机器人、自动点击和展示生成工具、第三方产生点击或展示的第三方服务,例如付费点击、付费冲浪、自动冲浪和点击交换程序或任何欺骗性软件。

刷新广告违反了产生印象的规则。 话虽如此,我认为任何有理智的人都会同意,在 AJAX 应用程序中刷新广告以响应用户行为(例如响应点击)并不违反精神< /em> 规则。

例如,想象一下重写整个应用程序以停止使用 AJAX。 对于您的用户来说,这显然是更糟糕的体验(速度较慢,每次点击时页面都会闪烁,页面无法在后台动态更新),但从技术角度来看,这并不违反 AdSense 计划政策。

显然,Google 的意思是禁止每五秒自动更换一次广告(创建广告“幻灯片”)。 谷歌还打算禁止通过看似比实际访问量更多的方式让您的网站对广告商更具吸引力。 我确信他们并没有打算阻止您设计高性能 AJAX 网站...但不幸的是,有时规则会产生意想不到的后果。

当然,正如您最初指出的那样,如果您将广告嵌入 iframe 并修改其位置,您仍然可以刷新广告。 (这里介绍如何在 AJAX 应用程序中使用 iframe 来刷新 AdSense。)

您在最初的问题中拒绝了 iframe,也许是因为您知道使用 iframe 会违反 Google 的政策...但如果您坚持违反规则,您可能会这样做我们一路打破他们! ;-)

最终,我认为您会发现以这种方式产生印象并不值得冒险:您“刷新”广告只会发现 Google 只向您展示与以前完全相同的广告。

As both of the other answers state, refreshing your AdSense advertisements automatically isn't allowed. I understand that you only intend to refresh the ad in response to user action, but it still isn't allowed, even though it should be!

Remember, the reason why you want to update the advertisements is so that you can show new ones. Displaying an advertisement is called an "impression." When you use code to refresh the ads, you are automatically generating ad impressions.

AdSense Program Policies state (emphasis mine):

Invalid Clicks and Impressions

Clicks on Google ads must result from genuine user interest. Any method that artificially generates clicks or impressions on your Google ads is strictly prohibited. These prohibited methods include but are not limited to repeated manual clicks or impressions, using robots, automated click and impression generating tools, third-party services that generate clicks or impressions such as paid-to-click, paid-to-surf, autosurf, and click-exchange programs, or any deceptive software.

Refreshing your advertisements is a violation of the letter of the rule against generating impressions. With that said, I think any reasonable person would agree that refreshing advertisements in an AJAX app in response to user behavior (e.g. in response to a click) isn't a violation of the spirit of the rule.

For example, imagine rewriting your entire app to stop using AJAX. That's clearly a worse experience for your users (it's slower, the page flashes on every click, the page can't dynamically update in the background), but, by a technicality, it's not a violation of the AdSense Program Policies.

Clearly Google meant to prohibit automatically replacing the advertisements every five seconds (creating a "slideshow" of advertisements). Google also meant to prohibit making your site look more attractive to advertisers by appearing to have more visits than you actually have. I'm sure they didn't intend to prevent you from designing a high-performance AJAX website... but unfortunately sometimes rules have unintended consequences.

Of course, as you originally pointed out, you CAN still refresh your advertisements if you embed them in an iframe and modify its location. (Here's how to use iframes in an AJAX application to refresh AdSense.)

You rejected iframes in your initial question, perhaps because you knew that using iframes would violate Google's policies... but if you insist on breaking the rules, you might as well break them all the way! ;-)

Ultimately, I think you'll find that generating impressions this way isn't worth the risk: you'll "refresh" the ads only to find that Google is just showing you the exact same ads as before.

南街九尾狐 2024-07-18 19:56:38

新的 Google DFP“标签”专门允许“AJAX 广告刷新”

刷新

pubService.refresh(槽)
使用新广告刷新页面上指定的广告位数组。

参数:

数组槽 - 要刷新的可选槽数组。 如果未提供,则刷新所有广告位。
示例:

var slot1 = googletag.defineUnit("/1234567/leaderboard", [728, 90], "div-1").addService(googletag.pubads());

var slot2 = googletag.defineUnit("/1234567/skyscraper", [160, 600], "div-2").addService(googletag.pubads());

// 调用刷新会为每个广告位提取一个新广告

googletag.pubads().refresh([slot1, slot2]);
http://support.google .com/dfp_sb/bin/answer.py?hl=zh-CN&answer=2372721&expand=pubservice_details#refresh

The new Google DFP 'tags' allow specifically 'ad refreshing for AJAX'

refresh

pubService.refresh(slots)
Refreshes the specified array of slots on the page with new ads.

Parameters:

array slots - Optional array of slots to refresh. If not supplied, all ad slots are refreshed.
Example:

var slot1 = googletag.defineUnit("/1234567/leaderboard", [728, 90], "div-1").addService(googletag.pubads());

var slot2 = googletag.defineUnit("/1234567/skyscraper", [160, 600], "div-2").addService(googletag.pubads());

// The call to refresh fetches a new ad for each slot

googletag.pubads().refresh([slot1, slot2]);
http://support.google.com/dfp_sb/bin/answer.py?hl=en&answer=2372721&expand=pubservice_details#refresh

轻许诺言 2024-07-18 19:56:38

我知道我迟到了一年半,但是......广告的问题可能是他们正在使用 document.write (广告服务器因此而臭名昭著,但我不知道 AdSense 是否使用它。)

如果是这样,我有一个可以提供帮助的库:writeCapture.js。 示例:

$('#ads').writeCapture().html('<script src="whatever-your-adsense-code-is"> </script>');

这是使用 jQuery,但也有一个独立版本。

至于是否违反服务条款... Gmail 会动态更改广告,因此情况不会那么糟糕。 只要内容也在改变,我认为就可以了。

I know I'm a year and a half late to the party, but... It's possible that the problem with the ads is that they are using document.write (Ad servers are notorious for this, but I don't know if AdSense uses it or not.)

If that's the case, I have a library that can help: writeCapture.js. Example:

$('#ads').writeCapture().html('<script src="whatever-your-adsense-code-is"> </script>');

That's using jQuery, but there is also a standalone version.

As for whether it's a TOS violation... Gmail changes ads dynamically, so it can't be that bad. As long as the content is changing too, I would think it was OK.

浅暮の光 2024-07-18 19:56:38

您可以使用以下代码刷新 Google 广告位。 将其放入要刷新广告的 JS 函数中。 它应该刷新页面上的所有广告。

if ( undefined !== googletag ) {
  googletag.pubads().refresh();
}

Google Ad Manager 帮助 - 无需刷新页面即可重新加载广告

You can refresh the Google Ad Slots with the following code. Put this in the JS function you want to refresh the Ads. It should refresh all of the ads on the page.

if ( undefined !== googletag ) {
  googletag.pubads().refresh();
}

Google Ad Manager Help - Reload ads without a page refresh

两仪 2024-07-18 19:56:38

只需将广告包含在您通过 ajax 加载的页面中即可。 通过 ajax 按页面从文件加载广告不会有任何问题。

如果我加载有一些内容和广告的 Read.inc
单击页面上的某个内容,您将进入 Make.inc,其中包含内容和广告。

这有什么问题吗? 那是有机的。 将广告作为内容的一部分加载一次。

这与单击链接相同。

我还没有真正尝试过,但这看起来确实合乎逻辑。

Just include the ads in the pages you are loading via ajax. There can be nothing wrong with loading the ads from a file via ajax on a per page basis.

if I load Read.inc which has some content and an ad
Click something on the page and it takes you to Make.inc which has content an an ad.

Whats wrong with that? That's organic. One load with the ad as part of the content.

It's the same as clicking a link.

I haven't actually tried this yet, but it certainly seems logical.

成熟稳重的好男人 2024-07-18 19:56:38

不允许(根据 AdSense 条款)在页面生命周期内尝试重新加载广告。 而且,这几乎不可能(由于平台架构)。

It is not allowed (according to AdSense terms) to try and reload ads during the page life-cycle. Also, it is hardly possible (thanks to the platform architecture).

彩虹直至黑白 2024-07-18 19:56:38

不允许。 但我认为你可以使用 iframe 来实现这一点。 我看到了很好的教程。
我尝试通过 ajax 回滚我对 Adsense TOS 的更改

It is not allowed. but I think you can use a iframe for that. I saw good tutorials of that.
I tried do it by ajax by I rollback my changes for the Adsense TOS

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