prebid / Prebid.js

Setup and manage header bidding advertising partners without writing code or confusing line items. Prebid.js is open source and free.
https://docs.prebid.org
Apache License 2.0
1.28k stars 2.05k forks source link

When using passback the page doesn't stop loading #752

Closed Rubioli closed 7 years ago

Rubioli commented 7 years ago

I dont use DFP in my application for prebid and because of that I use Postbid Example from prebid.org.

One of the reasons I used that example is since I can do PassBacks without needing DFP and this is what I do to get the passback:

      if (params && params['hb_adid']){
        pbjs.renderAd(iframeDoc, params['hb_adid']);
        console.log(params['hb_bidder'], params['hb_pb']);
      } else {
        // If no bidder return any creatives, run passback.
        iframe.width = tagWidth;
        iframe.height = tagHeight;
        iframeDoc.write(passbackTagHtml);
        console.log('HB: PassBack');
      }

And here is my whole code PS: I already add the prebid.js in <head>:

var tagWidth = 300;
var tagHeight = 250;

var bidTimeOut = 1000;
var passbackTagHtml = '<iframe src="http://www.w3schools.com"></iframe>';

var bids = [
  {
    bidder: 'aol',
    params: {
      placement: '4303226',
      network: '29889.1',
      bidFloor: '0.2'
    } },

  {
    bidder: 'defymedia',
    params: {
      placementId: '9753647'
    } },
];

/* prebid.js v0.13.1
 Updated : 2016-10-19 */
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];

var doNotChange = 'doNotChange';

pbjs.que.push(function() {

  var adUnits = [{
    code: doNotChange,
    sizes: [[tagWidth, tagHeight]],
    bids: bids
  }];

  pbjs.addAdUnits(adUnits);

  pbjs.requestBids({
    timeout: bidTimeOut,
    bidsBackHandler: function() {
      var iframe = document.getElementById('oe-1-1-mrppcrmym6hnm7ieyy');
      var iframeDoc = iframe.contentWindow.document;
      var params = pbjs.getAdserverTargetingForAdUnitCode(doNotChange);

      // If any bidders return any creatives, render the ad with the top bid.
      if (params && params['hb_adid']){
        pbjs.renderAd(iframeDoc, params['hb_adid']);
        console.log(params['hb_bidder'], params['hb_pb']);
      } else {
        // If no bidder return any creatives, run passback.
        iframe.width = tagWidth;
        iframe.height = tagHeight;
        iframeDoc.write(passbackTagHtml);
        console.log('HB: PassBack');
      }
    }
  });
});

When page is loading, if there is a header bidding ad from one of our partners, everything goes fine, BUT if it goes to the PassBack, that page never stop loading and it just keep loading and loading.

I have a 2 part question: 1) If I don't use DFP, is Postbid Example best way to go or there is other way to do so like using Basic Prebid.js Example and fix it for none DFP?

2) Why the page keeps loading when it goes to PassBack (have tried iframe & <script> with same result) and how to fix it?

Any help is much appreciated

mkendall07 commented 7 years ago

1) yes postbid is a good way to go but you can also write your own code. 2) You need to close your iframe document after your done writing, otherwise the browser doesn't receive the signal that the iframe is loaded. iframeDoc.close();

Rubioli commented 7 years ago

Thanks a bunch @mkendall07

Regarding writing my own code, is it any good sources so I can read over and write what I need?

Appreciate your help!

mkendall07 commented 7 years ago

I think you've got already what you need? There isn't any other examples except what is published on Prebid.org.