App Content Personalization
The Smartech SDK enables dynamic content delivery via personalised widgets for each user. This guide covers methods for fetching widgets, retrieving widget metadata, and tracking user interactions for analytics.
Set Up the Widget Listener
Before retrieving widget content, initialize a listener to receive widget data:
Smartech().setWidgetListener((widgetData) {
print('Widget data received: $widgetData');
});
Fetching Widgets
1. Fetch a Single Widget by Name
Use this method to retrieve a widget using its unique name. The widget data will be returned through the listener.
await Smartech().getWidgetByName("<widget-name>");
2. Fetch Multiple Widgets by Names
Fetch multiple widgets by passing a list of widget names. All matching widgets will be returned via the listener.
List<String> widgetNames = [
"<widget-name1>",
"<widget-name2>"
];
await Smartech().getWidgetByNames(widgetNames);
3. Fetch All Available Widgets
Retrieve all widgets available for the current user session.
await Smartech().getAllWidgets();
Widget Metadata
4. List All Widget Names
Get a list of all widget names available for the user. Useful for debugging and for dynamically rendering widgets.
List<String> widgetNames = await Smartech().getAllWidgetNames();
Tracking Widget Events
While delivery events are automatically tracked when widgets are rendered, you must manually log viewed and clicked events for accurate engagement metrics.
Track a View Event
Call this method when the widget becomes visible to the user:
await Smartech().trackWidgetAsViewed(widgetData);
Track a Click Event
Log a click event when the user interacts with the widget:
await Smartech().trackWidgetAsClicked(widgetData);
