API reference
clearPropositions
This API clears out the client-side in-memory propositions cache.
Android Java
data-slots=heading, code
data-repeat=2
Syntax
public static void clearCachedPropositions()
Example
Optimize.clearCachedPropositions();
iOS Swift
data-slots=heading, code
data-repeat=2
Syntax
static func clearCachedPropositions()
Example
Optimize.clearCachedPropositions()
iOS Objective-C
data-slots=heading, code
data-repeat=2
Syntax
+ (void) clearCachedPropositions;
Example
[AEPMobileOptimize clearCachedPropositions];
extensionVersion
The extensionVersion() method (on Android) or the extensionVersion property (on iOS) returns the version information for currently installed AEPOptimize extension.
Android Java
data-slots=heading, code
data-repeat=2
Syntax
public static String extensionVersion()
Example
Optimize.extensionVersion();
iOS Swift
data-slots=heading, code
data-repeat=2
Syntax
static var extensionVersion: String
Example
let extensionVersion = Optimize.extensionVersion
iOS Objective-C
data-slots=heading, code
data-repeat=2
Syntax
+ (nonnull NSString*) extensionVersion;
Example
NSString *extensionVersion = [AEPMobileOptimize extensionVersion];
getPropositions
This API retrieves the previously fetched propositions, for the provided decision scopes, from the in-memory extension propositions cache. The completion callback is invoked with the decision propositions corresponding to the given decision scopes. If a certain decision scope has not already been fetched prior to this API call, it will not be contained in the returned propositions.
When connected to Assurance for previewing content, this method will return simulated results.
Android Java
- decisionScopes is a list of decision scopes for which propositions are requested.
- callback
callmethod is invoked with propositions map of typeMap<DecisionScope, OptimizeProposition>. If the callback is an instance of AdobeCallbackWithError, and if the operation times out or an error occurs in retrieving propositions, thefailmethod is invoked with the appropriate AdobeError.
data-slots=heading, code
data-repeat=2
Syntax
public static void getPropositions(final List<DecisionScope> decisionScopes, final AdobeCallback<Map<DecisionScope, OptimizeProposition>> callback)
Example
final DecisionScope decisionScope1 = DecisionScope("xcore:offer-activity:1111111111111111", "xcore:offer-placement:1111111111111111", 2);
final DecisionScope decisionScope2 = new DecisionScope("myScope");
final List<DecisionScope> decisionScopes = new ArrayList<>();
decisionScopes.add(decisionScope1);
decisionScopes.add(decisionScope2);
Optimize.getPropositions(scopes, new AdobeCallbackWithError<Map<DecisionScope, OptimizeProposition>>() {
@Override
public void fail(final AdobeError adobeError) {
// handle error
}
@Override
public void call(Map<DecisionScope, OptimizeProposition> propositionsMap) {
if (propositionsMap != null && !propositionsMap.isEmpty()) {
// get the propositions for the given decision scopes
if (propositionsMap.contains(decisionScope1)) {
final OptimizeProposition proposition1 = propsMap.get(decisionScope1)
// read proposition1 offers
}
if (propositionsMap.contains(decisionScope2)) {
final OptimizeProposition proposition2 = propsMap.get(decisionScope2)
// read proposition2 offers
}
}
}
});
iOS Swift
- decisionScopes is an array of decision scopes for which propositions are requested.
- completion is invoked with propositions dictionary of type
[DecisionScope: OptimizeProposition]. AnErroris returned if SDK fails to retrieve the propositions.
data-slots=heading, code
data-repeat=2
Syntax
static func getPropositions(for decisionScopes: [DecisionScope],
_ completion: @escaping ([DecisionScope: OptimizeProposition]?, Error?) -> Void)
Example
let decisionScope1 = DecisionScope(activityId: "xcore:offer-activity:1111111111111111",
placementId: "xcore:offer-placement:1111111111111111",
itemCount: 2)
let decisionScope2 = DecisionScope(name: "myScope")
Optimize.getPropositions(for: [decisionScope1, decisionScope2]) { propositionsDict, error in
if let error = error {
// handle error
return
}
if let propositionsDict = propositionsDict {
// get the propositions for the given decision scopes
if let proposition1 = propositionsDict[decisionScope1] {
// read proposition1 offers
}
if let proposition2 = propositionsDict[decisionScope2] {
// read proposition2 offers
}
}
}
iOS Objective-C
- decisionScopes is an array of decision scopes for which propositions are requested.
- completion is invoked with propositions dictionary of type
NSDictionary<AEPDecisionScope*, AEPOptimizeProposition*>. AnNSErroris returned if SDK fails to retrieve the propositions.
data-slots=heading, code
data-repeat=2
Syntax
+ (void) getPropositions: (NSArray<AEPDecisionScope*>* _Nonnull) decisionScopes
completion: (void (^ _Nonnull)(NSDictionary<AEPDecisionScope*, AEPOptimizeProposition*>* _Nullable propositionsDict, NSError* _Nullable error)) completion;
Example
AEPDecisionScope* decisionScope1 = [[AEPDecisionScope alloc] initWithActivityId: @"xcore:offer-activity:1111111111111111"
placementId: @"xcore:offer-placement:1111111111111111"
itemCount: 2];
AEPDecisionScope* decisionScope2 = [[AEPDecisionScope alloc] initWithName: @"myScope"];
[AEPMobileOptimize getPropositions: @[decisionScope1, decisionScope2]
completion: ^(NSDictionary<AEPDecisionScope*, AEPOptimizeProposition*>* propositionsDict, NSError* error) {
if (error != nil) {
// handle error
return;
}
AEPOptimizeProposition* proposition1 = propositionsDict[decisionScope1];
// read proposition1 offers
AEPOptimizeProposition* proposition2 = propositionsDict[decisionScope2];
// read proposition2 offers
}];
getPropositionsWithTimeout
This API retrieves the previously fetched propositions for the provided decision scopes from the in-memory extension propositions cache, similar to getPropositions. The completion callback is invoked with the decision propositions corresponding to the given decision scopes. If a certain decision scope has not been fetched prior to this API call, it will not be included in the returned propositions.
Additionally, this API allows specifying a timeout for the operation. If the propositions retrieval does not complete within the given timeout, an error is returned, providing improved control over handling delays and ensuring timely application responses.
When connected to Assurance for previewing content, this method will return simulated results.
Android Java
- decisionScopes is a list of decision scopes for which propositions are requested.
- timeoutSeconds is a duration in seconds specifying the maximum time
getPropositionwill wait for completion before returning AdobeError. - callback
callmethod is invoked with propositions map of typeMap<DecisionScope, OptimizeProposition>. If the callback is an instance of AdobeCallbackWithError, and if the operation times out or an error occurs in retrieving propositions, thefailmethod is invoked with the appropriate AdobeError.
data-slots=heading, code
data-repeat=2
Syntax
public static void getPropositions(final List<DecisionScope> decisionScopes, final double timeoutSeconds, final AdobeCallback<Map<DecisionScope, OptimizeProposition>> callback)
Example
final DecisionScope decisionScope1 = DecisionScope("xcore:offer-activity:1111111111111111", "xcore:offer-placement:1111111111111111", 2);
final DecisionScope decisionScope2 = new DecisionScope("myScope");
final List<DecisionScope> decisionScopes = new ArrayList<>();
decisionScopes.add(decisionScope1);
decisionScopes.add(decisionScope2);
Optimize.getPropositions(scopes, 10.0, new AdobeCallbackWithError<Map<DecisionScope, OptimizeProposition>>() {
@Override
public void fail(final AdobeError adobeError) {
// handle error
}
@Override
public void call(Map<DecisionScope, OptimizeProposition> propositionsMap) {
if (propositionsMap != null && !propositionsMap.isEmpty()) {
// get the propositions for the given decision scopes
if (propositionsMap.contains(decisionScope1)) {
final OptimizeProposition proposition1 = propsMap.get(decisionScope1)
// read proposition1 offers
}
if (propositionsMap.contains(decisionScope2)) {
final OptimizeProposition proposition2 = propsMap.get(decisionScope2)
// read proposition2 offers
}
}
}
});
iOS Swift
- decisionScopes is an array of decision scopes for which propositions are requested.
- timeout is a duration in seconds specifying the maximum time
getPropositionwill wait for completion before returningError. - completion is invoked with propositions dictionary of type
[DecisionScope: OptimizeProposition]. AnErroris returned if SDK fails to retrieve the propositions.
data-slots=heading, code
data-repeat=2
Syntax
static func getPropositions(for decisionScopes: [DecisionScope],
timeout: TimeInterval,
_ completion: @escaping ([DecisionScope: OptimizeProposition]?, Error?) -> Void)
Example
let decisionScope1 = DecisionScope(activityId: "xcore:offer-activity:1111111111111111",
placementId: "xcore:offer-placement:1111111111111111",
itemCount: 2)
let decisionScope2 = DecisionScope(name: "myScope")
Optimize.getPropositions(for: [decisionScope1, decisionScope2], timeout: 1.0) { propositionsDict, error in
if let error = error {
// handle error
return
}
if let propositionsDict = propositionsDict {
// get the propositions for the given decision scopes
if let proposition1 = propositionsDict[decisionScope1] {
// read proposition1 offers
}
if let proposition2 = propositionsDict[decisionScope2] {
// read proposition2 offers
}
}
}
iOS Objective-C
- decisionScopes is an array of decision scopes for which propositions are requested.
- timeout is a duration in seconds specifying the maximum time
getPropositionwill wait for completion before returningNSError. - completion is invoked with propositions dictionary of type
NSDictionary<AEPDecisionScope*, AEPOptimizeProposition*>. AnNSErroris returned if SDK fails to retrieve the propositions.
data-slots=heading, code
data-repeat=2
Syntax
+ (void)getPropositions:(NSArray<AEPDecisionScope *> *_Nonnull) decisionScopes
timeout:(NSTimeInterval) timeout
completion:(void (^_Nonnull)(NSDictionary<AEPDecisionScope *, AEPOptimizeProposition *> *_Nullable propositionsDict, NSError *_Nullable error)) completion;
Example
AEPDecisionScope* decisionScope1 = [[AEPDecisionScope alloc] initWithActivityId: @"xcore:offer-activity:1111111111111111"
placementId: @"xcore:offer-placement:1111111111111111"
itemCount: 2];
AEPDecisionScope* decisionScope2 = [[AEPDecisionScope alloc] initWithName: @"myScope"];
[AEPMobileOptimize getPropositions: @[decisionScope1, decisionScope2]
timeout:1.0
completion: ^(NSDictionary<AEPDecisionScope*, AEPOptimizeProposition*>* propositionsDict, NSError* error) {
if (error != nil) {
// handle error
return;
}
AEPOptimizeProposition* proposition1 = propositionsDict[decisionScope1];
// read proposition1 offers
AEPOptimizeProposition* proposition2 = propositionsDict[decisionScope2];
// read proposition2 offers
}];
onPropositionsUpdate
This API registers a permanent callback which is invoked whenever the Edge extension dispatches a response event with an eventType of personalization.response. Additionally, the callback is only invoked if the response event contains at least one valid offer. The personalization response can be triggered by the updatePropositions API.
data-variant=warning
data-slots=text
onPropositionsUpdate will not be invoked if the Experience Edge Network returns an error for the personalization query, or if the response event payload is empty or has invalid proposition data. This API should not be used for handling errors that might occur when updatePropositions is called.When connected to Assurance for previewing content, this method will return simulated results.
Android Java
- callback
callmethod is invoked with propositions map of typeMap<DecisionScope, OptimizeProposition>. Errors and empty responses for personalization queries are not passed back in thecallmethod.
data-slots=heading, code
data-repeat=2
Syntax
public static void onPropositionsUpdate(final AdobeCallback<Map<DecisionScope, OptimizeProposition>> callback)
Example
Optimize.onPropositionsUpdate(new AdobeCallback<Map<DecisionScope, OptimizeProposition>>() {
@Override
public void call(final Map<DecisionScope, OptimizeProposition> propositionsMap) {
if (propositionsMap != null && !propositionsMap.isEmpty()) {
// handle propositions
}
}
});
iOS Swift
- action is invoked with propositions dictionary of type
[DecisionScope: OptimizeProposition]. Errors and empty responses for personalization queries are not passed back in action.
data-slots=heading, code
data-repeat=2
Syntax
static func onPropositionsUpdate(perform action: @escaping ([DecisionScope: OptimizeProposition]?) -> Void)
Example
Optimize.onPropositionsUpdate { propositionsDict in
if let propositionsDict = propositionsDict {
// handle propositions
}
}
iOS Objective-C
- action is invoked with propositions dictionary of type
NSDictionary<AEPDecisionScope*, AEPOptimizeProposition*>. Errors and empty responses for personalization queries are not passed back in action.
data-slots=heading, code
data-repeat=2
Syntax
+ (void) onPropositionsUpdate: (void (^ _Nonnull)(NSDictionary<AEPDecisionScope*, AEPOptimizeProposition*>* _Nullable)) action;
Example
[AEPMobileOptimize onPropositionsUpdate: ^(NSDictionary<AEPDecisionScope*, AEPOptimizeProposition*>* propositionsDict) {
// handle propositions
}];
registerExtension
data-variant=warning
data-slots=text1, text2
MobileCore.registerExtensions() API instead.Android Java
data-slots=heading, code
data-repeat=2
Syntax
public static void registerExtension()
Example
Optimize.registerExtension();
resetIdentities
data-variant=warning
data-slots=text
This MobileCore API is a request to each extension to reset its identities. Every extension responds to this request in its own unique manner. For example, Optimize extension uses this API call to clear out its client-side in-memory propositions cache. For details on syntax, usage and availability, refer to Mobile Core - Reset identities.
updatePropositions
data-variant=warning
data-slots=text1, text2
Optimize.updatePropositions or Optimize.updatePropositions APIs instead.This API dispatches an Event for the Edge network extension to fetch decision propositions, for the provided decision scopes array, from the decisioning services enabled in the Experience Edge. The returned decision propositions are cached in-memory in the Optimize SDK extension and can be retrieved using getPropositions API.
When connected to Assurance for previewing content, this method will override the simulated results. It will remove all simluated results and serve the actual data.
Android Java
- decisionScopes is a list of decision scopes for which propositions need updating.
- xdm is a map containing additional XDM formatted data to be attached to the Experience Event.
- data is a map containing additional freeform data to be attached to the Experience Event.
data-slots=heading, code
data-repeat=2
Syntax
public static void updatePropositions(final List<DecisionScope> decisionScopes, final Map<String, Object> xdm, final Map<String, Object> data)
Example
final DecisionScope decisionScope1 = DecisionScope("xcore:offer-activity:1111111111111111", "xcore:offer-placement:1111111111111111", 2);
final DecisionScope decisionScope2 = new DecisionScope("myScope");
final List<DecisionScope> decisionScopes = new ArrayList<>();
decisionScopes.add(decisionScope1);
decisionScopes.add(decisionScope2);
Optimize.updatePropositions(decisionScopes,
new HashMap<String, Object>() {
{
put("xdmKey", "xdmValue");
}
},
new HashMap<String, Object>() {
{
put("dataKey", "dataValue");
}
});
iOS Swift
- decisionScopes is an array of decision scopes for which propositions need updating.
- xdm is a dictionary containing additional XDM formatted data to be attached to the Experience Event.
- data is a dictionary containing additional freeform data to be attached to the Experience Event.
data-slots=heading, code
data-repeat=2
Syntax
static func updatePropositions(for decisionScopes: [DecisionScope],
withXdm xdm: [String: Any]?,
andData data: [String: Any]? = nil)
Example
let decisionScope1 = DecisionScope(activityId: "xcore:offer-activity:1111111111111111",
placementId: "xcore:offer-placement:1111111111111111",
itemCount: 2)
let decisionScope2 = DecisionScope(name: "myScope")
Optimize.updatePropositions(for: [decisionScope1, decisionScope2]
withXdm: ["xdmKey": "xdmValue"]
andData: ["dataKey": "dataValue"])
iOS Objective-C
- decisionScopes is an array of decision scopes for which propositions need updating.
- xdm is a dictionary containing additional XDM formatted data to be attached to the Experience Event.
- data is a dictionary containing additional freeform data to be attached to the Experience Event.
data-slots=heading, code
data-repeat=2
Syntax
+ (void) updatePropositions: (NSArray<AEPDecisionScope*>* _Nonnull) decisionScopes
withXdm: (NSDictionary<NSString*, id>* _Nullable) xdm
andData: (NSDictionary<NSString*, id>* _Nullable) data;
Example
AEPDecisionScope* decisionScope1 = [[AEPDecisionScope alloc] initWithActivityId: @"xcore:offer-activity:1111111111111111"
placementId: @"xcore:offer-placement:1111111111111111"
itemCount: 2];
AEPDecisionScope* decisionScope2 = [[AEPDecisionScope alloc] initWithName: @"myScope"];
[AEPMobileOptimize updatePropositions: @[decisionScope1, decisionScope2]
withXdm: @{@"xdmKey": @"xdmValue"}
andData: @{@"dataKey": @"dataValue"}];
updatePropositionsWithCompletionHandler
This API dispatches an event for the Edge network extension to fetch decision propositions, for the provided decision scopes array, from the decisioning services enabled in the Experience Edge. The returned decision propositions are cached in-memory in the Optimize SDK extension and can be retrieved using getPropositions API.
data-variant=help
data-slots=text
updatePropositions supports network timeout and fatal errors returned by edge network along with fetched propositions data. The SDK's internal retry mechanism handles the recoverable HTTP errors. As a result, recoverable HTTP errors are not returned through this callback.Android Java
- decisionScopes is a list of decision scopes for which propositions need updating.
- xdm is a map containing additional XDM formatted data to be attached to the Experience Event.
- data is a map containing additional freeform data to be attached to the Experience Event.
- callback is an optional completion handler that is invoked at the completion of the edge request. The
callmethod is invoked with propositions map of typeMap<DecisionScope, OptimizeProposition>. If the callback is an instance ofAdobeCallbackWithOptimizeError, and if the operation times out or an error occurs in retrieving propositions, thefailmethod is invoked with the appropriate AEPOptimizeError. Note: In certain cases, both the success and failure callbacks may be triggered. To handle these cases, ensure that your implementation checks for both successful propositions and errors within the callback, as both may be present simultaneously.
data-slots=heading, code
data-repeat=2
Syntax
public static void updatePropositions(final List<DecisionScope> decisionScopes,
final Map<String, Object> xdm,
final Map<String, Object> data,
final AdobeCallback<Map<DecisionScope, OptimizeProposition>> callback)
Example
final DecisionScope decisionScope1 = DecisionScope("xcore:offer-activity:1111111111111111", "xcore:offer-placement:1111111111111111", 2);
final DecisionScope decisionScope2 = new DecisionScope("myScope");
final List<DecisionScope> decisionScopes = new ArrayList<>();
decisionScopes.add(decisionScope1);
decisionScopes.add(decisionScope2);
Optimize.updatePropositions(decisionScopes,
new HashMap<String, Object>() {
{
put("xdmKey", "xdmValue");
}
},
new HashMap<String, Object>() {
{
put("dataKey", "dataValue");
}
},
new AdobeCallbackWithOptimizeError<Map<DecisionScope, OptimizeProposition>>() {
@Override
public void fail(AEPOptimizeError optimizeError) {
responseError = optimizeError;
}
@Override
public void call(Map<DecisionScope, OptimizeProposition> propositionsMap) {
responseMap = propositionsMap;
}
});
iOS Swift
- decisionScopes is an array of decision scopes for which propositions need updating.
- xdm is a dictionary containing additional XDM formatted data to be attached to the Experience Event.
- data is a dictionary containing additional freeform data to be attached to the Experience Event.
- completion is a optional completion handler invoked at the completion of the edge request with map of successful decision scopes to propositions and errors, if any.
data-slots=heading, code
data-repeat=2
Syntax
static func updatePropositions(for decisionScopes: [DecisionScope],
withXdm xdm: [String: Any]?,
andData data: [String: Any]? = nil,
_completion: (([DecisionScope: OptimizeProposition]?, Error?) -> Void)? = nil)
Example
let decisionScope1 = DecisionScope(activityId: "xcore:offer-activity:1111111111111111",
placementId: "xcore:offer-placement:1111111111111111",
itemCount: 2)
let decisionScope2 = DecisionScope(name: "myScope")
Optimize.updatePropositions(for: [decisionScope1, decisionScope2]
withXdm: ["xdmKey": "xdmValue"]
andData: ["dataKey": "dataValue"]) { data, error in
if let error = error as? AEPOptimizeError {
// handle error
}
}
iOS Objective-C
- decisionScopes is an array of decision scopes for which propositions are requested.
- xdm is a dictionary containing additional XDM formatted data to be attached to the Experience Event.
- data is a dictionary containing additional freeform data to be attached to the Experience Event.
- completion is invoked with propositions dictionary of type
NSDictionary<AEPDecisionScope*, AEPOptimizeProposition*>. AnNSErroris returned if SDK fails to retrieve the propositions.
data-slots=heading, code
data-repeat=2
Syntax
+ (void) updatePropositions: (NSArray<AEPDecisionScope*>* _Nonnull) decisionScopes
withXdm: (NSDictionary<NSString*, id>* _Nullable) xdm
andData: (NSDictionary<NSString*, id>* _Nullable) data
completion: (void (^ _Nonnull)(NSDictionary<AEPDecisionScope*, AEPOptimizeProposition*>* _Nullable propositionsDict, NSError* _Nullable error)) completion;
Example
AEPDecisionScope* decisionScope1 = [[AEPDecisionScope alloc] initWithActivityId: @"xcore:offer-activity:1111111111111111"
placementId: @"xcore:offer-placement:1111111111111111"
itemCount: 2];
AEPDecisionScope* decisionScope2 = [[AEPDecisionScope alloc] initWithName: @"myScope"];
[AEPMobileOptimize updatePropositions: @[decisionScope1, decisionScope2]
withXdm: @{@"xdmKey": @"xdmValue"}
andData: @{@"dataKey": @"dataValue"}]
completion: ^(NSDictionary<AEPDecisionScope* AEPOptimizeProposition*>* propositionsDict, NSError* error) {
if (error != nil) {
// handle error
return;
}
AEPOptimizeProposition* proposition1 = propositionsDict[decisionScope1];
// read proposition1 offers
AEPOptimizeProposition* proposition2 = propositionsDict[decisionScope2];
// read proposition2 offers
}];
updatePropositionsWithCompletionHandlerAndTimeout
This API dispatches an event for the Edge network extension to fetch decision propositions for the provided decision scopes array from the decisioning services enabled in the Experience Edge. Similar to updatePropositionsWithCompletionHandler, the returned decision propositions are cached in-memory within the Optimize SDK extension and can be retrieved using the getPropositions API.
Additionally, this API allows specifying a completion timeout, ensuring that the operation either completes within the given time frame or returns an error indicating a timeout. This feature provides better control over the responsiveness of the application when interacting with decisioning services.
data-variant=help
data-slots=text
updatePropositions supports network timeout and fatal errors returned by edge network along with fetched propositions data. The SDK's internal retry mechanism handles the recoverable HTTP errors. As a result, recoverable HTTP errors are not returned through this callback.Android Java
- decisionScopes is a list of decision scopes for which propositions need updating.
- xdm is a map containing additional XDM formatted data to be attached to the Experience Event.
- data is a map containing additional freeform data to be attached to the Experience Event.
- timeoutSeconds is a duration in seconds specifying the maximum time
updatePropositionwill wait for completion before returning AEPOptimizeError which contains AdobeError.CALLBACK_TIMEOUT. - callback is an optional completion handler that is invoked at the completion of the edge request. The
callmethod is invoked with propositions map of typeMap<DecisionScope, OptimizeProposition>. If the callback is an instance ofAdobeCallbackWithOptimizeError, and if the operation times out or an error occurs in retrieving propositions, thefailmethod is invoked with the appropriate AEPOptimizeError. Note: In certain cases, both the success and failure callbacks may be triggered. To handle these cases, ensure that your implementation checks for both successful propositions and errors within the callback, as both may be present simultaneously.
data-slots=heading, code
data-repeat=2
Syntax
public static void updatePropositions(final List<DecisionScope> decisionScopes,
final Map<String, Object> xdm,
final Map<String, Object> data,
final double timeoutSeconds,
final AdobeCallback<Map<DecisionScope, OptimizeProposition>> callback)
Example
final DecisionScope decisionScope1 = DecisionScope("xcore:offer-activity:1111111111111111", "xcore:offer-placement:1111111111111111", 2);
final DecisionScope decisionScope2 = new DecisionScope("myScope");
final List<DecisionScope> decisionScopes = new ArrayList<>();
decisionScopes.add(decisionScope1);
decisionScopes.add(decisionScope2);
Optimize.updatePropositions(decisionScopes,
new HashMap<String, Object>() {
{
put("xdmKey", "xdmValue");
}
},
new HashMap<String, Object>() {
{
put("dataKey", "dataValue");
}
},
10.0,
new AdobeCallbackWithOptimizeError<Map<DecisionScope, OptimizeProposition>>() {
@Override
public void fail(AEPOptimizeError optimizeError) {
responseError = optimizeError;
}
@Override
public void call(Map<DecisionScope, OptimizeProposition> propositionsMap) {
responseMap = propositionsMap;
}
});
iOS Swift
- decisionScopes is an array of decision scopes for which propositions need updating.
- xdm is a dictionary containing additional XDM formatted data to be attached to the Experience Event.
- data is a dictionary containing additional freeform data to be attached to the Experience Event.
- timeout is a duration in seconds specifying the maximum time
updatePropositionwill wait for completion before returningAEPOptimizeError. - completion is a optional completion handler invoked at the completion of the edge request with map of successful decision scopes to propositions and
AEPOptimizeError, if any.
data-slots=heading, code
data-repeat=2
Syntax
static func updatePropositions(for decisionScopes: [DecisionScope],
withXdm xdm: [String: Any]?,
andData data: [String: Any]? = nil,
timeout: TimeInterval,
_completion: (([DecisionScope: OptimizeProposition]?, Error?) -> Void)? = nil)
Example
let decisionScope1 = DecisionScope(activityId: "xcore:offer-activity:1111111111111111",
placementId: "xcore:offer-placement:1111111111111111",
itemCount: 2)
let decisionScope2 = DecisionScope(name: "myScope")
Optimize.updatePropositions(for: [decisionScope1, decisionScope2],
withXdm: ["xdmKey": "xdmValue"],
andData: ["dataKey": "dataValue"],
timeout: 1.0) { data, error in
if let error = error as? AEPOptimizeError {
// handle error
}
}
iOS Objective-C
- decisionScopes is an array of decision scopes for which propositions are requested.
- xdm is a dictionary containing additional XDM formatted data to be attached to the Experience Event.
- data is a dictionary containing additional freeform data to be attached to the Experience Event.
- timeout is a duration in seconds specifying the maximum time
updatePropositionwill wait for completion before returningNSError. - completion is invoked with propositions dictionary of type
NSDictionary<AEPDecisionScope*, AEPOptimizeProposition*>. AnNSErroris returned if SDK fails to retrieve the propositions.
data-slots=heading, code
data-repeat=2
Syntax
+ (void) updatePropositions: (NSArray<AEPDecisionScope*>* _Nonnull) decisionScopes
withXdm: (NSDictionary<NSString*, id>* _Nullable) xdm
andData: (NSDictionary<NSString*, id>* _Nullable) data
timeout:(NSTimeInterval) timeout
completion: (void (^ _Nonnull)(NSDictionary<AEPDecisionScope*, AEPOptimizeProposition*>* _Nullable propositionsDict, NSError* _Nullable error)) completion;
Example
AEPDecisionScope* decisionScope1 = [[AEPDecisionScope alloc] initWithActivityId: @"xcore:offer-activity:1111111111111111"
placementId: @"xcore:offer-placement:1111111111111111"
itemCount: 2];
AEPDecisionScope* decisionScope2 = [[AEPDecisionScope alloc] initWithName: @"myScope"];
[AEPMobileOptimize updatePropositions: @[decisionScope1, decisionScope2]
withXdm: @{@"xdmKey": @"xdmValue"}
andData: @{@"dataKey": @"dataValue"}]
timeout:1.0
completion: ^(NSDictionary<AEPDecisionScope* AEPOptimizeProposition*>* propositionsDict, NSError* error) {
if (error != nil) {
// handle error
return;
}
AEPOptimizeProposition* proposition1 = propositionsDict[decisionScope1];
// read proposition1 offers
AEPOptimizeProposition* proposition2 = propositionsDict[decisionScope2];
// read proposition2 offers
}];
Public classes
DecisionScopeDecisionScopeAEPDecisionScopePropositionOptimizePropositionAEPOptimizePropositionOfferOfferAEPOfferOfferUtils__________OptimizeOptimizeOptimizeAEPOptimizeErrorAEPOptimizeErrorAEPOptimizeErrorDecisionScope
This class represents the decision scope which is used to fetch the decision propositions from the Edge decisioning services. The encapsulated scope name can also represent the Base64-encoded JSON string created using the provided activityId, placementId, and itemCount.
Android Java
/**
* {@code DecisionScope} class represents a scope used to fetch personalized offers from the Experience Edge network.
*/
public class DecisionScope {
/**
* Constructor creates a {@code DecisionScope} using the provided {@code name}.
*
* @param name {@link String} containing scope name.
*/
public DecisionScope(final String name) {...}
/**
* Constructor creates a {@code DecisionScope} using the provided {@code activityId} and {@code placementId}.
*
* This constructor assumes the item count for the given scope to be {@value #DEFAULT_ITEM_COUNT}.
*
* @param activityId {@link String} containing activity identifier for the given scope.
* @param placementId {@code String} containing placement identifier for the given scope.
*/
public DecisionScope(final String activityId, final String placementId) {...}
/**
* Constructor creates a {@code DecisionScope} using the provided {@code activityId} and {@code placementId}.
*
* @param activityId {@link String} containing activity identifier for the given scope.
* @param placementId {@code String} containing placement identifier for the given scope.
* @param itemCount {@code String} containing number of items to be returned for the given scope.
*/
public DecisionScope(final String activityId, final String placementId, final int itemCount) {...}
/**
* Gets the name for this scope.
*
* @return {@link String} containing the scope name.
*/
public String getName() {...}
}
iOS Swift
/// `DecisionScope` class is used to create decision scopes for personalization query requests to Experience Edge Network.
@objc(AEPDecisionScope)
public class DecisionScope: NSObject, Codable {
/// Decision scope name
@objc public let name: String
/// Creates a new decision scope using the given scope `name`.
///
/// - Parameter name: string representation for the decision scope.
@objc
public init(name: String) {...}
/// Creates a new decision scope using the given `activityId`, `placementId` and `itemCount`.
///
/// This initializer creates a scope name by Base64 encoding the JSON string created using the provided data.
///
/// If `itemCount` == 1, JSON string is
///
/// {"activityId":#activityId,"placementId":#placementId}
/// otherwise,
///
/// {"activityId":#activityId,"placementId":#placementId,"itemCount":#itemCount}
/// - Parameters:
/// - activityId: unique activity identifier for the decisioning activity.
/// - placementId: unique placement identifier for the decisioning activity offer.
/// - itemCount: number of offers to be returned from the server.
@objc
public convenience init(activityId: String, placementId: String, itemCount: UInt = 1) {...}
}
OptimizeProposition
This class represents the decision propositions received from the decisioning services, upon a personalization query request to the Experience Edge network.
data-variant=warning
data-slots=text
- In SDK versions lower than Android 3.0.0 and iOS 5.0.0, this class was named
Proposition - OptimizeProposition for ODE offers do not support the
activityandplacementobjects in SDK versions prior to Android 3.6.0 and iOS 5.6.0
Android Java
/**
* {@code OptimizeProposition} class represents a proposition containing personalized offers from the Experience Edge network.
* This class supports both Target and ODE (Offer Decisioning Engine) propositions.
*
* Note: Activity and placement object support for ODE offers is available from SDK version 3.6.0 onwards.
* For versions below 3.6.0, these objects will be null for ODE offers.
*/
public class OptimizeProposition {
/**
* Constructor creates a {@code OptimizeProposition} using the provided proposition details.
*
* @param id {@link String} containing proposition identifier.
* @param offers {@code List<Offer>} containing proposition items.
* @param scope {@code String} containing encoded scope.
* @param scopeDetails {@code Map<String, Object>} containing scope details.
* @param activity {@code Map<String, Object>} containing activity details for ODE offers.
* @param placement {@code Map<String, Object>} containing placement details for ODE offers.
*/
OptimizeProposition(
final String id,
final List<Offer> offers,
final String scope,
final Map<String, Object> scopeDetails,
final Map<String, Object> activity,
final Map<String, Object> placement
) {...}
/**
* Gets the {@code OptimizeProposition} identifier.
*
* @return {@link String} containing the {@link OptimizeProposition} identifier.
*/
public String getId() {...}
/**
* Gets the {@code OptimizeProposition} items.
*
* @return {@code List<Offer>} containing the {@link OptimizeProposition} items.
*/
public List<Offer> getOffers() {...}
/**
* Gets the {@code OptimizeProposition} scope.
*
* @return {@link String} containing the encoded {@link OptimizeProposition} scope.
*/
public String getScope() {...}
/**
* Gets the {@code OptimizeProposition} scope details.
*
* @return {@code Map<String, Object>} or {@code null} containing the {@link OptimizeProposition} scope details.
*/
@Nullable public Map<String, Object> getScopeDetails() {...}
/**
* Gets the {@code OptimizeProposition} activity details for ODE offers.
*
* @return {@code Map<String, Object>} or {@code null} containing the activity details.
*/
@Nullable public Map<String, Object> getActivity() {...}
/**
* Gets the {@code OptimizeProposition} placement details for ODE offers.
*
* @return {@code Map<String, Object>} or {@code null} containing the placement details.
*/
@Nullable public Map<String, Object> getPlacement() {...}
/**
* Generates a map containing XDM formatted data for {@code Experience Event - OptimizeProposition Reference} field group from this {@code OptimizeProposition}.
*
* The returned XDM data does not contain {@code eventType} for the Experience Event.
*
* @return {@code Map<String, Object>} containing the XDM data for the OptimizeProposition reference.
*/
public Map<String, Object> generateReferenceXdm() {...}
}
iOS Swift
/// `OptimizeProposition` class represents a proposition containing personalized offers from the Experience Edge network.
/// This class supports both Target and ODE (Offer Decisioning Engine) propositions.
///
/// Note: Activity and placement object support for ODE offers is available from SDK version 5.6.0 onwards.
/// For versions below 5.6.0, these objects will be nil for ODE offers.
@objc(AEPOptimizeProposition)
public class OptimizeProposition: NSObject, Codable {
/// Unique proposition identifier
@objc public let id: String
/// Array containing proposition decision options
@objc public lazy var offers: [Offer] = {...}()
/// Decision scope string
@objc public let scope: String
/// Scope details dictionary
@objc public var scopeDetails: [String: Any]?
/// Activity details dictionary for ODE offers
@objc public var activity: [String: Any]?
/// Placement details dictionary for ODE offers
@objc public var placement: [String: Any]?
}
The OptimizeProposition class extension provides a method for generating XDM data for Proposition Reference field group which can be used for proposition tracking.
/// `OptimizeProposition` extension
@objc
public extension OptimizeProposition {
/// Creates a dictionary containing XDM formatted data for `Experience Event - Proposition Reference` field group from the given proposition.
///
/// The Edge `sendEvent(experienceEvent:_:)` API can be used to dispatch this data in an Experience Event along with any additional XDM, free-form data, or override dataset identifier.
///
/// - Note: The returned XDM data does not contain an `eventType` for the Experience Event.
/// - Returns A dictionary containing XDM data for the proposition reference.
func generateReferenceXdm() -> [String: Any] {...}
}
Offer
This class represents the proposition option received from the decisioning services, upon a personalization query to the Experience Edge network.
data-variant=warning
data-slots=text
Offer Score was int. It is now changed to doubleAndroid Java
public class Offer {
/**
* {@code Offer} Builder.
*/
public static class Builder {
/**
* Builder constructor with required {@code Offer} attributes as parameters.
*
* It sets default values for remaining {@link Offer} attributes.
*
* @param id required {@link String} containing {@code Offer} identifier.
* @param type required {@link OfferType} indicating the {@code Offer} type.
* @param content required {@link String} containing the {@code Offer} content.
*/
public Builder(final String id, final OfferType type, final String content) {...}
/**
* Sets the etag for this {@code Offer}.
*
* @param etag {@link String} containing {@link Offer} etag.
* @return this Offer {@link Builder}
* @throws UnsupportedOperationException if this method is invoked after {@link Builder#build()}.
*/
public Builder setEtag(final String etag) {...}
/**
* Sets the score for this {@code Offer}.
*
* @param score {@code double} containing {@link Offer} score.
* @return this Offer {@link Builder}
* @throws UnsupportedOperationException if this method is invoked after {@link Builder#build()}.
*/
public Builder setScore(final double score) {...}
/**
* Sets the schema for this {@code Offer}.
*
* @param schema {@link String} containing {@link Offer} schema.
* @return this Offer {@link Builder}
* @throws UnsupportedOperationException if this method is invoked after {@link Builder#build()}.
*/
public Builder setSchema(final String schema) {...}
/**
* Sets the metadata for this {@code Offer}.
*
* @param meta {@code Map<String, Object>} containing {@link Offer} metadata.
* @return this Offer {@link Builder}
* @throws UnsupportedOperationException if this method is invoked after {@link Builder#build()}.
*/
public Builder setMeta(final Map<String, Object> meta) {...}
/**
* Sets the language for this {@code Offer}.
*
* @param language {@code List<String>} containing supported {@link Offer} language.
* @return this Offer {@link Builder}
* @throws UnsupportedOperationException if this method is invoked after {@link Builder#build()}.
*/
public Builder setLanguage(final List<String> language) {...}
/**
* Sets the characteristics for this {@code Offer}.
*
* @param characteristics {@code Map<String, String>} containing {@link Offer} characteristics.
* @return this Offer {@link Builder}
* @throws UnsupportedOperationException if this method is invoked after {@link Builder#build()}.
*/
public Builder setCharacteristics(final Map<String, String> characteristics) {...}
/**
* Builds and returns the {@code Offer} object.
*
* @return {@link Offer} object or null.
* @throws UnsupportedOperationException if this method is invoked after {@link Builder#build()}.
*/
public Offer build() {...}
}
/**
* Gets the {@code Offer} identifier.
*
* @return {@link String} containing the {@link Offer} identifier.
*/
public String getId() {...}
/**
* Gets the {@code Offer} etag.
*
* @return {@link String} containing the {@link Offer} etag.
*/
public String getEtag() {...}
/**
* Gets the {@code Offer} score.
*
* @return {@code double} containing the {@link Offer} score.
*/
public double getScore() {...}
/**
* Gets the {@code Offer} schema.
*
* @return {@link String} containing the {@link Offer} schema.
*/
public String getSchema() {...}
/**
* Gets the {@code Offer} metadata.
*
* @return {@code Map<String, Object>} containing the {@link Offer} metadata.
*/
public Map<String, Object> getMeta() {...}
/**
* Gets the {@code Offer} type.
*
* @return {@link OfferType} indicating the {@link Offer} type.
*/
public OfferType getType() {...}
/**
* Gets the {@code Offer} language.
*
* @return {@code List<String>} containing the supported {@link Offer} language.
*/
public List<String> getLanguage() {...}
/**
* Gets the {@code Offer} content.
*
* @return {@link String} containing the {@link Offer} content.
*/
public String getContent() {...}
/**
* Gets the {@code Offer} characteristics.
*
* @return {@code Map<String, String>} containing the {@link Offer} characteristics.
*/
public Map<String, String> getCharacteristics() {...}
/**
* Gets the containing {@code OptimizeProposition} for this {@code Offer}.
*
* @return {@link OptimizeProposition} instance.
*/
public OptimizeProposition getProposition() {...}
/**
* Dispatches an event for the Edge network extension to send an Experience Event to the Edge network with the display interaction data for the
* given {@code OptimizeProposition} offer.
*/
public void displayed() {...}
/**
* Dispatches an event for the Edge network extension to send an Experience Event to the Edge network with the tap interaction data for the
* given {@code OptimizeProposition} offer.
*/
public void tapped() {...}
/**
* Generates a map containing XDM formatted data for {@code Experience Event - Proposition Interactions} field group from this {@code OptimizeProposition} item.
*
* The returned XDM data does contain the {@code eventType} for the Experience Event with value {@code decisioning.propositionDisplay}.
*
* Note: The Edge sendEvent API can be used to dispatch this data in an Experience Event along with any additional XDM, free-form data, and override
* dataset identifier.
*
* @return {@code Map<String, Object>} containing the XDM data for the proposition interaction.
*/
public Map<String, Object> generateDisplayInteractionXdm() {...}
/**
* Generates a map containing XDM formatted data for {@code Experience Event - Proposition Interactions} field group from this {@code OptimizeProposition} offer.
*
* The returned XDM data contains the {@code eventType} for the Experience Event with value {@code decisioning.propositionInteract}.
*
* Note: The Edge sendEvent API can be used to dispatch this data in an Experience Event along with any additional XDM, free-form data, and override
* dataset identifier.
*
* @return {@code Map<String, Object>} containing the XDM data for the proposition interaction.
*/
public Map<String, Object> generateTapInteractionXdm() {...}
}
iOS Swift
/// `Offer` class
@objc(AEPOffer)
public class Offer: NSObject, Codable {
/// Unique Offer identifier
@objc public let id: String
/// Offer revision detail at the time of the request
@objc public let etag: String
/// Offer priority score
@objc public let score: Double
/// Offer schema string
@objc public let schema: String
/// Offer metadata
@objc public let meta: [String: Any]?
/// Offer type as represented in enum `OfferType`
@objc public let type: OfferType
/// Optional Offer language array
@objc public let language: [String]?
/// Offer content string
@objc public let content: String
/// Optional Offer characteristics dictionary
@objc public let characteristics: [String: String]?
}
The Offer class extension provides methods for generating XDM data for Proposition Interactions field group which can be used for proposition tracking.
/// `Offer` extension
@objc
public extension Offer {
/// Creates a dictionary containing XDM formatted data for `Experience Event - Proposition Interactions` field group from the given proposition option.
///
/// The Edge `sendEvent(experienceEvent:_:)` API can be used to dispatch this data in an Experience Event along with any additional XDM, free-form data, or override dataset identifier.
/// If the proposition reference within the option is released and no longer valid, the method returns `nil`.
///
/// - Note: The returned XDM data also contains the `eventType` for the Experience Event with value `decisioning.propositionDisplay`.
/// - Returns A dictionary containing XDM data for the proposition interactions.
func generateDisplayInteractionXdm() -> [String: Any]? {...}
/// Creates a dictionary containing XDM formatted data for `Experience Event - Proposition Interactions` field group from the given proposition option.
///
/// The Edge `sendEvent(experienceEvent:_:)` API can be used to dispatch this data in an Experience Event along with any additional XDM, free-form data, or override dataset identifier.
/// If the proposition reference within the option is released and no longer valid, the method returns `nil`.
///
/// - Note: The returned XDM data also contains the `eventType` for the Experience Event with value `decisioning.propositionInteract`.
/// - Returns A dictionary containing XDM data for the proposition interactions.
func generateTapInteractionXdm() -> [String: Any]? {...}
/// Dispatches an event for the Edge extension to send an Experience Event to the Edge network with the display interaction data for the given proposition item.
func displayed() {...}
/// Dispatches an event for the Edge extension to send an Experience Event to the Edge network with the tap interaction data for the given proposition item.
func tapped() {...}
}
OfferUtils | Optimize
Starting from Android SDK version 3.4.0 and iOS SDK version 5.4.0, the Optimize SDK provides enhanced support for batching multiple display propositions track events. The following methods are available in the OfferUtils.kt and Optimize.swift public classes respectively.
Android Kotlin
object OfferUtils {
/**
* Dispatches an event for the Edge network extension to send an Experience Event to the Edge
* network with the display interaction data for the given list of [Offer]s.
*
* This function extracts unique [OptimizeProposition]s from the list of offers based on their
* proposition ID and dispatches an event with multiple propositions.
*
* @see XDMUtils.trackWithData
*/
@JvmStatic
fun List<Offer>.displayed() {...}
/**
* Generates a map containing XDM formatted data for `Experience Event - OptimizeProposition
* Interactions` field group from the given list of [Offer]s.
*
* This function extracts unique [OptimizeProposition]s from the list of offers based on their
* proposition ID and generates XDM data for the interaction.
*
* @return [Map] containing the XDM data for the proposition interaction, or null if the list is empty
* or no valid propositions are found
*/
@JvmStatic
fun List<Offer>.generateDisplayInteractionXdm(): Map<String, Any>? {...}
}
iOS Swift
/// This API dispatches an event for the Edge extension to send an Experience Event to the Edge network with the display interaction data for list of offers passed.
///
/// - Parameter offers: An array of offer.
@objc(displayed:)
static func displayed(for offers: [Offer]){...}
/// This API returns a dictionary containing XDM formatted data for `Experience Event - Proposition Interactions` field group for the list of offers
///
/// The Edge `sendEvent(experienceEvent:_:)` API can be used to dispatch this data in an Experience Event along with any additional XDM, free-form data, or override dataset identifier.
///
/// - Parameter offers: An array of offer.
/// - Note: The returned XDM data also contains the `eventType` for the Experience Event with value `decisioning.propositionInteract`.
/// - Returns A dictionary containing XDM data for the propositon interactions.
/// - SeeAlso: `interactionXdm(for:)`
@objc(generateDisplayInteractionXdm:)
static func generateDisplayInteractionXdm(for offers: [Offer]) -> [String: Any]?{...}
OfferType
An enum indicating the type of an offer, derived from the proposition item format field in personalization query response.
Android Java
public enum OfferType {
UNKNOWN, JSON, TEXT, HTML, IMAGE;
@Override
public String toString() {...}
/**
* Returns the {@code OfferType} for the given {@code format}.
*
* @param format {@link String} containing the {@link Offer} format.
* @return {@link OfferType} indicating the {@code Offer} format.
*/
public static OfferType from(final String format) {...}
}
iOS Swift
/// Enum representing the supported Offer Types.
public enum OfferType: Int, Codable {
/// Unknown Offer type
case unknown = 0
/// JSON Offer
case json = 1
/// Plain text Offer
case text = 2
/// Html Offer
case html = 3
/// Image Offer
case image = 4
/// Initializes OfferType with the provided format string.
/// - Parameter format: Offer format string
init(from format: String) {...}
}
AEPOptimizeError
This class represents the error details returned by the Edge Network while fetching propositions.
iOS Swift
Error details received from Edge response along with AEPError object returned with values:
- AEPError.callbackTimeout is returned when request timeout without any response.
- AEPError.serverErrors is returned for HTTP Status 500.
- AEPError.invalidRequest is returned for HTTP Status 400 - 499 (except 408 and 429).
@objc(AEPOptimizeError)
public class AEPOptimizeError: NSObject, Error {
// This is a URI reference (RFC3986) that identifies the problem type
public let type: String?
// This is the HTTP status code generated by the server for this occurrence of the problem.
public let status: Int?
// This is a short, human-readable summary of the problem type.
public let title: String?
// This is human-readable description of the problem type.
public let detail: String?
// This is a map of additional properties that aid in debugging such as the request ID or the org ID. In some cases, it might contain data specific to the error at hand, such as a list of validation errors.
public let report: [String: Any]?
// This ia a mandatory AEPError representing the high level error status
public var aepError = AEPError.unexpected
// Initializer for AEPOptimizeError based based on the Error details returned by Edge respose
public init(type: String?, status: Int?, title: String?, detail: String?, aepError: AEPError? = nil) {...}
}
Android Kotlin
Error details received from Edge response along with AdobeError object returned with values:
- AdobeError.CALLBACK_TIMEOUT is returned when request timeout without any response.
- AdobeError.SERVER_ERROR is returned for HTTP Status 500.
- AdobeError.INVALID_REQUEST is returned for HTTP Status 400 - 499 (except 408 and 429).
class AEPOptimizeError(val type: String? = "",
val status: Int? = 0,
val title: String? = "",
val detail: String? = "",
var report: Map<String, Any>?,
var adobeError: AdobeError?) {...}