Remove empty ad slot
This commit is contained in:
1 parent
f9c2c4153d
commit
d388c2c563
1 file changed
+19
@@ -90,5 +90,24 @@ const page = Astro.url;
|
||||
}
|
||||
|
||||
googletag.enableServices();
|
||||
|
||||
googletag.pubads().addEventListener('slotRenderEnded', function (e) {
|
||||
if (!e.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
const slotId = e.slot.getSlotElementId();
|
||||
if (!slotId) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If empty, hide the ad slot after a small delay.
|
||||
setTimeout(() => {
|
||||
const adContainer = document.getElementById(slotId);
|
||||
if (adContainer) {
|
||||
adContainer.style.display = 'none';
|
||||
}
|
||||
}, 1800);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
Reference in new issue
Block a user