Prebid.js icon indicating copy to clipboard operation
Prebid.js copied to clipboard

Send out another Prebid call without canceling the first

Open KevinCHill opened this issue 10 years ago • 8 comments

The Situation

We have normal defined ad slots that are in the header, sidebar, etc. We also have an ad injector that will dynamically inject ads throughout the content based on word count and/or content height in pixels. Since this can change according to device and browser width, We must wait for the page to render so that the script can evaluate the content length and then dynamically generate all the ad slots and inject the appropriate number of ads throughout the content.

The Problem

We noticed that if you try and run multiple Prebid Auctions right after another (the first comes from the defined slots in the static locations and then a second as soon as the page has loaded and the dynamic ad slots are injected) that the last Prebid auction will cancel out any other prebid auction that is called. The end result is you only get bids and filled impressions from whatever the last auction was.

Failed Solutions

  1. Grouping the calls together: Originally we did a separate call for each injected ad using Ad unit refresh (issue: calls still come in too close together and cancel eachother out. Plus if the user scrolls really fast it can cause a storm of calls). so we grouped the call all into one dynamically generated Prebid auction - but the latency was too great since we had to wait for all the content to load before we could start the auction). So we settled on creating two groups: 1) the defined slot group 2) the dynamically generated group

  2. Stipulating separate timeouts for each auction (issue: nothing regulates when they start so they still cancel each other out)

  3. Setting a fixed delay on the second auction (issue: due to the variability of connection speeds, we either had to make massive sacrifices in latency (long timeouts), or frequent canceling out (short timeouts).

  4. Hijacking the bidRunning var in prebid.js We found this thing called bidRunning in the prebid.js file. So we tried to use that to detect if there is a current auction running, if it is, we tell the system to wait 1200ms and check again. If it doesn't detect any running auctions - it will execute the next prebid auction. (Issue: this still doesn't seem to prevent the canceling out of the previous auction).

    requestBids: function(adUnits) { if (adUnits.defined && !w.$TBNJS.df._bidRunning) { window.$TBNJS.utils.log("DF", "request bids proceding: " + stringify(adUnits)); w.$TBNJS.df._request(adUnits); } else { window.$TBNJS.utils.log("DF", "request bids queued: " + stringify(adUnits)); w.$TBNJS.df._queuedBids.push(adUnits); w.setTimeout(w.$TBNJS.df._requestQueuedBids, 1200); } },

    Live Example

    http://beinggenevieve.com/faux-wood-door/ (I've disabled AdX so that prebid would be able to win everytime)

http://beinggenevieve.com/demandfusion/FlightDF.js

KevinCHill avatar Sep 21 '16 13:09 KevinCHill

@KevinCHill the issue you describe here seems to be the same fixed in https://github.com/prebid/Prebid.js/pull/636

anxobotana avatar Sep 23 '16 07:09 anxobotana

@KevinCHill Thank you for the detailed issue write up. Can you confirm that release 0.13.0. contains the same issue?

mkendall07 avatar Sep 23 '16 18:09 mkendall07

Closing this out. Please reopen if you still see an issue. Thanks

mkendall07 avatar Sep 26 '16 19:09 mkendall07

@mkendall07 I think I have the same issue, using the master branch.

For example, I run 2 calls to requestBids(), with a timeout of 1000ms. Prebid.js is already loaded when I call the pbjs.que.push() Here is the result, the first column is the time relative to my own script:

first placement:
    2 Starting bids: 4 bidders (just before the requestBids call)
  321 appnexus:   0.114   x 0.87  = 0.099   (CPM: 0.25, Time: 316)
  664 criteo:     0.04    x 1     = 0.04    (CPM: 0.25, Time: 655)
  757 rubicon:    0       x 0.885 = 0       (CPM: 0.25, Time: 748)
  866 rubicon:    2.222   x 0.885 = 1.966   (CPM: 0.25, Time: 858)
  870 Handling bids (=bidsBackHandler)
  870 bid #0: appnexus  CPM: 0      Time: 316
  870 bid #1: criteo    CPM: 0      Time: 655
  870 bid #2: rubicon   CPM: 0      Time: 748
  871 bid #3: rubicon   CPM: 1.966  Time: 858
  885 Winner: rubicon (price bucket: 1.90)

second placement:
   11 Starting bids: 4 bidders (just before the requestBids call)
 1098 Handling bids (=bidsBackHandler)
 1098 No bid
 1119 appnexus:   0.368   x 0.87  = 0.32    (CPM: 0.3, Time: 231)
 1288 criteo:     0.17    x 1     = 0.17    (CPM: 0.3, Time: 395)

As you can see: the pbjs.que.push function is run at 2 and 11ms. The first placement works fine, all bidders answer within 1 second.

But the second placement shows that bidsBackHandler is launch at the timeout of the first placement (around 1000ms, here it's 1098ms).

So the second placement is always blocked by the first one. And bids were rendered within 1s: AppNexus answers in 231ms, so it wasn't started at 11ms, but around 1098-231=867ms, just around the first placement run its bidsBackHandler.

How can I add 2 separate calls to pbjs.que.push with separate timeouts? I don't have the choice, as Prebid is initiated by an adserver, hence I don't know if there will be one or two adUnits (so I can't trigger a final global call).

Or am I missing something?

dugwood avatar Oct 12 '16 17:10 dugwood

If I add a 2000ms delay (over the 1000ms Prebid timeout) between pbjs.que.push, there's no issue:

    4 Starting bids: 4 bidders
  212 appnexus:   0.12    x 0.87  = 0.105   (CPM: 0.25, Time: 201)
  493 criteo:     0.07    x 1     = 0.07    (CPM: 0.25, Time: 478)
  728 rubicon:    0       x 0.885 = 0       (CPM: 0.25, Time: 716)
  748 rubicon:    0       x 0.885 = 0       (CPM: 0.25, Time: 736)
  751 Handling bids
  751 bid #0: appnexus  CPM: 0      Time: 201
  751 bid #1: criteo    CPM: 0      Time: 478
  752 bid #2: rubicon   CPM: 0      Time: 716
  752 bid #3: rubicon   CPM: 0      Time: 736
  752 No winner (floor price)

 1928 Starting bids: 4 bidders
 2101 appnexus:   0.368   x 0.87  = 0.32    (CPM: 0.3, Time: 171)
 2139 criteo:     0.12    x 1     = 0.12    (CPM: 0.3, Time: 205)
 2929 Handling bids
 2930 bid #0: appnexus  CPM: 0.32   Time: 171
 2930 bid #1: criteo    CPM: 0      Time: 205
 2933 Winner: appnexus (price bucket: 0.30)

Here we correctly hit the 1000ms timeout (2 bidders are out of time), from 1928 to 2929.

dugwood avatar Oct 12 '16 17:10 dugwood

I'll take a look

mkendall07 avatar Oct 12 '16 18:10 mkendall07

After a new read of this issue, it's not the same case... So maybe I should open another ticket. I'll try to have a look too, in the build/dev version of prebid.js which I can tweak a bit for logs.

dugwood avatar Oct 12 '16 18:10 dugwood

@dugwood yeah can you open a new ticket?

mkendall07 avatar Oct 12 '16 19:10 mkendall07