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?
googletag.Constructs an ad slot with a given ad unit path and size and associates it with the ID of a div element on the page that will contain the ad. Example. googletag. defineSlot('/1234567/sports', [728, 90], 'div-1'); See also.
Google Publisher Tag (GPT) is an ad tag library that allows publishers to define inventory, initiate and bundle ad requests, and render matching demand. GPT takes key details from you (such as ad unit code, ad size, and key-values), builds the request, and displays the ad on web pages.
Other options to open the Publisher ConsoleAfter loading the page, enter javascript: googletag. openConsole() in your browser's JavaScript console and run the code. Developer Tools. Click Console.
Google Publisher Tag is an ad tagging library that helps publishers to build ad requests dynamically. Publishers can get better control creating and serving ads on the inventory through GPT. Not only it enables a publisher to define ad settings in the code itself but also sets targeting options for different ad slots.
In our getting started and basic concept examples, the Google Publisher Tag (GPT) library's display () method is used to register and display an ad slot. However, there are times when it may be preferrable or even necessary to separate these actions, in order to more precisely control when ad content is loaded.
Google Ad Manager (Google DFP) is one of the reliable ad servers for publishers. This article aims to simplify one of its ad tag types ‘Google Publisher Tag‘, which is an overhaul of how usual ad tags work.
Using refresh () to replace the contents of ad slots that are never viewable can significatly lower your ActiveView rate. The ImpressionViewableEvent can be used to determine when an ad slot has become viewable, as in the example below.
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;
}
});
The GPT API provides a "SlotRenderEndedEvent" which fires when the ad is rendered ( or if nothing is returned )
https://developers.google.com/doubleclick-gpt/reference
You add the handler and check for isEmpty to determine if an ad has been served.
Also if you've enabled CollapsEmptyDivs for the ad slot, the ad div will be set to display:none by GPT so that is also a clue that nothing was returned.
You can use an on-screen debugging tool called the Google Publisher Console to troubleshoot delivery problems.Use "?googfc" as querystring. Reference: https://support.google.com/dfp_premium/answer/2462712?hl=en
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With