AdSense Responsive Ads

:warning: IF YOU ARE RUNNING AN AD BLOCKER RIGHT NOW YOU WILL HAVE A VERY BAD TIME TRYING TO SET THIS UP! TURN IT OFF BEFORE PROCEEDING DOWN THIS PATH! You’ve been warned. :dragon:

Google AdSense offers the option to show ads with a size of Google’s choice using the responsive ad size option.

:warning:

Note that responsive ads are an all-or-nothing option. You can’t limit the height and width of them. They will cause jumpy behaviour when scrolling within a topic.

It is recommended to use fixed size ads instead.

Defining your AdSense ad units

Simply define your ad unit(s) in AdSense using the responsive option:

It can take a few hours before AdSense has any inventory to show in the ad unit, so it’s useful to define some fallback creative in the “If no ads available” field to verify that the ad unit is working and to see which ad sizes AdSense is choosing.

Once you create the ad unit, it will show up in your ad units list with a numbered ID. You’ll need the ID to enter in Discourse.

Discourse Settings

On your Discourse instance, go to Admin > Settings > AdSense. Enter your publisher ID as usual (the number after pub-), enter the ad unit ID in the location(s) where you want it to appear, and choose “responsive” as the size.

Current limitations require you to set a very permissive policy using the content_security_policy_script_src site setting. See below:

Controlling Ad Sizes

There is no way to control responsive ad sizes anymore due to changes made by Google. See discussion later in this topic.

@neil thanks a million. This simplifies things wonderfully for using Adsense in a multi-device world. Great work.

A simple like is not enough - this is a massive improvement. Only thing missing is that desktop view ads are not resized if the window is. I have no idea how feasible this is and it is quite an outlier use case. Mobile view scales nicely when the device is rotated 90-degrees.

So great work!

P.S. Server cost whiners - if you have traffic, this can roughly compensate the costs.

Ads that are already rendered won’t be re-sized since we would need to ask the AdSense javascript library to re-fetch the ad (and I don’t remember there being any way to do that). The next time an ad unit is rendered, it should pick up the new view size anyway.

Glad it’s working out well for you!

@neil I would need a little hand holding with this.

On mobiles (with full HD screens or better) the responsive setting has started to increasingly show large square banners in the top banner positions. This drops the majority of the content below the fold.

I tried mocking around based on your CSS example but could not nail it. I would like to halve the top banner height, making it a large mobile banner (320x100). How could I achieve that?

What CSS did you use, and how did you add/enable it? Which ad units are you trying to limit the height?

It should be this if you want it to be 100px height of the ad unit above the topic lists:

:warning:

This doesn’t work anymore

.adsense-topic-list-top.adsense-responsive {
  height: 100px;
}

Thanks, I’ll give that a try tomorrow or later this week.

Been using the responsive ads for a full year, since my earlier praise in this thread. For some reason the large square ad format has increased popularity as time went by. Originally I got the large mobile banners, but now more squares.

Thanks, I’ll report back later.

@neil

Now I just realized that the code you pasted above was identical to the earlier. The reason I had issues implementing was that for some reason it does not work correctly in the Chrome Inspector / Mobile mode (the ad remains square and topics flood over it), but now when I implemented it again and verified on real devices, the results look as expected.

I’ll ask my community to verify this to get some device diversity.

Update: Well, our community is the best and had already spotted layout breakage. This happens on some Android devices at least.

I can see square ads in Chrome on Android too, and sometimes banner ads. I don’t see it underneath the topic list content though… Which devices are people seeing layout problems?

Also, I don’t see the CSS to control height, which would prevent the square ads.

Sony XZ, Honor 7 and OnePlus 5T were used by those who reported. The screen capture was taken with the Sony phone.

And you want to allow square ads, which is why you didn’t add the custom css with height?

@neil 再次感谢您开发这个插件——对于我们的社区而言,这一组件是决定成败的关键功能,而我们的社区运营没有任何其他资金支持。

自该功能引入插件以来,我一直使用带有响应式设置的 AdSense 横幅。然而最近,响应式广告开始出现问题:我似乎收到了更大的广告单元,破坏了预期的用户体验(首屏广告内容过多)。此外,我还收到了对于我的 iPhone SE 来说过大的广告,除非将设备横屏,否则屏幕上会出现大片空白区域。

我查看了设置,发现广告尺寸现在是一个多选选项。我尝试在此处搜索,但未能找到关于该多选功能实际工作原理的说明——如果我选择了多个尺寸,会显示哪些广告尺寸,以及在什么情况下显示?

如果您选择了多个尺寸,广告单元将均匀地在这些尺寸之间交替显示。例如,您可以在同一个广告位中交替显示横幅广告和方形广告。

至于您遇到的广告高度问题,您可以尝试为广告位添加高度规则,就像本主题的第一个帖子中展示的那样:

:warning:

此方法已不再有效!

顺便提一下,我从未成功实现响应式元素尺寸控制。最近注意到谷歌在九月份对响应式单位进行了一些更新。

支持最大高度/宽度将是该插件的一个绝佳功能,并且会让固定尺寸选项变得多余。这或许值得在开发路线图中考虑?

您现在就可以实现这一功能,请查看本主题首帖中的**(可选) 控制广告尺寸**部分。

顺便一提,我从未让响应式元素尺寸控制正常工作过

但这并不是重点。我已经尝试过多次,但出于某种原因,它在当前场景下无法按原样工作。

这样做的好处本应是简化插件设置视图,而该视图目前相当杂乱。

我不知道你在提议什么,但我发现了这篇文章,它似乎表明响应式广告现在可以忽略其容器。

…响应式广告单元现在可以调整其所在的 HTML 父容器(例如 <div>)的大小。这使得它们能够自动适应发布商页面上的各种广告尺寸。

请注意,要使响应式广告单元正常工作,它们不得放置在具有固定或有限高度的容器内。

不错。:frowning:

如果您想限制响应式广告的高度,则需要修改响应式广告代码…

<ins class="adsbygoogle" style="display:inline-block;min-width:400px;max-width:970px;width:100%;height:90px"

所以,就像以前使用容器和 CSS 那样做同样的事情,但改用内联样式,以便让 Google“自动适应各种广告尺寸”,不管那是什么意思。

但是,他们的示例显示使用 CSS 仍然有效:@ljpp 请看这篇文章:

你确定你没有尝试使用 CSS 来控制响应式单元的最大宽度/高度吗?这两篇文章相互矛盾,所以也许他们的示例已过时。


正在获取广告信息,但未显示任何广告。

为什么广告位只显示“advertisement”这个词?这是我的配置!Screenshot_20191209-180110|281x500, 50%

大家好,我发布这条消息是想就广告带来的一个反复出现且令人非常烦恼的问题寻求一些反馈:

在移动设备上,帖子经常会在页面所有内容加载完毕后上下“跳动”(暂且这样描述),导致某些帖子极难阅读,因为这种非自愿的垂直滚动。屏幕无法稳定在帖子上,一旦用户试图将其重新置于视野中央,它就会跳动。我认为这是由广告引起的,因为当没有广告时,这个问题就会消失。我的配置完全正确,Discourse 上的响应式广告与 AdSense 上的响应式广告代码相对应。

是否有人遇到过这种行为?
这是否与 AdSense 一直在试图“决定”广告高度有关?