Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check Google publisher tag ad slot is empty or not?

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?

like image 951
user2254912 Avatar asked Apr 07 '13 16:04

user2254912


People also ask

What is Googletag defineSlot?

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.

What are Google Publisher tags?

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.

How do I use Google Publisher Console?

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.

What is Google publisher tag?

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.

How do I register and display an ad slot in GPT?

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.

What is Google publisher tag (DFP)?

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.

How do I know when an ad slot becomes viewable?

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.


3 Answers

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;     
    }
});
like image 61
Federico J. Álvarez Valero Avatar answered Oct 02 '22 19:10

Federico J. Álvarez Valero


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.

like image 38
dougwig Avatar answered Oct 02 '22 18:10

dougwig


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

like image 29
Prasanna Jathan Avatar answered Oct 02 '22 17:10

Prasanna Jathan