App Content Personalization
Begin setting up your Android app's App Content Personalization!
Note
App Content Personalization is available for integration from Smartech SDK v3.7.0 onwards.
Step 1: Complete Basic Setup
Go to Basic Setup to integrate your Android project with Netcore CE.
Step 2: Implement SMTWidgetListener in the Activity
To receive widget data, implement the SMTWidgetListener interface in the activity where you plan to display the widgets. Alternatively, implement it in a centralized parent activity if you manage widget rendering globally.
Note
Make sure to remove the listener in onDestroy() to avoid memory leaks.
public class MainActivity extends AppCompatActivity implements SMTWidgetListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set the SMTWidgetListener
Smartech.getInstance(new WeakReference<>(this)).setWidgetListener(this);
}
@Override
public void onWidgetsLoaded(@Nullable HashMap<String, @Nullable SMTWidget> data) {
// Handle the received widget data here
}
@Override
protected void onDestroy() {
super.onDestroy();
// Remove listener to avoid memory leaks
Smartech.getInstance(new WeakReference<>(this)).removeWidgetListener(this);
}
}v
class MainActivity : AppCompatActivity(), SMTWidgetListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Set the SMTWidgetListener
Smartech.getInstance(WeakReference(this)).setWidgetListener(this)
}
override fun onWidgetsLoaded(data: HashMap<String, SMTWidget?>?) {
// Handle the received widget data here
}
override fun onDestroy() {
super.onDestroy()
// Remove listener to avoid memory leaks
Smartech.getInstance(WeakReference(this)).removeWidgetListener(this)
}
}
Step 2: Fetch Widget Data
Smartech SDK provides multiple methods to retrieve widgets, depending on your use case. You can choose to fetch all widgets, a specific widget by name, or multiple widgets together. Use these methods according to your rendering logic and personalization strategy.
Get All Available Widgets
Use this method to retrieve all widget configured and targeted for the current user session.
Smartech.getInstance(new WeakReference<>(this)).getAllWidgets();
Smartech.getInstance(WeakReference(this)).getAllWidgets()
Get Widget by Name
Use this method to retrieve and render a single widget based on its configured name.
Smartech.getInstance(new WeakReference<>(this)).getWidgetByName(<"your_widget_name">);
Smartech.getInstance(WeakReference(this)).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.
Smartech.getInstance(new WeakReference<>(this)).getWidgetByName(new String[] {<"widget_1">, <"widget_2">});
Smartech.getInstance(WeakReference(this)).getWidgetByName(arrayOf(<"widget_1">, <"widget_2">))
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.getInstance(new WeakReference<>(this)).getAllWidgetNames();
Smartech.getInstance(WeakReference(this)).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
This event is called when the widget becomes visible to the user:
Smartech.getInstance(new WeakReference<>(this)).trackWidgetAsViewed(smtWidgetObj);
Smartech.getInstance(WeakReference(this)).trackWidgetAsViewed(smtWidgetObj)
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.getInstance(new WeakReference<>(this)).trackWidgetAsClicked(smtWidgetObj);
Smartech.getInstance(WeakReference(this)).trackWidgetAsClicked(smtWidgetObj)
SMTWidget Data Classes
The SDK uses the following data models to represent widgets and their contents:
SMTWidget
data class SMTWidget(
var layoutType: String = "",
var widgetName: String = "",
var widgetId: Int = 0,
var campaignId: Int = 0,
var audienceId: Int = 0,
var contentId: String = "",
var content: SMTWidgetContent? = null,
var gaParams: HashMap<String, String>? = null,
var customKeyValueParams: HashMap<String, Any>? = null
)
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
data class SMTWidgetContent(
val title: String = "",
val message: String = "",
val mediaUrl: String = "",
val deeplinkUrl: String = "",
val backgroundColor: String = "",
val backgroundGradient: List<String>? = arrayListOf(),
val actionButtons: List<SMTWidgetActionButton>? = arrayListOf(),
val json: JSONObject? = JSONObject(),
val customKeyValueParams: HashMap<String, Any>? = hashMapOf()
)
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
data class SMTWidgetActionButton(
val actionName: String = "",
val actionDeeplink: String = "",
val actionType: Int = 0,
val cpText: String = "",
val backgroundColor: String = "",
val textColor: String = ""
)
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 (onCreate() / onDestroy()).
- 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 about 23 hours ago