Create a Banner Message Action
Displaying a banner involves creating an action trigger that activates an Omnichannel experience to return an appropriate JSON object. This object contains data that you can use to populate a banner message. You can use the getActions method to set up this trigger and obtain the JSON.
You can use the returned JSON data for multiple purposes. This example uses the JSON to display a banner message.
Creating the Experience
You must first create an Omnichannel experience in the Monetate platform that uses an Omni JSON action type. Refer to Create an Omnichannel Experience in the Monetate Knowledge Base for instructions, and to Available Action Types for additional information on Omni JSON actions.
You can use the following JSON template for the required input:
{
"meta":
{
"code": 200
},
"data":
{
"responses":
[
{
"requestId": "sample-unique-request-id-ABC-123",
"actions":
[
{
"json":
{
"text": "Free Shipping on orders over $500",
"color": "#FFFFFF",
"style": "bold",
"fontSize": 24,
"background-color": "#697895"
},
"actionType": "monetate:action:OmnichannelJson",
"component": "home_component_1",
"actionId ": 5005228
}
]
}
]
}
}This is the JSON object that is returned on the trigger. Modify this template to suit your needs.
Triggering the Experience
The Omnichannel experience is triggered using the getActions method. This method is used when you want to satisfy an experience using a single event condition.
public String getActions(String context, Object event, String[] actionTypes, boolean includeReports) {returns response;}The parameters are as follows:
- context is name of the event.
- eventData is the data associated with the event.
- actionTypes is the type of action you want to request. You can specify one action or multiple actions in an array to handle.
- includeReporting indicates whether the response will have impression reporting data.
Full Code Example
This code triggers the configured Omni JSON experience and handles the experience by displaying a banner. Customize the example code as you see fit.
Account account = new Account("localhost.org", "a-701b337c", "p", "localhost");
User user = new User();
user.setCustomerId(null);
user.setDeviceId("1769696968989");
Personalization personalization = new Personalization(user, account);
IpAddress address = new IpAddress();
address.setIpAddress("127.0.0.0.");
String responseData;
new Thread(new Runnable()
{
@Override
public void run()
{
// Gets the responseData using getActionsData
responseData = personalization.getActions(EventTypes.ContextIpAddress, address, new String[]
{
"monetate:action:OmnichannelJson"
}, true);
// Once you receive the responseData from getActionsData, use the Handler and parse the required data from it
new Handler(Looper.getMainLooper()).post(new Runnable()
{
@Override
public void run()
{
// Parse the received responseData, get the requiredData from it and use it accordingly
try
{
// Example: textView.setText(requiredData);
}
catch (Exception ex)
{
// Catch any exception that occurs while parsing
ex.printStackTrace();
}
}
});
}
}).start();You must handle the getActions method in a Thread or AsyncTask. To update the main thread, you can use either Handler or runOnUiThread. This code example uses Thread and Handler to update the main thread and change the UI.
Banner Message Action using Context layer approach
Supported SDK Versions
- Android: 1.0.6-A or later
- React-Native: 1.0.6-RN or later
- Web: 1.0.6-W or later
- iOS: 2026.01.06 or later
Using the new Context Layer–based approach, BannerMessage Actions can be implemented using enhanced getActions() method. Below is the sample code snippet demonstrating this usage.
For detailed information on the enhanced getActions() flow, please refer to the Context and getActions sections.
Code Example
public void getActions(Context context, String[] actionTypes, boolean includeReports, ActionsCallback actionsCallback)
FullCode Example
const context = new Context();
context
.addPageDetails()
.url("www.monetate.com")
.path(monetate.com)
.pageType("home")
.breadcrumbs(["Home"])
.categories(["Homepage"]);
Personalization.getActions(
["monetate:action:OmnichannelJson"],
context)
.then((res: any) => console.log("Action === 1 res", res));