Script outside the head
Each component's script goes in the head, and the ad goes in the body. Without the right script, the component does not work.
Implementation guide
AMP ads (amp-ad, amp-auto-ads, amp-sticky-ad)
How to show ads on AMP pages with amp-ad, Auto ads and a sticky bar, in AdSense and Ad Manager.
Understand it in 1 minute
AMP is a way to build very light and fast pages, created as an open project. Imagine a lunch box with compartments: everything has its own little spot and you cannot throw just anything in there. An AMP page is the same. You cannot paste just any ad code. Instead, you use ready-made pieces, called components, that already know how to request and show ads without making the page heavy.
There are three main pieces. The amp-ad is the regular ad space, like a banner: you say the network type, adsense for AdSense or doubleclick for Ad Manager, and provide the width and height. The amp-auto-ads is the automatic mode: it receives a configuration from the network and chooses on its own where to place ads, respecting a maximum number and a minimum distance between them. The amp-sticky-ad is the strip that stays pinned to the bottom of the screen, like an anchor, and has a close button.
The ad network's code does not run directly on the page. It runs in a separate little box, called an iframe, which AMP itself controls. If no ad arrives, AMP tries to hide the empty space, but it does not hide a space that is on screen, so the page does not jump. AMP ads also cannot sit inside fixed-position boxes, except AMP's own sticky ads and the amp-lightbox.
Google explains that AMP is an open project that aims for fast pages with good performance on any device. In AdSense, you create an ad unit and choose the AMP code, or turn on Auto ads for AMP. In Ad Manager, you generate AMP tags straight in the dashboard, and Google recommends using HTML ads for AMP. It is worth using if your site already has AMP versions of the pages and you want them to show ads too.
Step by step
Implemented example
<!-- No <head> da página AMP -->
<script async custom-element="amp-ad"
src="https://cdn.ampproject.org/v0/amp-ad-0.1.js"></script>
<script async custom-element="amp-auto-ads"
src="https://cdn.ampproject.org/v0/amp-auto-ads-0.1.js"></script>
<script async custom-element="amp-sticky-ad"
src="https://cdn.ampproject.org/v0/amp-sticky-ad-1.0.js"></script>
<body>
<!-- AdSense: anúncios automáticos, logo depois de abrir o body -->
<amp-auto-ads type="adsense"
data-ad-client="ca-pub-0000000000000000">
</amp-auto-ads>
<!-- AdSense: bloco responsivo, onde o anúncio deve aparecer -->
<amp-ad width="100vw" height="320"
type="adsense"
data-ad-client="ca-pub-0000000000000000"
data-ad-slot="1234567890"
data-auto-format="rspv"
data-full-width>
<div overflow></div>
</amp-ad>
<!-- Ad Manager: faixa fixa embaixo (só uma por página) -->
<amp-sticky-ad layout="nodisplay">
<amp-ad width="320" height="50"
type="doubleclick"
data-slot="/1234567/exemplo">
</amp-ad>
</amp-sticky-ad>
</body>What Google recommends
Tips
Watch out
Each component's script goes in the head, and the ad goes in the body. Without the right script, the component does not work.
AdSense gives you the ready-made AMP code when you choose the AMP option. Copy the code from your account, with your publisher ID.
The amp-sticky-ad needs the nodisplay layout and a single amp-ad inside it.
AdSense asks that the regular page and the AMP page point to each other, with the amphtml and canonical markups.
Use the AMP code. On AMP pages, the ad network's JavaScript does not run directly on the page, but in an iframe controlled by AMP.
AMP tries to hide the space. If it cannot, it shows the fallback. The sticky strip with no ad does not appear.
Yes, for Fast Fetch ads. You put a markup in the head with the interval, at least 30 seconds, per page or per slot. It does not work together with SRA.
Usually a few minutes, and sometimes up to an hour.
Library
Everything on this page follows Google's official documentation. Read it straight from the source:
The audit reads the site as a visitor would, without clicking anything, and shows what to fix.