Skip to main content

(Optional) Widget Events

How to Enable Events?

Please note, widget events are "disabled" by default. Thus, a developer who wishes to receive widget events should set the isWidgetEventsEnabled static variable, for example SFWebViewWidget.isWidgetEventsEnabled = true before calling the init() method, see example below:

SFWebViewWidget.isWidgetEventsEnabled = true;
mSFSmartfeedWidget.init(scrollView, "http://mobile-demo.outbrain.com");

How to "Catch" events?

Please make sure to setSfWebViewEventsListener() again, before calling the init() method, see example below:

mSFSmartfeedWidget.setSfWebViewEventsListener(new SFWebViewEventsListener() {
@Override
public void onWidgetEvent(String eventName, JSONObject additionalData) {
Log.i("ScrollViewActivity", "onWidgetEvent: " + eventName);
Log.i("ScrollViewActivity", "onWidgetEvent: " + additionalData);
}
});

SFWebViewWidget.isWidgetEventsEnabled = true;
mSFSmartfeedWidget.init(scrollView, "http://mobile-demo.outbrain.com");

SFWebViewEventsListener

public interface SFWebViewEventsListener {

/**
* @brief Called when the JS widget inside the SFWebViewWidget dispatch widget events (for example: rendered, error, viewability, etc).
* it should be implemented only if the publisher would like to manually keep track of widget events.
* @param eventName - the name of the event being dispatched
* @param additionalData - additional data that comes with the event. For example you'll find there: "widget ID", "widget index" and "timestamp".
*/
void onWidgetEvent(String eventName, JSONObject additionalData);
}

Event Types

Here is the list of event types:

  • ready
  • rendered
  • dataReturned
  • viewability