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 NameDescriptionExample Value
layoutTypeDefines the format or layout of the widget."text_image"
widgetNameIt defines the name assigned to the widget in the Smartech dashboard."welcome_banner"
contentIt contains UI content (SMTWidgetContent)
customKeyValueParamsKey-value pairs used for dynamic rendering or logic conditions.{ "userType": "new" }
gaParamsParameters 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 NameDescriptionExample Value
title, messageText content to be displayed inside the widget."Welcome!", "Enjoy your offer"
mediaUrlURL to an image, GIF, or video used in the widget."https://example.com/image.png"
deeplinkUrlDeep link that opens when the widget is clicked."myapp://home"
backgroundColor , backgroundGradientDefines background color or gradient styling."#FFFFFF", "linear-gradient(...)"
actionButtonsArray 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 TypeBehaviorExample
1Open in-app deep linkdemoapp://orders
2Open external browser linkhttps://amazon.in
3Copy text to clipboardcpText = "FC30" (e.g., coupon)

Key Fields

Field NameDescriptionExample Value
actionNameName of the action button"Shop Now"
actionDeeplinkDeeplink value used to redirect on click of the action button"<https://amazon.in>"
actionTypeType of the action, as defined in the reference table1 or 2 or 3
backgroundColorBackground color of the action button"#FFFFFF"
textColorText color of the action button"#FFFFFF"
cpTextValue used when actionType is 3 to enable copy text functionality"FC30"

Supported layoutType Values

ValueDescription
imageShows a single image without text.
jsonRenders 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.