Ram Gandhapuneni
Ram Gandhapuneni

Reputation: 566

Google Publisher Tag(GPT) ad call returning a bad request

We are trying to convert DFP ad calls on our site into GPT ad calls with asynchronous rendering with single request mode. We arte trying to make a proof of concept page with ads. But the page doesnt seem to display any ads..... Below is the code I modified from https://support.google.com/dfp_premium/bin/answer.py?hl=en&answer=1638622&topic=28788&ctx=topic

Seems to receive a bad request in response to the ad call...and the ad divs are empty

<html>
<head>
<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.pubads().set("adsense_background_color", "000000");
  });
</script>
<script>
  googletag.cmd.push(function() {
    googletag.defineSlot("/N6752/adj/hw.bd/home",[728, 90], "div-gpt-ad-123456789-0")
      .addService(googletag.pubads());
    googletag.defineSlot("/N6752/adj/hw.bd/home", [300, 250] , "div-gpt-ad-123456789-1")
      .addService(googletag.pubads());
     googletag.pubads().enableSingleRequest();
     googletag.enableServices();
   });
 </script>
</head>
<body>
  <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>
    <div id="div-gpt-ad-123456789-1">
    <script type="text/javascript">
      googletag.cmd.push(function() {
          googletag.display("div-gpt-ad-123456789-1");
      });
    </script>
  </div>
</body>
</html>

Upvotes: 2

Views: 5385

Answers (1)

Glenn Stevens
Glenn Stevens

Reputation: 2008

Right off I see two issues with the googletag.defineSlot portion of your calls:

  1. When using asyncronous ad calls in single request mode you do not need to prefix the network code with a 'N' like you do when using the old style JavaScript style ad calls. So in your case it should be /6752/ not /N6752/
  2. For the targeted ad unit /adj/hw.bd/home you have included the old tag indicating the type of ad slot at the begining /adj/. You do not need to pass this in the asyncronous ad calls in single request mode like you did when using the old style JavaScript style ad calls. Instead you should just pass in the ad unit /hw.bd/home

After fixing those two issues your code:

<script>
  googletag.cmd.push(function() {
    googletag.defineSlot("/6752/hw.bd/home",[728, 90], "div-gpt-ad-123456789-0")
      .addService(googletag.pubads());
    googletag.defineSlot("/6752/hw.bd/home", [300, 250], "div-gpt-ad-123456789-1")
      .addService(googletag.pubads());
    googletag.pubads().enableSingleRequest();
    googletag.enableServices();
   });
</script>

is no longer returns a 'Bad Request' response. The calls are still not returning actual creatives and are instead returning DFP's default respose so I suspect you still either need to verify you have ads targeted for the given slot/size OR you may have to pass in additional key/value targeting parameters using .setTargeting after the calls to .addService i.e. .setTargeting("key", "value");

<script>
    googletag.cmd.push(function () {
    googletag.defineSlot("/6752/hw.bd/home", [728, 90], "div-gpt-ad-123456789-0")
        .addService(googletag.pubads())
        .setTargeting("key", "value");
    googletag.defineSlot("/6752/hw.bd/home", [300, 250], "div-gpt-ad-123456789-1")
        .addService(googletag.pubads())
        .setTargeting("key", "value");
    googletag.pubads().enableSingleRequest();
    googletag.enableServices();
});
</script>

More information on this can be found at the same link https://support.google.com/dfp_premium/bin/answer.py?hl=en&answer=1638622 you referenced in your question by lookin in the right hand column where the document has detailed comments on the sample code.

Upvotes: 5

Related Questions