Widget External Event Handler

Widget External Event Handler provides a function to execute custom scripts after the Widget loading events.

Code Sample

To register an event callback, an array of object OBREvents must be defined on the global scope and callback event object must be added.

window.OBREvents = window.OBREvents || [];
OBREvents.push({
  event: 'widgetDataReturned',
  widgetId: ['AR_1', 'AR_2'],
  func: function(e) {
    console.log(e);
  }
});

Callback Event object

Property Description Sample Value
event The name of event to trigger the callback ‘widgetDataReturned’
widgetId The array of widget ids to execute the callback in the event of callback [‘AR_1’, ‘AR_2’]
func The callback function to be executed on the event function(e){console.log(e);}

Available Events

Event name Description
widgetDataReturned It will be triggered when the Outbrain server has returned the data for a certain widget Id.
widgetRendered It will be triggered when the rendering of a certain widget Id has been completed.

Return object in callback

Event callback function will receive Object of each widget’s information as:

Property Description Sample Value
idx Index number of widget in the page 0
widgetId The name of the widget ‘AR_1’
container The reference to HTMLElement of the widget container or null if empty HTMLElement (div#outbrain_widget_0.OUTBRAIN)
recsNumber The number of recs returned or -1 if erred or not available 1
{
  idx: 0,
  widgetId: 'AR_1',
  container: div#outbrain_widget_0.OUTBRAIN,
  recsNumber: 1
}