App Content Personalization
The Smartech Widget iOS SDK allows you to integrate and display personalized widgets within your iOS application. This guide outlines the steps to implement widget functionality using the SmartechWidgetDelegate protocol.
Note
App Content Personalization is available for integration for Smartech-iOS-SDK v3.7.0 onwards
Begin setting up your Android app's App Content Personalization!
Step 1: Delegate Protocol Implementation
To receive widget data, implement the SmartechWidgetDelegate protocol in the view controller where you plan to display the widgets.
Important
Ensure to remove the delegate in dealloc() to avoid memory leaks.
@interface ViewController () <SmartechWidgetDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[Smartech sharedInstance].widgetDelegate = self;
}
- (void)handleWidgetData:(NSDictionary<NSString *, SMTWidget *> *)widgetDictionary {
// Handle widget data
}
- (void)dealloc {
[Smartech sharedInstance].widgetDelegate = nil;
}
@end
class ViewController: UIViewController, SmartechWidgetDelegate {
override func viewDidLoad() {
super.viewDidLoad()
Smartech.sharedInstance().widgetDelegate = self
}
func handleWidgetData(_ widgetDictionary: [String : SMTWidget]) {
// Handle widget data
}
deinit {
Smartech.sharedInstance().widgetDelegate = nil
}
}
Step 2: Fetch Widget Data
The Smartech SDK provides multiple methods to fetch widgets based on your use case.
You can retrieve all available widgets, fetch a specific widget by name, or load multiple widgets in a single call.
Get All Available Widgets
Use the following methods to retrieve all widget content based on your integration needs.
[[Smartech sharedInstance] getAllWidgets];
Smartech.sharedInstance().getAllWidgets()
Get Widget by Name
Use this method to retrieve and render a single widget based on its configured name.
[[Smartech sharedInstance] getWidgetByName:@"your_widget_name"];
Smartech.sharedInstance().getWidgetByName("your_widget_name")
Note
- Make sure to update your widget names as per your Smartech dashboard configuration.
- Widgets will be delivered through the SMTWidgetListener once this method is called.
Get Multiple Widgets by Names
Use this method when you want to retrieve multiple widgets in a single call by specifying their configured names.
NSArray<NSString *> *widgetNames = @[@"widget1", @"widget2", @"widget3"];
[[Smartech sharedInstance] getWidgetByNames:widgetNames];
let widgetNames = ["widget1", "widget2", "widget3"]
Smartech.sharedInstance().getWidgetByNames(widgetNames)
Get All Widget Names for Debugging or Dynamic Rendering
Use this method to retrieve the names of all widgets for which campaigns have been created.
[[Smartech sharedInstance] getAllWidgetNames];
Smartech.sharedInstance().getAllWidgetNames()
Step 3: Track Widget Events
Smartech SDK automatically tracks widget delivery events. However, you must explicitly log the following events to ensure accurate engagement tracking.
Track View Event
You can call this event when the widget becomes visible to the user:
[[Smartech sharedInstance] trackWidgetAsViewed:widget];
Smartech.sharedInstance().trackWidgetAsViewed(widget)
Important
smtWidgetObj is the actual SMTWidget class object which you used to render ther UI.
Track Click Event
This event is called when the user interacts or clicks the widget:
[[Smartech sharedInstance] trackWidgetAsClicked:widget];
Smartech.sharedInstance().trackWidgetAsClicked(widget)
SMTWidget Data Classes
The SDK uses the following data models to represent widgets and their contents:
SMTWidget
@class SMTWidgetContent;
NS_ASSUME_NONNULL_BEGIN
@interface SMTWidget : NSObject
@property (nonatomic, assign) NSNumber *campaignId;
@property (nonatomic, assign) NSNumber *widgetId;
@property (nonatomic, strong) NSString *widgetName;
@property (nonatomic, strong) NSNumber *audienceId;
@property (nonatomic, strong) NSString *contentId;
@property (nonatomic, strong) NSString *layoutType;
@property (nonatomic, strong) SMTWidgetContent *content;
@property (nonatomic, strong) NSDictionary *customKeyValueParams;
@property (nonatomic, strong) NSDictionary *gaParameters;
- (NSDictionary *)toDictionary;
@end
NS_ASSUME_NONNULL_END
Key Fields
Field Name | Description | Example Value |
---|---|---|
layoutType | Defines the format or layout of the widget. | "text_image" |
widgetName | It defines the name assigned to the widget in the Smartech dashboard. | "welcome_banner" |
content | It contains UI content (SMTWidgetContent ) | |
customKeyValueParams | Key-value pairs used for dynamic rendering or logic conditions. | { "userType": "new" } |
gaParams | Parameters for Google Analytics campaign tracking. It is an optional field. | { "utm_source": "..." } |
SMTWidgetContent
@class SMTWidgetActionButton;
NS_ASSUME_NONNULL_BEGIN
@interface SMTWidgetContent : NSObject
@property (nonatomic, strong) NSString *title;
@property (nonatomic, strong) NSString *message;
@property (nonatomic, strong) NSString *mediaUrl;
@property (nonatomic, strong) NSString *deeplink;
@property (nonatomic, strong) NSString *backgroundColor;
@property (nonatomic, strong) NSArray *backgroundGradientColor;
@property (nonatomic, strong) NSArray<SMTWidgetActionButton *> *actionButtons;
@property (nonatomic, strong) NSDictionary *json;
@property (nonatomic, strong) NSDictionary *customKeyValueParams;
- (NSDictionary *)toNSDictionary;
@end
Key Fields
Field Name | Description | Example Value |
---|---|---|
title, message | Text content to be displayed inside the widget. | "Welcome!" , "Enjoy your offer" |
mediaUrl | URL to an image, GIF, or video used in the widget. | "https://example.com/image.png" |
deeplinkUrl | Deep link that opens when the widget is clicked. | "myapp://home" |
backgroundColor , backgroundGradient | Defines background color or gradient styling. | "#FFFFFF" , "linear-gradient(...)" |
actionButtons | Array of buttons with labels and associated actions. | [ { "label": "Shop Now", "url": "..." } ] |
SMTWidgetActionButton
@interface SMTWidgetActionButton : NSObject
@property (nonatomic, strong) NSString *actionName;
@property (nonatomic, strong) NSString *actionDeeplink;
@property (nonatomic, assign) NSInteger actionType;
@property (nonatomic, strong) NSString *cpText;
@property (nonatomic, strong) NSString *backgroundColor;
@property (nonatomic, strong) NSString *textColor;
- (NSDictionary *)toNSDictionary;
+ (NSArray *)toDictionaryArray:(NSArray <SMTWidgetActionButton *> *)actionButtonArray;
@end
Button Action Types:
Action Type | Behavior | Example |
---|---|---|
1 | Open in-app deep link | demoapp://orders |
2 | Open external browser link | https://amazon.in |
3 | Copy text to clipboard | cpText = "FC30" (e.g., coupon) |
Key Fields
Field Name | Description | Example Value |
---|---|---|
actionName | Name of the action button | "Shop Now" |
actionDeeplink | Deeplink value used to redirect on click of the action button | "<https://amazon.in>" |
actionType | Type of the action, as defined in the reference table | 1 or 2 or 3 |
backgroundColor | Background color of the action button | "#FFFFFF" |
textColor | Text color of the action button | "#FFFFFF" |
cpText | Value used when actionType is 3 to enable copy text functionality | "FC30" |
Supported layoutType Values
Value | Description |
---|---|
image | Shows a single image without text. |
json | Renders the widget using raw JSON payload. |
Best Practices
- Set and remove listeners properly.
- Always call trackWidgetAsViewed() and trackWidgetAsClicked() for accurate analytics.
- Use customKeyValueParams and gaParams for advanced personalization and tracking.
- Use getAllWidgetNames() to debug which widgets are available to the user.
Updated 1 day ago