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
Android

Syntax

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

Example

Java

OfferDecisioning.onOfferUpdate(new AdobeCallbackWithError<Map<DecisionScope, List<Offer>>>() {
@Override
public void fail(AdobeError adobeError) {
}
@Override
public void call(Map<DecisionScope, List<Offer>> decisionScopeListMap) {
// handle offers
}
});
iOS — Swift

Syntax

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

Example

Here are some examples in Objective C and Swift:

Objective C

[AEPMobileOfferDecisioning onOfferUpdateWithPerform:^(NSDictionary<AEPDecisionScope*, NSArray<AEPOffer*>*>* offersDict) {
//handle offers response
}];

Swift

OfferDecisioning.onOfferUpdate { offersDict in
//handle offers response
}

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
Android

Syntax

public static void prefetchOffers(final List<DecisionScope> decisionScopes)
public static void prefetchOffers(final List<DecisionScope> decisionScopes, final OfferExperienceEvent offerExperienceEvent)

Example

Java

// prefetch offers for decision scopes
OfferDecisioning.prefetchOffers(Arrays.asList(
new DecisionScope("xcore:offer-activity:124e8bc413c888dd", "xcore:offer-placement:124e8a16430888db")));
// prefetch offers for decision scopes with additional expxperience event
OfferExperienceEvent exEvent = new OfferExperienceEvent(
new HashMap<String, Object>() {
{
put("xdmkey", "xdmvalue");
}
},null,"override-datasetId");
OfferDecisioning.prefetchOffers(Arrays.asList(
new DecisionScope("xcore:offer-activity:124e8bc413c888dd", "xcore:offer-placement:124e8a16430888db"),
exEvent);
iOS — Swift

Syntax

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

Examples

Here are some examples in Objective C and Swift:

Objective C

AEPDecisionScope* decisionScope = [[AEPDecisionScope alloc] initWithActivityId:@"xcore:offer-activity:124e8bc413c888dd" placementId:@"xcore:offer-placement:124e8a16430888db"];
// prefetch offers for decision scopes
[AEPMobileOfferDecisioning prefetchOffersWithDecisionScopes:@[decisionScope]];
// prefetch offers for decision scopes with additional expxperience event
AEPOfferExperienceEvent* expxperienceEvent = [[AEPOfferExperienceEvent alloc] initWithXdm:@{@"key":@"value"} data:nil datasetIdentifier:nil];
[AEPMobileOfferDecisioning prefetchOffersWithDecisionScopes:@[decisionScope] experienceEvent:expxperienceEvent];

Swift

let decisionScope = DecisionScope(activityId: "xcore:offer-activity:124e8bc413c888dd", placementId: "xcore:offer-placement:124e8a16430888db")
// prefetch with only decision scopes
OfferDecisioning.prefetchOffers(decisionScopes: [decisionScope ])
// prefetch with additional data
let experienceEvent = OfferExperienceEvent(xdm: ["xdmkey": "xdmvalue"], data: nil, datasetIdentifier: "override-datasetId")
OfferDecisioning.prefetchOffers(decisionScopes: [decisionScope ], experienceEvent: experienceEvent)

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
Android

Syntax

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

Example

Java

OfferDecisioning.retrievePrefetchedOffers(Arrays.asList(
new DecisionScope("xcore:offer-activity:11cfb1fa93381aca", "xcore:offer-placement:1175009612b0100c")),
new AdobeCallbackWithError<Map<DecisionScope, List<Offer>>>() {
@Override
public void fail(AdobeError adobeError) {
}
@Override
public void call(Map<DecisionScope, List<Offer>> decisionScopeListMap) {
StringBuffer sb = new StringBuffer();
// render the offer with offer.content
}
});
iOS — Swift

Syntax

func retrievePrefetchedOffers(decisionScopes: [DecisionScope], completionHandler: @escaping ([DecisionScope: [Offer]], Error?) -> Void)
  • 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

AEPDecisionScope* homeDecisionScope = [[AEPDecisionScope alloc] initWithActivityId:@"xcore:offer-activity:124e8bc413c888dd" placementId:@"xcore:offer-placement:124e8a16430888db"];
[AEPMobileOfferDecisioning retrievePrefetchedOffersWithDecisionScopes:@[homeDecisionScope] completionHandler:^(NSDictionary<AEPDecisionScope *,NSArray<AEPOffer*>*>* offers, NSError * error) {
// get the offers for homeDecisionScope
NSArray<AEPOffer*>* homeOffers = offers[homeDecisionScope]
// deal with the offers
}];

Swift

let homeDecisionScope = DecisionScope(activityId: "xcore:offer-activity:124e8bc413c888dd", placementId: "xcore:offer-placement:124e8a16430888db")
OfferDecisioning.retrievePrefetchedOffers(decisionScopes: [homeDecisionScope]) { offersDict, _ in
// get the offers for homeDecisionScope
if let homeOffers = offersDict[homeDecisionScope] {
// deal with the offers
}
}

Public classes

iOS — Swift
iOS — Swift

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.

public class DecisionScope{
public let activityId: String
public let placementId: String
public let itemCount: Int
public init(activityId: String, placementId: String, itemCount: Int = 1) {
self.activityId = activityId
self.placementId = placementId
self.itemCount = itemCount
}
}

Proposition/AEPProposition

This class represents the proposition received from the offer decisioning service.

public class Proposition: NSObject, Codable {
public let id: String
public let scopeString: String
public let decisionScope: DecisionScope
public lazy var offers: [Offer] = {...}()
}

Offer/AEPOffer

This class represents the offer option received from the offer decisioning service.

public class Offer: NSObject, Codable {
public let id: String
public let type: OfferType
public let language: [String]?
public let content: String?
public let characteristics: [String: String]?
public let schema: String
public weak var proposition: Proposition?
}

OfferType/AEPOfferType

An enum indicating the type of an offer, which is a field of the Offer class

public enum OfferType{
case unknown = 0
case json = 1
case text = 2
case html = 3
case image = 4
}

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.

public class OfferExperienceEvent: NSObject {
/// XDM formatted data, use an `XDMSchema` implementation for a better XDM data injestion and format control
@objc public let xdm: [String: Any]
/// Optional free-form data associated with this event
@objc public let data: [String: Any]?
/// Adobe Experience Platform dataset identifier, if not set the default dataset identifier set in the Edge Configuration is used
@objc public let datasetIdentifier: String?
/// Initialize an Experience Event with the provided event data
/// - Parameters:
/// - xdm: XDM formatted data for this event, passed as a raw XDM Schema data dictionary.
/// - data: Any free form data in a [String : Any] dictionary structure.
/// - datasetIdentifier: The Experience Platform dataset identifier where this event should be sent to; if not provided, the default dataset identifier set in the Edge configuration is used
@objc public init(xdm: [String: Any], data: [String: Any]? = nil, datasetIdentifier: String? = nil) {
self.xdm = xdm
self.data = data
self.datasetIdentifier = datasetIdentifier
}
}