amp-ad
简介
如何在您的 AMP HTML 文件中显示广告。
设置
在头部导入 amp-ad
组件。
<script async custom-element="amp-ad" src="https://cdn.ampproject.org/v0/amp-ad-0.1.js"></script>
基本用法
amp-ad
需要 width
和 height
值。通过 type 参数选择广告网络。
<amp-ad width="300" height="250" type="a9" data-amzn_assoc_ad_mode="auto" data-divid="amzn-assoc-ad-fe746097-f142-4f8d-8dfb-45ec747632e5" data-recomtype="async" data-adinstanceid="fe746097-f142-4f8d-8dfb-45ec747632e5">
</amp-ad>
占位符
可选地,amp-ad
支持带有 placeholder
属性的子元素。如果广告网络支持,则在广告可供查看之前会显示此元素。
这里是占位符!!!
<amp-ad width="300" height="200" type="doubleclick" data-slot="/4119129/doesnt-exist">
<div placeholder>
<b>Placeholder here!!!</b>
</div>
</amp-ad>
回退
amp-ad
支持带有 fallback
属性的子元素。如果广告网络支持,则当此广告位没有广告可用时,将显示此元素。
感谢您尝试 AMP!
您很幸运!我们没有广告可以向您展示!
<amp-ad width="300" height="200" type="doubleclick" data-slot="/4119129/doesnt-exist">
<div fallback>
<p>Thank you for trying AMP!</p>
<p>You got lucky! We have no ad to show to you!</p>
</div>
</amp-ad>
需要进一步解释?
如果此页面上的解释没有涵盖您所有的问题,请随时与其他 AMP 用户联系,讨论您的具体用例。
前往 Stack Overflow 未解释的功能?AMP 项目强烈鼓励您的参与和贡献!我们希望您能成为我们开源社区的长期参与者,但也欢迎您为特别感兴趣的问题做出一次性贡献。
在 GitHub 上编辑示例-
由 @sebastianbenz 撰写