The following methods are available to use in the Monetate SDK. All methods are part of the personalization class.
This method generates a Monetate ID and returns it as a string. You can store this ID locally for future use.
static generateMonetateId(): string
static generateMonetateId(): string
public func generateMonetateID () -> String
public static string generateMonetateId();
const monetateId = Personalization.generateMonetateId()
const monetateId = Personalization.generateMonetateId()
let monetateId = self.personalization.generateMonetateID()
String monetateId = Personalization.generateMonetateId();
Note: This is the legacy report() method supported for backward compatibility.For Context Layer–based reporting, see report[New]. Reports an event to Monetate. This allows data to later be used for decisions within Monetate. Use this method to report events.
report(context: EventTypes, events: ContextData): void
report(context: EventTypes, events: ContextData): void
report(context: <ContextEnum>, event: <MEvent?>)
public void report(String context, Object events){}
This method must be run in a thread.
The parameters are as follows:
const personalizationInstance = new Personalization(user, account);
const cart = {
"cartLines": [{
"sku": "SKU1",
"pid": "PID1",
"quantity": 2,
"currency": "USD",
"value": "24.00"
}]
};
personalizationInstance.report(
EventTypes.ContextCart,
{ cartLines: cart }
);
const personalizationInstance = new Personalization(user, account);
const cart = {
"cartLines": [{
"sku": "SKU1",
"pid": "PID1",
"quantity": 2,
"currency": "USD",
"value": "24.00"
}]
};
personalizationInstance.report(
EventTypes.ContextCart,
{ cartLines: cart }
);
objPersonalization.report(context: .RecClicks, event: RecClicks(recClicks: ["rt.1.xxx", "rt.1.yyy"]))
Account account = new Account("localhost.org", "a-701b337c", "p", "localhost");
User user = new User();
user.setDeviceId("1109349827122");
try
{
Personalization personalization = new Personalization(user, account);
IpAddress address = new IpAddress();
address.setIpAddress("127.0.0.0.");
new Thread(new Runnable()
{
@Override
public void run()
{
personalization.report(EventTypes.ContextIpaddress, address);
}
}).start();
}
catch (AccountDetailsException e)
{
e.printStackTrace();
}
Note:These enhancements are currently available for the Android and iOS SDKs.The React SDK is not impacted by these changes.
- Android: 1.0.6-A or later
This method adds event data to the SDK's internal stack. Use this method to add events to the stack that you intend to use to trigger experiences. You can use multiple calls of this method to add multiple events to stack. Use this method with getActionsData when an experience requires data from more than one event.
addEvent(context: EventTypes, events: ContextData): void
addEvent(context: EventTypes, events: ContextData): void
addEvent(context: <ContextEnum>, event: <MEvent?>)
public void addEvent(String context, Object event)
The parameters are as follows:
personalizationInstance.addEvent(EventTypes.ContextIpAddress, {
ipAddress: "10.0.0.2",
});
personalizationInstance.addEvent(EventTypes.ContextPageView, {
url: "http://www.monetate.com/index.html",
pageType: "Home"
});
personalizationInstance.addEvent(EventTypes.ContextIpAddress, {
ipAddress: "10.0.0.2",
});
personalizationInstance.addEvent(EventTypes.ContextPageView, {
url: "http://www.monetate.com/index.html",
pageType: "Home"
});
objPersonalization.addEvent(context: .ScreenSize, event: ScreenSize(height: 1000, width: 400))
objPersonalization.addEvent(context: .IpAddress, event: IPAddress(ipAddress: "192.168.1.52"))
objPersonalization.addEvent(context: .PageView, event: PageView(pageType: "PDP", path: "n/a", url: "n/a", categories: [], breadcrumbs: []))
IpAddress ipAddress = new IpAddress();
ipAddress.setIpAddress("1.0.0.0");
ScreenSize screenSize = new ScreenSize();
screenSize.setHeight(1011);
screenSize.setWidth(2011);
PageView pageView = new PageView();
pageView.setPageType("Cartpage");
pageView.setUrl("https://www.monetate.com");
personalization.addEvent(EventTypes.ContextIpAddress, ipAddress);
personalization.addEvent(EventTypes.ContextPageView, pageView);
personalization.addEvent(EventTypes.ContextScreenSize, screenSize);
Requests an experience decision from Monetate based off the action type. You can specify multiple action types in an array to get multiple responses.
The experience decision depends on event data reported using addEvent calls. Use addEvent to add report all of the relevant events before you use this method to request a decision.
getActionsData(actionType: Array<string>, includeReporting?: boolean) : Promise<any>
The parameters are as follows:
getActionsData(actionType: Array<string>, includeReporting?: boolean) : Promise<any>
The parameters are as follows:
- actionType 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.
getActionsData(requestId: <String>, includeReporting: <Bool>, arrActionTypes: <[String]>)
The parameters are as follows:
- requestID is the request ID for the API.
- includeReporting indicates whether the response will have impression reporting data.
- arrActionTypes is the type of actions you want to request. You can specify multiple actions in an array to handle.
public String getActionsData(String[] actionTypes, boolean includeReports)
The parameters are as follows:
- actionTypes is the type of action you want to request. You can specify one action or multiple actions in an array to handle.
- includeReports indicates whether the response will have impression reporting data.
The following example specifies a single action.
personalizationInstance
.getActionsData("monetate:action:OmnichannelJson")
.then(res => {
recsData = res[0].actions;
})
.catch(error => {
console.warn('Error!', error);
});
personalizationInstance
.getActionsData("monetate:action:OmnichannelJson")
.then(res => {
recsData = res[0].actions;
})
.catch(error => {
console.warn('Error!', error);
});
objPersonalization.getActionsData(
requestId: "123456", includeReporting: false,
arrActionTypes: ["monetate:action:OmniChannelRecommendation"]
).on { res in
if res.status == 200 {
self.handleRecommendations(res: res)
} else {
}
}
try
{
Personalization personalization = new personalization(user, account);
// Events and context data
IpAddress ipAddress = new IpAddress();
ipAddress.setIpAddress("1.0.0.0");
ScreenSize screenSize = new ScreenSize();
screenSize.setHeight(1011);
screenSize.setWidth(2011);
PageView pageView = new PageView();
pageView.setPageType("Cartpage");
pageView.setUrl("https://www.monetate.com");
// addEvent
personalization.addEvent(EventTypes.ContextScreenSize, screenSize);
personalization.addEvent(EventTypes.ContextIpAddress, ipAddress);
personalization.addEvent(EventTypes.ContextPageView, pageView);
// getActionsData
String responseData;
new Thread(new Runnable()
{
@Override
public void run()
{
// Gets the responseData using getActionsData
responseData = personalization.getActionsData("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();
}
catch (AccountDetailsException e)
{
e.printStackTrace();
}
The following example specifies multiple actions.
// For multiple actions, send an array
// When an empty array in passed as an argument, it will fetch all the configured Omnichannel actions
const requiredActions : [ "monetate:action:OmnichannelRecommendation"
, "monetate:action:SocialProofDataV2" ]
personalizationInstance
.getActionsData(requiredActions)
.then(res => {
recsData = res[0].actions;
})
.catch(error => {
console.warn('Error!', error);
});
// For multiple actions, send an array
// When an empty array in passed as an argument, it will fetch all the configured Omnichannel actions
const requiredActions : [ "monetate:action:OmnichannelRecommendation"
, "monetate:action:SocialProofDataV2" ]
personalizationInstance
.getActionsData(requiredActions)
.then(res => {
recsData = res[0].actions;
})
.catch(error => {
console.warn('Error!', error);
});
objPersonalization.getActionsData(
requestId: "123456", includeReporting: false,
arrActionTypes: ["monetate:action:OmniChannelJson", "monetate:action:OmniChannelRecommendation"]
).on { res in
if res.status == 200 {
self.handleRecommendations(res: res)
} else {
}
}
try
{
Personalization personalization = new personalization(user, account);
// Events and context data
IpAddress ipAddress = new IpAddress();
ipAddress.setIpAddress("1.0.0.0");
ScreenSize screenSize = new ScreenSize();
screenSize.setHeight(1011);
screenSize.setWidth(2011);
PageView pageView = new PageView();
pageView.setPageType("Cartpage");
pageView.setUrl("https://www.monetate.com");
// addEvent
personalization.addEvent(EventTypes.ContextScreenSize, screenSize);
personalization.addEvent(EventTypes.ContextIpAddress, ipAddress);
personalization.addEvent(EventTypes.ContextPageView, pageView);
// getActionsData
String responseData;
new Thread(new Runnable()
{
@Override
public void run()
{
// Gets the responseData using getActionsData
responseData = personalization.getActionsData(new String[]{"monetate:action:OmnichannelJson","monetate:action:OmnichannelRecommendation"}, 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();
}
catch (AccountDetailsException e)
{
e.printStackTrace();
}
Note: This is the legacy getActions() flow supported for backward compatibility.For the Context Layer–based approach, see getActions()[New]
Reports an event and immediately requests a decision from Monetate. Use this method if an experience you want to trigger requires a single event. This method returns a JSON object that includes the response data.
The response data can then be used in your application. For example, you can use this method to obtain data to display as a banner on a page.
getActions(actionType, context?, eventData?, includeReporting?) : Promise<any>
The parameters are as follows:
getActions(actionType, context?, eventData?, includeReporting?) : Promise<any>
- actionType is the type of action you want to request. You can specify multiple actions in an array to handle.
- context is name of the event.
- eventData is the data associated with the event.
- includeReporting indicates whether the response will have impression reporting data.
objPersonalization.getActions(context: <ContextEnum>, requestId: <String>, includeReporting: <Bool>, arrActionTypes: <[String]>, event: <MEvent?>)
- context is name of the event.
- requestID is the request ID for the API.
- includeReporting indicates whether the response will have impression reporting data.
- arrActionTypes is the type of actions you want to request. You can specify multiple actions in an array to handle.
- event is the data associated with the event.
public String getActions(String context, Object event, String[] actionTypes, boolean includeReports) {returns response;}
The parameters are as follows:
- actionTypes is the type of action you want to request. You can specify one action or multiple actions in an array to handle.
- context is name of the event.
- event is the data associated with the event.
- includeReports indicates whether the response will have impression reporting data.
import React, { useEffect, useState} from "react" ;
import { View , Text} from "react-native" ;
import Personalization from '@personalization-js-sdk/react-native';
import { ActionTypes, EventTypes } from "@personalization-js-sdk/common";
const test = () => {
const personalizationInstance = new Personalization(account, user)
const [actionData, setActionData] = useState({});
const handleGetActions = () => {
const eventType = EventTypes.ContextCart;
personalizationInstance.getActions("monetate:action:OmnichannelJson", eventType)
.then((res) => {
if (res.length > 0) {
res[0].actions.map((action) => {
if (action.json.meta && action.json.meta.tool === 'react-native') {
const data = {
color: action.json.data.json.color,
text: action.json.data.json.text,
fontSize: action.json.data.json.fontSize,
style: action.json.data.json.style,
buttonText: action.json.data.json.buttonText,
buttonColor: action.json.data.json.buttonColor,
};
setActionData(prevState => {
return {
...prevState,
decisionEventData: data,
}
});
} else {
console.warn('Meta Object not present in Omni JSON.');
}
});
}
})
.catch((error) => console.warn('Please try after some time!', error));
};
useEffect(() => {
handleGetActions();
}, []);
return <View>
<Text> {actionData.buttonText} //Render Data On UI
</View>;
};
import React, { useEffect, useState} from "react" ;
import Personalization from '@personalization-js-sdk/web';
import { ActionTypes, EventTypes } from "@personalization-js-sdk/common";
const test = () => {
const personalizationInstance = new Personalization(account, user)
const [actionData, setActionData] = useState({});
const handleGetActions = () => {
const eventType = EventTypes.ContextCart;
personalizationInstance.getActions("monetate:action:OmnichannelJson", eventType)
.then((res) => {
if (res.length > 0) {
res[0].actions.map((action) => {
if (action.json.meta && action.json.meta.tool === 'web') {
const data = {
color: action.json.data.json.color,
text: action.json.data.json.text,
fontSize: action.json.data.json.fontSize,
style: action.json.data.json.style,
buttonText: action.json.data.json.buttonText,
buttonColor: action.json.data.json.buttonColor,
};
setActionData(prevState => {
return {
...prevState,
decisionEventData: data,
}
});
} else {
console.warn('Meta Object not present in Omni JSON.');
}
});
}
})
.catch((error) => console.warn('Please try after some time!', error));
};
useEffect(() => {
handleGetActions();
}, []);
return <div>
<p> {actionData.buttonText} //Render Data On UI </p>
</div>;
};
import MarqueeLabel
import UIKit
import monetate_ios_sdk
class CategoryViewController: UIViewController {
@IBOutlet weak var bottomLabel: MarqueeLabel!
@IBOutlet weak var bottomView: UIView!
@IBOutlet weak var constraintHeightBottomView: NSLayoutConstraint!
final var objPersonalization = Personalization(
account: Account(
instance: "p", domain: "localhost.org", name: "a-701b337c", shortname: "localhost"),
user: User(deviceId: "62bd2e2d-213d-463f-83bb-12c0b2530a14"))
override func viewDidLoad() {
super.viewDidLoad()
self.bottomView.isHidden = true
self.constraintHeightBottomView.constant = 0
bottomLabel.text = ""
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
pageEvent()
}
func pageEvent() {
objPersonalization.getActions(
context: .PageView, requestId: "test_request_id", includeReporting: false,
arrActionTypes: ["monetate:action:OmniChannelJson"],
event: PageView(
pageType: "Homepage", path: "n/a", url: "n/a", categories: [], breadcrumbs: [])
).on { (res) in
if res.status == 200 {
let data = JSON(res.data)
print(data)
self.handleAction(res: res)
} else {
}
}
}
fileprivate func handleAction(res: APIResponse) {
let data = JSON(res.data)
for item in data["data"]["responses"].arrayValue {
bottomLabel.animationCurve = .linear
bottomLabel.speed = .duration(5)
bottomLabel.fadeLength = 15.0
if item["requestId"].string == res.requestId {
for oneaction in item["actions"].arrayValue {
let component = oneaction["component"].string ?? ""
if component.lowercased() == "footer" {
if let json = oneaction["json"].dictionary {
print("final dict \(json)")
if let text = json["text"]?.string {
self.bottomView.isHidden = false
self.constraintHeightBottomView.constant = 60
bottomLabel.text = text
if let fontStyle = json["style"]?.string, let fontSize = json["fontSize"]?.double {
if fontStyle == "bold" {
bottomLabel.font = UIFont(name: "Roboto-Bold", size: fontSize)
} else if fontStyle == "normal" {
bottomLabel.font = UIFont(name: "Roboto-Regular", size: fontSize)
} else if fontStyle == "italic" {
bottomLabel.font = UIFont(name: "Roboto-Italic", size: fontSize)
}
}
if let color = json["color"]?.string {
bottomLabel.textColor = MiscClass.hexStringToUIColor(hex: color)
}
if let backgroundColor = json["background-color"]?.string {
bottomView.backgroundColor = MiscClass.hexStringToUIColor(hex: backgroundColor)
return
}
}
}
}
}
}
}
}
}
Account account = new Account("localhost.org", "a-701b337c", "p", "localhost");
User user = new User();
user.setDeviceId("1109349827122");
try
{
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()
{
// Get the responseData using getActions
responseData = personalization.getActions(EventTypes.ContextIpAddress, address, new String[] {"monetate:action:OmnichannelJson"}, true);
// Once you receive the responseData from getActions, 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();
}
catch (AccountDetailsException e)
{
e.printStackTrace();
}
Note: These enhancements are currently available for the Android and iOS SDKs. The React SDK is not impacted by these changes.
- Android: 1.0.6-A or later
- iOS : 2026.01.01 or later
Immediately sends all event data that are currently queued. Use this method if you want to report an event immediately. This method returns a response of success or failure.
This method might throw the following exceptions that you must handle:
public String flush() throws InterruptedException, ExecutionException, TimeoutException {}
const Personalization= new Personalization(account, user);
PersonalizationInstance.report (
'monetate:context:IpAddress',
{ ipAddress: 10.10.10.10 }
),
Personalization.flush();
You can also capture the method response in a variable:
const response = Personalization.flush()
const Personalization= new Personalization(account, user);
PersonalizationInstance.report (
'monetate:context:IpAddress',
{ ipAddress: 10.10.10.10 }
),
Personalization.flush();
You can also capture the method response in a variable:
const response = Personalization.flush()
objPersonalization.report(context: .RecClicks, event: RecClicks(recClicks: ["rt.1.xxx", "rt.1.yyy"]))
objPersonalization.report(context: .RecImpressions, event: RecImpressions(recImpressions: ["rt.2.xxx", "rt.2.yyy"]))
objPersonalization.flush()
try
{
Personalization personalization = new Personalization(user, account);
IpAddress address = new IpAddress();
address.setIpAddress("127.0.0.0.");
new Thread(new Runnable()
{
@Override
public void run()
{
Personalization.report(EventTypes.ContextIpaddress, address);
personalization.flush();
}
}).start();
}
catch (Exception e)
{
e.printStackTrace();
}
setCustomerId(customerId)
setCustomerId(customerId)
setCustomerId(customerId)
public void setCustomerId(String customerId);
The parameter is as follows:
- customerId is a string containing the customer ID. (Required)
personalizationInstance.setCustomerId("test_customer_id");
personalizationInstance.setCustomerId("test_customer_id");
objPersonalization.setCustomerId(customerId:"155468")
personalization.setCustomerId("test_customer_id");