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

`refresh()` method on adapters #159

Closed nickjacob closed 8 years ago

nickjacob commented 8 years ago

Because some adapters load SDKs (AOL, OpenX) on callBids(), and different bidders have different requirements when requesting an additional pageview/auction, I was thinking it might be helpful to have an optional refresh(params) method in the adapter interface, so we can help minimize the impact during infinite scroll/slideshows & have best possible integrations on subsequent pageviews. For example the adtech adapter might look like:

refresh(params) {
  if (!window.ADTECH) {
    utils.logError('called refresh without calling _callBids first!', 'window.ADTECH is not present', ADTECH_BIDDER_NAME);
    return _callBids(params);
  }

  var bids = params.bids;
  utils._each(bids, function (bid) {
    ADTECH.refreshAd(_mapUnit(bid));
  });
}
mkendall07 commented 8 years ago

Thanks for the suggestion. It's something we'll need to add to the backlog, but will require a bit of work and testing of each adapter.

prebid commented 8 years ago

@nickjacob is it possible to change the AOL/OpenX adaptor, so that they don't load the SDK on each request? It's more efficient that way as well. It may not be possible with their code today, but we can make this as a requirement, so bidders upgrade their adaptors.

nickjacob commented 8 years ago

we could do something like AMP does internally, like:

loadService(window, 'http://adtech.us/script.js', function () {
  window.ADTECH(); 
});

function loadService(_global, src, callback) {
  // scripts are loaded by the global passed in, so we could
  // load a script in an iframe if we wanted to
  var _scriptLoad = _global._scriptLoad || (_global._scriptLoad = {});

  if (!_scriptLoad[src]) {
    _scriptLoad[src] = [];
    // modify loadScript to take a window to load w/i
    loadScript(src, function () {
      function _call(f){ return f(_global) };
      utils._each(_scriptLoad[src], _call);
      _scriptLoad[src].push = _call;
    }, _global);
  }

  _scriptLoad[src].push(callback);
}

I think this would be good in general but idk if it would solve for all refresh() scenarios

mkendall07 commented 8 years ago

@nickjacob I added caching to the adLoader.loadScript() function, which probably would solve this problem I think? https://github.com/prebid/Prebid.js/pull/242/files#diff-86d571de6e2be77b9e9aa02a2b847c41R11

protonate commented 8 years ago

Closing, reopen if new info.