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 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

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 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

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 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 (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.