Not checking whether the slot came back empty
GPT returns null when the page does not support anchors. If the code does not check for this, it tries to use a slot that does not exist.
Implementation guide
Anchor ads
An ad strip that stays stuck to the top or bottom of the screen while the person scrolls the page, and that can be closed easily.
Understand it in 1 minute
The anchor ad is an advertising strip that stays stuck to the edge of the screen. Think of a fridge magnet: the door opens and closes, but the magnet stays in the same place. Here it is the same. The person scrolls the text up and down, and the strip stays still at the top or bottom of the screen. It sits on top of the page.
In AdSense, the anchor is part of Auto ads, in the group called overlay formats. Overlay means the ad sits on top of the page. Google explains that, by default, the anchor appears at the top of the screen and moves to the bottom when staying at the top would get in the person's way. The top one only appears after the person scrolls enough, so it never covers the site name or the menu. There is also the dynamic anchor, which can get bigger, shrink or move to a small corner of the screen as a small ad.
In Ad Manager, the anchor is handled by GPT, the Google Publisher Tag, which is the Google code that requests and displays ads on the page. You request a slot, which is the ad space, of the top anchor or bottom anchor type. GPT itself creates the ad box, so you do not need to design a space on the page. If the page or the device does not support this format, GPT does not create the slot.
Google says anchor is a high-performance format that follows the Better Ads Standards, which are rules so ads do not bother readers. The person can close the ad at any time by clicking the little arrow. On mobile and desktop, Google recommends requesting the anchor only on the pages where you want it to show. If the same code goes to both, it is worth defining when and where each one shows the anchor.
Step by step
Implemented example
<!-- AdSense (opcional): âncoras só no rodapé -->
<script async
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-0000000000000000"
data-overlays="bottom"
crossorigin="anonymous"></script>
<!-- Ad Manager (GPT): slot âncora -->
<script async
src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"
crossorigin="anonymous"></script>
<script>
window.googletag = window.googletag || { cmd: [] };
googletag.cmd.push(() => {
const anchorSlot = googletag.defineOutOfPageSlot(
"/1234567/exemplo",
googletag.enums.OutOfPageFormat.BOTTOM_ANCHOR // ou TOP_ANCHOR
);
// Volta null se a página ou o aparelho não aceitar âncora
if (anchorSlot) {
anchorSlot.addService(googletag.pubads());
}
googletag.enableServices();
if (anchorSlot) {
googletag.display(anchorSlot);
}
});
</script>
<!-- Teste: https://www.exemplo.com/#gamTopAnchorDemo
ou #gamBottomAnchorDemo -->What Google recommends
Tips
Watch out
GPT returns null when the page does not support anchors. If the code does not check for this, it tries to use a slot that does not exist.
The anchor needs a mobile-optimized page, with neutral zoom. This is usually solved with the viewport tag in the head.
With single request architecture (SRA), the first display request asks for all slots defined before it. If it comes before the fixed spaces exist on the page, ads are left out. Google recommends delaying that first call.
Anyone using the bottom parameter in the AdSense code turns on the anchor even with the option off in the dashboard. To really turn it off, remove the parameter too.
It can. In AdSense it works mainly on mobile, but also on a computer, and you control this with the option for screens wider than 1,000 pixels.
Yes. Google says the anchor is easy to dismiss, and in Ad Manager the person can close it at any time by clicking the arrow.
No. The anchor creates its own box. You only define the slot in GPT.
Yes. Out-of-stream video (not in-stream) is on by default, and the Block non-in-stream video ads protection must be turned off.
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.