elizabk
elizabk

Reputation: 480

Collapse empty div of passback tag ad

Background

We use Google Ad Manager (formerly DFP) as an ad publisher for our own site. We don't want to always traffic house ads, so we're collapsing all empty divs.

slot.setCollapseEmptyDiv(true, true);

We're starting to do some programmatic ads, so we provided the third-party networks with passback tags for a specific ad unit that has some house ads line items.

<script src='https://www.googletagservices.com/tag/js/gpt.js'>
  googletag.pubads().definePassback('/123456789/PassbackAdUnit', [728, 90]).display();
</script>

The Problem

The line items in the PassbackAdUnit are all house ads, but we don't want to serve a very large amount of house ads. Those line items are set only serve a certain number or percentage of impressions. This causes the passback to somethimes result in no line item available to serve.

We would like the div to collapse as all empty ad divs do. But in this case it's not collapsing, and Publisher Console is showing the slot to be filled with the programmatic ad.

How can I make this empty div collapse?

Upvotes: 2

Views: 1470

Answers (1)

rabsom
rabsom

Reputation: 859

I found a way to collapse your empty passback, using the slotRenderEnded event listener :

<script src='https://www.googletagservices.com/tag/js/gpt.js'>
googletag.pubads().definePassback('/123456789/PassbackAdUnit', [728, 90]).display();
googletag.cmd.push(function () {
            googletag.pubads().addEventListener('slotRenderEnded', function (event) {
                if (event.isEmpty) {
                //if adcall is empty, then display none on the parent frame
                top.document.getElementById(this.frameElement.id).style.display = "none";
                }
            });
        });
</script>

This workaround is not perfect : the adslot will be displayed empty until the passback adcall ended. Then the parent iframe will be hidden.

Upvotes: 0

Related Questions