Home / Tools / Google Ad Manager
✦ Google Ad Manager

Google Ad Manager GPT tag generator

Enter your network code and ad units and get ready-to-paste Google Publisher Tag code: the gpt.js loader and slot definitions for <head>, and one div with display() for every slot.

Network and ad units

In Ad Manager: Admin → Global settings → Network code. Every ad unit path starts with it.

Ad slots

Sizes: 300x250, several separated by commas (300x250, 336x280), or fluid for native and responsive ads.

Page options

One key=value per line, several values separated by commas. Applies to every slot on the page. Create the keys in Ad Manager under Inventory → Key-values.

Your GPT code

googletag.setConfig() is the current API. Google marks enableSingleRequest, collapseEmptyDivs, enableLazyLoad and pubads().setTargeting as deprecated.

1. In <head>

2. In <body>, where each ad should appear

Checks

How the Google Publisher Tag works

The Google Publisher Tag (GPT) is the JavaScript library that requests ads from Google Ad Manager. The <head> part loads gpt.js asynchronously from securepubads.g.doubleclick.net and queues your setup in googletag.cmd, so it runs as soon as the library is ready without blocking the page.

Inside that queue, googletag.defineSlot() tells GPT the ad unit path (/networkcode/ad-unit/child-ad-unit), the sizes the slot accepts and the div id it fills. addService(googletag.pubads()) attaches the slot to the publisher ads service, and googletag.enableServices() switches it on. Page-wide settings such as single request, lazy load, collapsing and targeting go before enableServices().

In the <body>, each slot needs a div with the same id and a call to googletag.display(). With single request on, the first display() fetches every slot defined in the head in one request.

A size mapping limits which of the slot's sizes may serve at which viewport: GPT uses the largest viewport line that fits the browser, width first, then height. Build one with the size mapping generator.

Frequently asked questions

Where do I find my Ad Manager network code?

In Google Ad Manager, open Admin, then Global settings. The network code is a number such as 1234567, and every ad unit path starts with it: /1234567/site/section.

Should I use googletag.setConfig or pubads() methods?

Use googletag.setConfig() for new tags. Google's GPT reference marks enableSingleRequest(), collapseEmptyDivs(), enableLazyLoad() and pubads().setTargeting() as deprecated in favour of the singleRequest, collapseDiv, lazyLoad and targeting settings. The old methods still work, so switch to the legacy output only to match an existing setup.

What does the fluid size do?

A fluid slot takes 100% of the width of its parent div and resizes its height to fit the creative. It's used for native ads. You can list it on its own or together with fixed sizes, e.g. 300x250, fluid.

Can lazy load and single request be used together?

Yes. With both on, GPT sends one request for all slots when the first slot comes within the fetch margin, instead of one request per slot as it scrolls into view.

Why is my ad slot empty?

Check that the div id in the body matches the id in defineSlot exactly, that the ad unit path exists and is active in Ad Manager, that a line item targets it with a size the slot accepts, and that display() runs after the div is on the page. New ad units can take a while before they serve.

Related guides

More free tools