API Reference

onOfferUpdate

Use this API to register a callback, it will be invoked whenever the AEP Offer Decisioning extension receives an offer response from backend services. The Offer Decisioning requests can be triggered by the OfferDecisioning.prefetchOffers() API, Edge.sendEvent() API or consequence rules.
Android
iOS — Swift

Syntax

1
public static void onOfferUpdate(final AdobeCallbackWithError<Map<DecisionScope, List<Offer>>> callback)
Copied!

Example

Java

1
OfferDecisioning.onOfferUpdate(new AdobeCallbackWithError<Map<DecisionScope, List<Offer>>>() {
2
@Override
3
public void fail(AdobeError adobeError) {
4
5
}
6
@Override
7
public void call(Map<DecisionScope, List<Offer>> decisionScopeListMap) {
8
// handle offers
9
}
10
});
Copied!

Syntax

1
func onOfferUpdate(perform: @escaping ([DecisionScope: [Offer]]) -> Void)
Copied!

Example

Here are some examples in Objective C and Swift:
Objective C
1
[AEPMobileOfferDecisioning onOfferUpdateWithPerform:^(NSDictionary<AEPDecisionScope*, NSArray<AEPOffer*>*>* offersDict) {
2
//handle offers response
3
}];
Copied!
Swift
1
OfferDecisioning.onOfferUpdate { offersDict in
2
//handle offers response
3
}
Copied!

prefetchOffers

This API sends a request to the Offer Decisioning Services with the decisioning scopes array. The returned offers will be cached and you can use retrievePrefetchedOffers API to retrieve them later on demand.
Android
iOS — Swift

Syntax

1
public static void prefetchOffers(final List<DecisionScope> decisionScopes)
2
public static void prefetchOffers(final List<DecisionScope> decisionScopes, final OfferExperienceEvent offerExperienceEvent)
Copied!

Example

Java

1
// prefetch offers for decision scopes
2
OfferDecisioning.prefetchOffers(Arrays.asList(
3
new DecisionScope("xcore:offer-activity:124e8bc413c888dd", "xcore:offer-placement:124e8a16430888db")));
4
5
// prefetch offers for decision scopes with additional expxperience event
6
OfferExperienceEvent exEvent = new OfferExperienceEvent(
7
new HashMap<String, Object>() {
8
{
9
put("xdmkey", "xdmvalue");
10
}
11
},null,"override-datasetId");
12
OfferDecisioning.prefetchOffers(Arrays.asList(
13
new DecisionScope("xcore:offer-activity:124e8bc413c888dd", "xcore:offer-placement:124e8a16430888db"),
14
exEvent);
Copied!

Syntax

1
func prefetchOffers(decisionScopes: [DecisionScope], experienceEvent: OfferExperienceEvent? = nil)
Copied!

Examples

Here are some examples in Objective C and Swift:
Objective C
1
AEPDecisionScope* decisionScope = [[AEPDecisionScope alloc] initWithActivityId:@"xcore:offer-activity:124e8bc413c888dd" placementId:@"xcore:offer-placement:124e8a16430888db"];
2
3
// prefetch offers for decision scopes
4
[AEPMobileOfferDecisioning prefetchOffersWithDecisionScopes:@[decisionScope]];
5
6
// prefetch offers for decision scopes with additional expxperience event
7
AEPOfferExperienceEvent* expxperienceEvent = [[AEPOfferExperienceEvent alloc] initWithXdm:@{@"key":@"value"} data:nil datasetIdentifier:nil];
8
9
[AEPMobileOfferDecisioning prefetchOffersWithDecisionScopes:@[decisionScope] experienceEvent:expxperienceEvent];
Copied!
Swift
1
let decisionScope = DecisionScope(activityId: "xcore:offer-activity:124e8bc413c888dd", placementId: "xcore:offer-placement:124e8a16430888db")
2
// prefetch with only decision scopes
3
OfferDecisioning.prefetchOffers(decisionScopes: [decisionScope ])
4
5
// prefetch with additional data
6
let experienceEvent = OfferExperienceEvent(xdm: ["xdmkey": "xdmvalue"], data: nil, datasetIdentifier: "override-datasetId")
7
8
OfferDecisioning.prefetchOffers(decisionScopes: [decisionScope ], experienceEvent: experienceEvent)
Copied!

retrievePrefetchedOffers

This API retrieves the prefetched offers for the targeted decision scopes from the cache. The returned dictionary will only contains offers for decision scopes that has already been prefetched and cached. If a certain decision scope has not been prefetched before, it won't be contained in the returned dictionary.
Android
iOS — Swift

Syntax

1
public static void retrievePrefetchedOffers(final List<DecisionScope> decisionScopes, final AdobeCallbackWithError<Map<DecisionScope, List<Offer>>> callback)
Copied!

Example

Java

1
OfferDecisioning.retrievePrefetchedOffers(Arrays.asList(
2
new DecisionScope("xcore:offer-activity:11cfb1fa93381aca", "xcore:offer-placement:1175009612b0100c")),
3
new AdobeCallbackWithError<Map<DecisionScope, List<Offer>>>() {
4
@Override
5
public void fail(AdobeError adobeError) {
6
7
}
8
@Override
9
public void call(Map<DecisionScope, List<Offer>> decisionScopeListMap) {
10
StringBuffer sb = new StringBuffer();
11
// render the offer with offer.content
12
}
13
});
Copied!

Syntax

1
func retrievePrefetchedOffers(decisionScopes: [DecisionScope], completionHandler: @escaping ([DecisionScope: [Offer]], Error?) -> Void)
Copied!
  • callback is invoked with the [DecisionScope: [Offer]] type of value. An Error will be returned if SDK fails to retrieve the offers.

Examples

Here are the examples in Objective C and Swift:

Objective C

1
AEPDecisionScope* homeDecisionScope = [[AEPDecisionScope alloc] initWithActivityId:@"xcore:offer-activity:124e8bc413c888dd" placementId:@"xcore:offer-placement:124e8a16430888db"];
2
3
[AEPMobileOfferDecisioning retrievePrefetchedOffersWithDecisionScopes:@[homeDecisionScope] completionHandler:^(NSDictionary<AEPDecisionScope *,NSArray<AEPOffer*>*>* offers, NSError * error) {
4
// get the offers for homeDecisionScope
5
NSArray<AEPOffer*>* homeOffers = offers[homeDecisionScope]
6
// deal with the offers
7
}];
Copied!
Swift
1
let homeDecisionScope = DecisionScope(activityId: "xcore:offer-activity:124e8bc413c888dd", placementId: "xcore:offer-placement:124e8a16430888db")
2
3
OfferDecisioning.retrievePrefetchedOffers(decisionScopes: [homeDecisionScope]) { offersDict, _ in
4
5
// get the offers for homeDecisionScope
6
if let homeOffers = offersDict[homeDecisionScope] {
7
// deal with the offers
8
}
9
}
Copied!

Public classes

Android
iOS — Swift

DecisionScope

This class encapsulates the decision activityId, placementId and itemCount. The DecisionScope object can be used to fetch offers from the Offer Decisioning service when it is enabled in the Datastreams on the Data collection UI. The default value for itemCount is 1, if not provided when creating the DecisionScope object.
1
final public class DecisionScope {
2
3
public DecisionScope(final String activityId, final String placementId) {...}
4
5
public DecisionScope(final String activityId, final String placementId, final int itemCount) {...}
6
7
public String getActivityId() {...}
8
9
public String getPlacementId() {...}
10
11
public int getItemCount() {...}
Copied!

Proposition

This class represents the proposition received from the offer decisioning service upon personalization query.
1
public class Proposition {
2
3
Proposition(final String id, final List<Offer> offers, final String scopeString, final DecisionScope decisionScope) {...}
4
5
public String getId() {...}
6
7
List<Offer> getOffers() {...}
8
9
public String getScopeString() {...}
Copied!

Offer

This class represents the offer option received from the offer decisioning service upon personalization query.
1
public class Offer {
2
3
Offer(final String id, final String etag, final String schema, final OfferType type, final List<String> language, final String content, final Map<String, String> characteristics) {...}
4
5
public String getId() {...}
6
7
public String getEtag() {...}
8
9
public OfferType getType() {...}
10
11
public List<String> getLanguage() {...}
12
13
public String getContent() {...}
14
15
public Map<String, String> getCharacteristics() {...}
16
17
public Proposition getProposition() {...}
Copied!

OfferType

An enum indicating the type of an offer. This is based on the offer format field returned in the personalization query response.
1
public enum OfferType {
2
UNKNOWN, JSON, HTML, IMAGE, TEXT {
3
@Override
4
public String toString() {
5
return "text/plain";
6
}
7
};
8
9
static OfferType from(final String type) {...}
10
}
Copied!

OfferExperienceEvent

An instance of OfferExperienceEvent can be supplied in the prefetch API when additional information such as xdm data, free-form data or dataset identifier needs to be passed to the Offer Decisioning service. If provided, the datasetIdentitifer overrides the default dataset configured in the Datastreams on the Data Collection UI.
1
public class OfferExperienceEvent {
2
3
public OfferExperienceEvent(final Map<String, Object> xdmData) {...}
4
5
public OfferExperienceEvent(final Map<String, Object> xdmData, final Map<String, Object> data, final String datasetIdentifier) {...}
6
7
public Map<String, Object> getXdmData() {...}
8
9
public Map<String, Object> getData() {...}
10
11
public String getDatasetIdentifier() {...}
12
}
Copied!

DecisionScope/AEPDecisionScope

This class contains the id of activity and placement, which is used by the offer decisioning service to propose offers for. For advanced use case you can also assign the value of itemCount, if not, a default value of 1 will be used.
1
@objc(AEPDecisionScope)
2
public class DecisionScope{
3
@objc public let activityId: String
4
@objc public let placementId: String
5
@objc public let itemCount: Int
6
7
@objc public init(activityId: String, placementId: String, itemCount: Int = 1) {...}
8
}
Copied!

Proposition/AEPProposition

This class represents the proposition received from the offer decisioning service.
1
@objc(AEPProposition)
2
public class Proposition: NSObject, Codable {
3
@objc public let id: String
4
@objc public let scopeString: String
5
@objc public let decisionScope: DecisionScope
6
@objc public lazy var offers: [Offer] = {...}()
7
}
Copied!

Offer/AEPOffer

This class represents the offer option received from the offer decisioning service.
1
@objc(AEPOffer)
2
public class Offer: NSObject, Codable {
3
@objc public let id: String
4
@objc public let etag: String
5
@objc public let type: OfferType
6
@objc public let language: [String]?
7
@objc public let content: String?
8
@objc public let characteristics: [String: String]?
9
@objc public weak var proposition: Proposition?
10
}
Copied!

OfferType/AEPOfferType

An enum indicating the type of an offer, which is a field of the Offer class
1
public enum OfferType{
2
case unknown = 0
3
case json = 1
4
case text = 2
5
case html = 3
6
case image = 4
7
}
Copied!

OfferExperienceEvent/AEPOfferExperienceEvent

An instance of OfferExperienceEvent need to be passed to the prefetch API when additional context data need to be provided to the Offer Decisioning services.
1
public class OfferExperienceEvent: NSObject {
2
/// XDM formatted data, use an `XDMSchema` implementation for a better XDM data injestion and format control
3
@objc public let xdm: [String: Any]
4
5
/// Optional free-form data associated with this event
6
@objc public let data: [String: Any]?
7
8
/// Adobe Experience Platform dataset identifier, if not set the default dataset identifier set in the Datastream configuration is used
9
@objc public let datasetIdentifier: String?
10
11
/// Initialize an Experience Event with the provided event data
12
/// - Parameters:
13
/// - xdm: XDM formatted data for this event, passed as a raw XDM Schema data dictionary.
14
/// - data: Any free form data in a [String : Any] dictionary structure.
15
/// - datasetIdentifier: The Experience Platform dataset identifier where this event should be sent to; if not provided, the default dataset identifier set in the Datastream configuration is used
16
@objc public init(xdm: [String: Any], data: [String: Any]? = nil, datasetIdentifier: String? = nil) {...}
17
}
Copied!
Last modified 1mo ago