[ Web Proxy ]
URL:
Viewing: https://developers.google.com/publisher-tag/samples/collapse-empty-ad-slots [Back]  [Original]

Collapse empty ad slots  |  Google Publisher Tag  |  Google for Developers Skip to main content
Send feedback Stay organized with collections Save and categorize content based on your preferences.

Collapse empty ad slots

By default, ad slots which are not filled are left visible, which may result in blank space on your page. If you know ahead of time that one or more ad slots on your page are unlikely to get filled, you can instruct the Google Publisher Tag (GPT) library to collapse them.

Caution: Incorrect use of this feature can cause additional reflow of the content of your page.

The optimal configuration of this feature will depend on how often you expect ad slots to be filled:

  1. If slots will be filled most of the time, use collapseDiv: 'ON_NO_FILL'. In this configuration, ad slots are expanded by default and collapse only if they cannot be filled.
  2. If slots will not be filled most of the time, use collapseDiv: 'BEFORE_FETCH'. In this configuration, ad slots are collapsed by default and only expand if they can be filled.

Because googletag API calls have no effect until GPT begins to run, to minimize reflow you will also need to configure the CSS on your page so that slots which are collapsed by default have zero dimensions.

It's also possible to configure per-slot overrides, as shown in the example below, if specific slots on your page are more or less likely to be filled.

Sample implementation

View demo

JavaScript

Loading...

Improve this sample Report an issue

TypeScript

Loading...

Improve this sample Report an issue
Need to tell us more? [[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],[],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page