Help improve the Google Publisher Tag developer experience. Share your thoughts in our survey.
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.

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 PubAdsService.collapseEmptyDivs(). 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 PubAdsService.collapseEmptyDivs(true). 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