I am using Google publisher tags to fetch the ads.
How to check whether I am getting an ad or any empty ad for an specific ad slot. I am using the below code.
googletag.defineSlot("/1234/travel", [[300,250],[300x600]], "div-gpt-ad-123456789-0"))
<div id="div-gpt-ad-123456789-0" style="width: 728px; height: 90px">
<script type="text/javascript">
googletag.cmd.push(function() {
googletag.display("div-gpt-ad-123456789-0");
});
</script>
</div>
How to check this div("div-gpt-ad-123456789-0") contains an ad or not?
You could do something like this:
googletag.pubads().addEventListener('slotRenderEnded', function(event) {
if (event.slot.getSlotElementId() == "div-gpt-ad-123456789-0") {
var containsAd = !event.isEmpty;
}
});