MynaG's Bits n Bytes

26 Dec, 2013

Hide to stop showing empty ads using Google’s DoubleClick for Publisher.

Posted by: mynag In: Blogs|online marketing & SEO|Solution & Tips|Wordpress

Introduction

If you have been using DoubleClick for Publishers (DFP) to monetize your website, then you probably know that once your ad campaign has ended or an ad line item has pass its End Time, the ad unit will stop showing the creatives assigned for the ad unit and it will instead display an empty blank space. However, if you enabled Adsense inventory settings in the Ad unit settings, Google Adsense ads will be shown in that ad unit.

Showing Adsense ads is a very good way to maximize revenue of the unsold and remnant inventory for your ad units, but there are times where you might want some particular ad units to be specifically used only for direct advertisement. To do that, you would have to first make sure you disable the Adsense inventory settings. Once you have done that, Adsense ads will stop displaying for unsold inventory.

Problem

Here comes the problem. A blank empty space with the size similar to that of what you assigned for the ad unit will appear on your web page exactly where you have placed that ad unit. So, if you have a 300×250 medium rectangle ad unit at the top of your side bar followed by some other stuffs such as your most recent posts links, you would have a blank empty space with a width of 300 and a height of 250 shown above the rest of the items at the sidebar which is a pretty undesirable look and it is not how you want to your webpage to be layout in that manner.

Solution

The best way is that you would want to remove that empty ad space and let the items below the ad unit at the sidebar to fill it up the void space. To do that, you do not have to physically remove the ad unit from the space by removing the Ad unit tags, because you would want to hide the ad unit ONLY when it is empty or when there is no advertisement items to be displayed in that unit. And when there is an advertisement banner assigned to be displayed in that ad unit, it would appear again automatically. So here’s what you do to prevent an empty ad unit from showing, add the following line of code into the Google Publisher tag¬†which you have placed in your header of your web page just above the line “googletag.enableServices();”.

googletag.pubads().collapseEmptyDivs(); // hide ad units when empty.

For example in this header of a webpage,

<!DOCTYPE HTML>
<html lang=”en-us”>
<head>
<meta http-equiv=”Content-type” content=”text/html; charset=utf-8″>
<title>Widgets Magazine</title>
<style type=”text/css” media=”screen”>
</style>

<!– GOOGLE PUBLISHER TAG –>

<script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
</script>

<script type='text/javascript'>
googletag.cmd.push(function() {
googletag.defineSlot('/10099999/Sidebar_Top_Adunit', [300, 250], 'div-gpt-ad-139999999-0').addService(googletag.pubads());
googletag.defineSlot('/10099999/Sidebar_Bottom_Adunit', [300, 250], 'div-gpt-ad-13999999-1').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.pubads().collapseEmptyDivs(); // hide ad units when empty.
googletag.enableServices();
});
</script>

</head>

No Responses to "Hide to stop showing empty ads using Google’s DoubleClick for Publisher."

Comment Form

Categories

About

Welcome to MynaG's Bits and Bytes. My little journal containing bits and bytes of the internet, web programming and etcetera