iOS Instructions
How to Enable Events?
Please note, events are “disabled” by default. Thus, a developer who wishes to receive widget events should call enableEvents()
method on SFWidget
before calling the configure
method, see example below:
self.sfWidget = SFWidget(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 0))
self.sfWidget.enableEvents()
self.sfWidget.configure(with: self, url: OBConf.baseURL, widgetId: self.widgetId, installationKey: OBConf.installationKey)
How to “Catch” events?
Please make sure to implement the optional SFWidgetDelegate
method:
- (void) widgetEvent:(NSString * _Nonnull)eventName additionalData:(NSDictionary<NSString *, id> * _Nonnull)additionalData;
For example:
func widgetEvent(_ eventName: String, additionalData: [String : Any]) {
print("App revceived widgetEvent: \(eventName) with data: \(additionalData)")
}
How to test all event types? (during development)
Just use testModeAllEvents()
instead of enableEvents()
, see example below:
self.sfWidget = SFWidget(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 0))
self.sfWidget.testModeAllEvents()
self.sfWidget.configure(with: self, url: OBConf.baseURL, widgetId: self.widgetId, installationKey: OBConf.installationKey)
This will cause the SDK to dispatch an example event for every possible type of event.
Android Instructions
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");
How to test all event types? (during development)
Just use the static variableisWidgetEventsTestMode
instead of isWidgetEventsEnabled
, see example below:
SFWebViewWidget.isWidgetEventsTestMode = true;
mSFSmartfeedWidget.init(scrollView, "http://mobile-demo.outbrain.com");
This will cause the SDK to dispatch an example event for every possible type of event.
SFWebViewEventsListener Intereface (for reference)
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);
}