addAuctionCallbacks() is used for setting up global callbacks - as an alternative to providing them to loadPrebid()
Sometimes it's not feasible to add callbacks directly in the call to loadPrebid() - for example if you want to add it in custom js code in the Yield UI without changing the site code.
Example:
window.relevantDigital = window.relevantDigital || {};
relevantDigital.cmd = relevantDigital.cmd || [];
relevantDigital.cmd.push(function() {
relevantDigital.addAuctionCallbacks({
onSlotAndUnit: function({ slot, unit }) {
console.info('Relevant Yield auction object', this);
console.info('Slot and unit', slot, unit);
},
onBeforeAdRequest: function(params) {
console.info('Relevant Yield auction object', this);
console.info('Parameters', params);
},
});
});
- this will be the auction object
- If you call the function multiple times for the same callback the listeners will be executed in the same order.
- Any function in the auction object can be intercepted using this method - this includes, but is not limited to, the callback functions normally supplied to loadPrebid().
Modifying results / add listener after
Normally the listeners are invoked before the normal callback/function (if any) but relevantDigital.addAuctionCallbacks() also takes a second parameter {when: 'after'} that can be used if you want to add the listener after the normal call - which also makes it possible to modify the result.
Example:
relevantDigital.addAuctionCallbacks({
createAdUnitCode: function(result, params) {
console.info("Parameters", params);
return (result || 'unknown') + '-extra'
},
}, { when: 'after' });
- The result from the the actual callback / function (if any) will be the first parameter. The normal parameters will then follow.
- What is returned will be used as the return value. So in order to not modify the result you need to simply return the first parameter.