This document details all the APIs provided by Target, along with sample code snippets on how to properly use the APIs.
This API sends a prefetch request to your configured Target server with the prefetch objects array and the specified target parameters.
static func prefetchContent(_ prefetchArray: [TargetPrefetch], with targetParameters: TargetParameters? = nil, _ completion: ((Error?) -> Void)?)
- prefetchArray - is an array of
TargetPrefetch
objects for various mbox locations. - targetParameters - is the configured
TargetParameters
for the prefetch request. - If the prefetch is successful,
completion
is invoked with a nil value. If the prefetch is not successful, an error message is returned.
let TargetParameters1 = TargetParameters(
parameters: ["status": "platinum"],
profileParameters: ["age": "20"],
order: TargetOrder(id: "ADCKKIM", total: 344.30, purchasedProductIds: ["34", "125"]),
product: TargetProduct(productId: "24D3412", categoryId:"Books")
)
let TargetParameters2 = TargetParameters(
parameters: ["userType": "Paid"],
profileParameters: nil,
order: TargetOrder(id: "ADCKKIM", total: 344.30, purchasedProductIds: ["id1", "id2"]),
product: TargetProduct(productId: "764334", categoryId:"Online")
)
let globalTargetParameters = TargetParameters(
parameters: ["status": "progressive"],
profileParameters: ["age": "20-32"],
order: TargetOrder(id: "ADCKKBC", total: 400.50, purchasedProductIds: ["34", "125"]),
product: TargetProduct(productId: "24D334", categoryId:"Stationary")
)
Target.prefetchContent(
[
TargetPrefetch(name: "mboxName1", targetParameters: TargetParameters1),
TargetPrefetch(name: "mboxName2", targetParameters: TargetParameters2),
],
with: globalTargetParameters
){ error in
// do something with the callback response
}
+ (void) prefetchContent: (nonnull NSArray<AEPTargetPrefetchObject*>*) targetPrefetchObjectArray
withParameters: (nullable AEPTargetParameters*) targetParameters
callback: (nullable void (^) (NSError* _Nullable error)) completion;
- prefetchObjectArray : is an array of
TargetPrefetch
objects for various mbox locations. - targetParameters : is the configured
TargetParameters
for the prefetch request. - If the prefetch is successful,
completion
is invoked with a nil value. If the prefetch is not successful, an error message is returned.
NSDictionary *mboxParameters1 = @{@"status":@"platinum"};
NSDictionary *profileParameters1 = @{@"age":@"20"};
AEPTargetProduct *product1 = [[AEPTargetProduct alloc] initWithProductId:@"24D3412" categoryId:@"Books"];
AEPTargetOrder *order1 = [[AEPTargetOrder alloc] initWithId:@"ADCKKIM" total:[@(344.30) doubleValue] purchasedProductIds:@[@"34", @"125"]];
AEPTargetParameters *targetParameters1 = [[AEPTargetParameters alloc] initWithParameters:mboxParameters1 profileParameters:profileParameters1 order:order1 product:product1 ];
NSDictionary *mboxParameters2 = @{@"userType":@"Paid"};
AEPTargetProduct *product2 = [[AEPTargetProduct alloc] initWithProductId:@"764334" categoryId:@"Online"];
AEPTargetOrder *order2 = [[AEPTargetOrder alloc] initWithId:@"ADCKKIM" total:[@(344.30) doubleValue] purchasedProductIds:@[@"id1",@"id2"]];
AEPTargetParameters *targetParameters2 = [[AEPTargetParameters alloc] initWithParameters:mboxParameters2 profileParameters:nil order:order2 product:product2 ];
// Creating Prefetch Objects
AEPTargetPrefetchObject *prefetch1 = [[AEPTargetPrefetchObject alloc] initWithName: @"logo" targetParameters:targetParameters1];
AEPTargetPrefetchObject *prefetch2 = [[AEPTargetPrefetchObject alloc] initWithName: @"buttonColor" targetParameters:targetParameters2];
// Creating prefetch Array
NSArray *prefetchArray = @[prefetch1,prefetch2];
// Creating Target parameters
NSDictionary *mboxParameters = @{@"status":@"progressive"};
NSDictionary *profileParameters = @{@"age":@"20-32"};
AEPTargetProduct *product = [[AEPTargetProduct alloc] initWithProductId:@"24D334" categoryId:@"Stationary"];
AEPTargetOrder *order = [[AEPTargetOrder alloc] initWithId:@"ADCKKBC" total:[@(400.50) doubleValue] purchasedProductIds:@[@"34", @"125"]];
AEPTargetParameters *targetParameters = [[AEPTargetParameters alloc] initWithParameters:mboxParameters
profileParameters:profileParameters
order:order
product:product];
// Target API Call
[AEPMobileTarget prefetchContent:prefetchArray withParameters:targetParameters callback:^(NSError * _Nullable error){
// do something with the callback response
}];
This API sends a batch request to the configured Target server for multiple mbox locations.
For mbox locations in the Target requests list that are not already prefetched, this API sends a batch request to the configured Target server. The content for the mbox locations that have been prefetched in a previous request are returned from the SDK, and no additional network request is made. Each Target request object in the list contains a callback function, which is invoked when content is available for its given mbox location.
When using contentWithData
callback to instantiate TargetRequest object, the following keys can be used to read response tokens and Analytics for Target (A4T) info from the data payload if available in the Target response.
- responseTokens (Response tokens)
- analytics.payload (A4T payload)
- clickmetric.analytics.payload (Click tracking A4T payload)
static func retrieveLocationContent(_ requestArray: [TargetRequest], with targetParameters: TargetParameters? = nil)
- requestArray : an array of
TargetRequest
objects to retrieve content - targetParameters : a
TargetParameters
object containing parameters for all locations in the requests array
let TargetParameters1 = TargetParameters(
parameters: ["status": "platinum"],
profileParameters: ["age": "20"],
order: TargetOrder(id: "ADCKKIM", total: 344.30, purchasedProductIds: ["34", "125"]),
product: TargetProduct(productId: "24D3412", categoryId: "Books")
)
let TargetParameters2 = TargetParameters(
parameters: ["userType": "Paid"],
profileParameters: nil,
order: TargetOrder(id: "ADCKKIM", total: 344.30, purchasedProductIds: ["id1", "id2"]),
product: TargetProduct(productId: "764334", categoryId: "Online")
)
let globalTargetParameters = TargetParameters(
parameters: ["status": "progressive"],
profileParameters: ["age": "20-32"],
order: TargetOrder(id: "ADCKKBC", total: 400.50, purchasedProductIds: ["34", "125"]),
product: TargetProduct(productId: "24D334", categoryId: "Stationary")
)
let request1 = TargetRequest(mboxName: "logo", defaultContent: "BlueWhale", targetParameters: TargetParameters1) { content in
if let content = content {
// do something with the target content.
}
}
let request2 = TargetRequest(mboxName: "logo", defaultContent: "red", targetParameters: TargetParameters2) { content, data in
if let content = content {
// do something with the target content.
}
// Read the data dictionary containing one or more of response tokens, analytics payload and click-tracking analytics payload, if available.
if let data = data {
let responseTokens = data["responseTokens"] as? [String: Any] ?? [:]
let analyticsPayload = data["analytics.payload"] as? [String: String] ?? [:]
let clickMetricAnalyticsPayload = data["clickmetric.analytics.payload"] as? [String: String] ?? [:]
...
}
}
Target.retrieveLocationContent([request1, request2], with: globalTargetParameters)
+ (void) retrieveLocationContent: (nonnull NSArray<AEPTargetRequestObject*>*) requests
withParameters: (nullable AEPTargetParameters*) parameters;
- requests : an array of
AEPTargetRequestObject
objects to retrieve content - parameters : a
AEPTargetParameters
object containing parameters for all locations in the requests array
NSDictionary *mboxParameters1 = @{@"status":@"platinum"};
NSDictionary *profileParameters1 = @{@"age":@"20"};
AEPTargetProduct *product1 = [[AEPTargetProduct alloc] initWithProductId:@"24D3412" categoryId:@"Books"];
AEPTargetOrder *order1 = [[AEPTargetOrder alloc] initWithId:@"ADCKKIM" total:[@(344.30) doubleValue] purchasedProductIds:@[@"34", @"125"]];
AEPTargetParameters *targetParameters1 = [[AEPTargetParameters alloc] initWithParameters:mboxParameters1 profileParameters:profileParameters1 order:order1 product:product1 ];
NSDictionary *mboxParameters2 = @{@"userType":@"Paid"};
AEPTargetProduct *product2 = [[AEPTargetProduct alloc] initWithProductId:@"764334" categoryId:@"Online"];
AEPTargetOrder *order2 = [[AEPTargetOrder alloc] initWithId:@"ADCKKIM" total:[@(344.30) doubleValue] purchasedProductIds:@[@"id1",@"id2"]];
AEPTargetParameters *targetParameters2 = [[AEPTargetParameters alloc] initWithParameters:mboxParameters2 profileParameters:nil order:order2 product:product2 ];
AEPTargetRequestObject *request1 = [[AEPTargetRequestObject alloc] initWithMboxName: @"logo" defaultContent: @"BlueWhale" targetParameters: targetParameters1 contentCallback:^(NSString * _Nullable content) {
// do something with the target content.
NSString *targetContent = content ?: @"";
}];
AEPTargetRequestObject *request2 = [[AEPTargetRequestObject alloc] initWithMboxName: @"logo" defaultContent: @"red" targetParameters: targetParameters2 contentWithDataCallback:^(NSString * _Nullable content, NSDictionary<NSString *,id> * _Nullable data) {
// do something with the target content.
NSString *targetContent = content ?: @"";
// Read the data dictionary containing one or more of response tokens, analytics payload and click-tracking analytics payload, if available.
if ([data count] > 0) {
if ([data objectForKey:@"responseTokens"]) {
// read response tokens
}
if ([data objectForKey:@"analytics.payload"]) {
// read analytics payload
}
if ([data objectForKey:@"clickmetric.analytics.payload"]) {
// read click-tracking analytics payload
}
}
}];
// Create request object array
NSArray *requestArray = @[request1,request2];
// Creating Target parameters
NSDictionary *mboxParameters = @{@"status":@"progressive"};
NSDictionary *profileParameters = @{@"age":@"20-32"};
AEPTargetProduct *product = [[AEPTargetProduct alloc] initWithProductId:@"24D334" categoryId:@"Stationary"];
AEPTargetOrder *order = [[AEPTargetOrder alloc] initWithId:@"ADCKKBC" total:[@(400.50) doubleValue] purchasedProductIds:@[@"34", @"125"]];
AEPTargetParameters *targetParameters = [[AEPTargetParameters alloc] initWithParameters:mboxParameters
profileParameters:profileParameters
order:order
product:product];
[AEPMobileTarget retrieveLocationContent: requestArray withParameters: targetParameters];
This API sets the custom visitor ID for Target.
This ID is preserved between app upgrades, is saved and restored during the standard application backup process, and is removed at uninstall, upon privacy status update to opted out, or when the resetExperience API is used.
static func setThirdPartyId(_ id: String?)
- id : a
String
that contains the custom visitor ID to be set in Target.
Target.setThirdPartyId("third-party-id")
+ (void) setThirdPartyId: (nullable NSString*) thirdPartyId;
- thirdPartyId : a NSString that contains the custom visitor ID to be set in Target.
[AEPMobileTarget setThirdPartyId:@"third-party-id"];
This API gets the custom visitor ID for Target. If no third-party
ID was previously set, or if the ID was reset by calling resetExperience API, it will have a null
value.
static func getThirdPartyId(_ completion: @escaping (String?, Error?) -> Void)
- completion : invoked with the
thirdPartyId
value. If nothird-party
ID was set, this value will benil
.
Target.getThirdPartyId({id, err in
// read Target thirdPartyId
})
+ (void) getThirdPartyId: (nonnull void (^) (NSString* __nullable thirdPartyId, NSError * _nullable error)) completion;
- completion : invoked with the
thirdPartyId
value. If nothird-party
ID was set, this value will benil
.
[AEPMobileTarget getThirdPartyId:^(NSString *thirdPartyID, NSError *error){
// read Target thirdPartyId
}];
This API sets the Target user identifier.
The provided tnt ID is persisted in the SDK and attached to subsequent Target requests. It is used to derive the edge host value in the SDK, which is also persisted and used in future Target requests.
If the provided tnt ID is nil or empty, or if the privacy status is opted out, the SDK will remove the tnt ID and edge host values from the persistence.
This ID is preserved between app upgrades, is saved and restored during the standard application backup process, and is removed at uninstall, upon privacy status update to opted out, or when the resetExperience API is used.
static func setTntId(_ id: String?)
- id : a
String
that contains the Target user identifier to be set in the SDK.
Target.setTntId("f741a5d5-09c0-4931-bf53-b9e568c5f782.35_0")
+ (void) setTntId: (NSString* _Nullable) id;
- id : a NSString that contains the Target user identifier to be set in the SDK.
[AEPMobileTarget setTntId:@"f741a5d5-09c0-4931-bf53-b9e568c5f782.35_0"];
This API gets the Target user identifier.
The tnt ID is returned in the network response from Target after a successful call to prefetchContent
API or retrieveLocationContent
API, which is then persisted in the SDK. The persisted tnt ID is used in subsequent Target requests until a different tnt ID is returned from Target, or a new tnt ID is set using setTntId
API.
static func getTntId(_ completion: @escaping (String?, Error?) -> Void)
- completion : invoked with the
tntId
value, ornil
if there was an error retrieving it.
Target.getTntId { id, err in
// read Target's tntId
}
+ (void) getTntId: (void (^ _Nonnull) (NSString* _Nullable tntId, NSError* _Nullable error)) completion;
- completion : invoked with the
tntId
value, ornil
if there was an error retrieving it.
[AEPMobileTarget getTntId:^(NSString *tntId, NSError *error){
// read Target's tntId
}];
This API sets the Target session identifier.
The provided session ID is persisted in the SDK for a period defined by target.sessionTimeout
configuration setting. If the provided session ID is nil or empty, or if the privacy status is opted out, the SDK will remove the session ID value from the persistence.
This ID is preserved between app upgrades, is saved and restored during the standard application backup process, and is removed at uninstall, upon privacy status update to opted out, or when the resetExperience API is used.
static func setSessionId(_ id: String?)
- id : a
String
that contains the Target session identifier to be set in the SDK.
Target.setSessionId("5568c1a2-ece1-42d1-b807-930623998ec3")
+ (void) setSessionId: (NSString* _Nullable) id;
- id : a NSString that contains the Target session identifier to be set in the SDK.
[AEPMobileTarget setSessionId:@"5568c1a2-ece1-42d1-b807-930623998ec3"];
This API gets the Target session identifier.
The session ID is generated locally in the SDK upon initial Target request and persisted for a period defined by target.sessionTimeout
configuration setting. If the session timeout happens upon a subsequent Target request, a new session ID will be generated for use in the request and persisted in the SDK.
static func getSessionId(_ completion: @escaping (String?, Error?) -> Void)
- completion : invoked with the Target
sessionId
value, ornil
if there was an error retrieving it.
Target.getSessionId { id, err in
// read Target sessionId
}
+ (void) getSessionId: (void (^ _Nonnull) (NSString* _Nullable sessionId, NSError* _Nullable error)) completion;
- completion : invoked with the Target
sessionId
value, ornil
if there was an error retrieving it.
[AEPMobileTarget getSessionId:^(NSString *sessionId, NSError *error){
// read Target sessionId
}];
This API resets the user's experience by removing the visitor identifiers and resetting the Target session. Invoking this API also removes previously set Target user ID and custom visitor IDs, Target Edge Host, and the session information from persistent storage.
static func resetExperience()
Target.resetExperience()
+ (void) resetExperience;
[AEPMobileTarget resetExperience];
This API clears the in-memory cache that contains the prefetched offers.
static func clearPrefetchCache()
Target.clearPrefetchCache()
+ (void) clearPrefetchCache;
[AEPMobileTarget clearPrefetchCache];
This API sets the Target preview URL to be displayed when the preview mode is enabled and preview selections are confirmed.
static func setPreviewRestartDeepLink(_ deeplink: URL)
- deeplink : an
URL
that contains the preview restart deeplink.
if let url = URL(string: "myapp://HomePage") {
Target.setPreviewRestartDeepLink(url)
}
+ (void) setPreviewRestartDeeplink: (nonnull NSURL*) deeplink;
- deeplink : an
NSURL
that contains the preview restart deeplink.
[AEPMobileTarget setPreviewRestartDeepLink:@"myapp://HomePage"];
Use this API to send a location (mbox) display notification to the configured Target server. This API should be invoked for a prefetched mbox after the mbox content is retrieved using the retrieveLocationContent
API. If no previous prefetch request is made, and the mbox content is retrieved using the retrieveLocationContent
API, calling this API does not trigger a notification request to the Target server.
static func displayedLocations(_ names: [String], targetParameters: TargetParameters?)
- names : is an array of the mbox locations for which the display notification will be sent to Target.
- targetParameters : is the configured
TargetParameters
for the request.
Target.displayedLocations(
names: ["mboxName1", "mboxName2"],
targetParameters: TargetParameters(
parameters: nil,
profileParameters: nil,
order: TargetOrder(id: "ADCKKBC", total: 400.50, purchasedProductIds: ["34", "125"]),
product: TargetProduct(productId: "24D334", categoryId: "Stationary")
)
)
+ (void) displayedLocations: (nonnull NSArray<NSString*>*) names
withTargetParameters: (nullable AEPTargetParameters*) targetParameters;
- names : is an NSArray of the mbox locations for which the display notification will be sent to Target.
- targetParameters : is the configured
AEPTargetParameters
for the request.
AEPTargetOrder *order = [[AEPTargetOrder alloc] initWithId:@"ADCKKBC" total:400.50 purchasedProductIds:@[@"34", @"125"]];
AEPTargetProduct *product =[[AEPTargetProduct alloc] initWithProductId:@"24D334" categoryId:@"Stationary"];
AEPTargetParameters * targetParams = [[AEPTargetParameters alloc] initWithParameters:nil profileParameters:nil order:order product:product];
[AEPMobileTarget displayedLocations:@[@"mboxName1", @"mboxName2"] withTargetParameters:targetParams];
This API sends a location (mbox) click notification to the configured Target server and can be invoked in the following cases:
-
For a prefetched mbox, after the mbox content is retrieved using the
retrieveLocationContent
API. -
For a regular mbox, where no previous prefetch request is made, and the mbox content is retrieved using the
retrieveLocationContent
API.
static func clickedLocation(_ name: String, targetParameters: TargetParameters?)
- name : a
String
that contains the mbox location for which the click notification will be sent to Target. - targetParameters : the configured
TargetParameters
for the request.
Target.clickedLocation(
name: "cartLocation",
targetParameters: TargetParameters(
parameters: nil,
profileParameters: nil,
order: TargetOrder(id: "ADCKKBC", total: 400.50, purchasedProductIds: ["34", "125"]),
product: TargetProduct(productId: "24D334", categoryId: "Stationary")
)
)
+ (void) clickedLocation: (nonnull NSArray<NSString*>*) names
withTargetParameters: (nullable AEPTargetParameters*) targetParameters;
- name : an
NSString
that contains the mbox location for which the click notification will be sent to Target. - targetParameters : the configured
AEPTargetParameters
for the request.
EPTargetOrder *order = [[AEPTargetOrder alloc] initWithId:@"ADCKKBC" total:400.50 purchasedProductIds:@[@"34", @"125"]];
AEPTargetProduct *product =[[AEPTargetProduct alloc] initWithProductId:@"24D334" categoryId:@"Stationary"];
AEPTargetParameters * targetParams = [[AEPTargetParameters alloc] initWithParameters:nil profileParameters:nil order:order product:product];
[AEPMobileTarget displayedLocations:@[@"mboxName1", @"mboxName2"] withTargetParameters:targetParams];
This document details all the raw APIs provided by Target, along with sample code snippets on how to properly use the APIs.
This API can be used to retrieve prefetch or execute response for mbox locations from the configured Target server.
static func executeRawRequest(_ request: [[String: Any]], _ completion: @escaping ([[String: Any]]?, Error?) -> Void)
- request - is a dictionary containing prefetch or execute request data in the Target v1 delivery API request format.
- completion - is the callback which will be invoked with the Target response data or error message after the request is completed.
let request: [String: Any] = [
"execute": [
"mboxes": [
[
"index": 0,
"name": "mbox1",
"parameters": [
"mbox_parameter_key1": "mbox_parameter_value1"
],
"profileParameters": [
"subscription": "premium"
],
"order": [
"id": "id1",
"total": 100.34,
"purchasedProductIds":[
"pId1"
]
],
"product": [
"id": "pId1",
"categoryId": "cId1"
]
],
[
"index": 1,
"name": "mbox2",
"parameters": [
"mbox_parameter_key2": "mbox_parameter_value2"
]
]
]
]
]
Target.executeRawRequest(request) { responseData, error in
if error != nil {
return
}
guard let responseData = responseData,
!responseData.isEmpty else {
return
}
// handle the response
}
+ (void)executeRawRequest:(nonnull NSDictionary<NSString *, id> *)request completion:(void (nonnull ^)(nullable NSDictionary<NSString *, id> *, nullable NSError *))completion;
- request : is a dictionary containing prefetch or execute request data in the Target v1 delivery API request format.
- completion : is the the callback which will be invoked with the Target response data or error message after the request is completed.
NSDictionary *request = @{
@"execute": @{
@"mboxes": @[
@{
@"index": @(0),
@"name": @"mbox1",
@"parameters": @{
@"mbox_parameter_key1": @"mbox_parameter_value1"
},
@"profileParameters": @{
@"subscription": @"premium"
},
@"order": @{
@"id": @"id1",
@"total": @(100.34),
@"purchasedProductIds": @[
@"pId1"
]
},
@"product": @{
@"id": @"pId1",
@"categoryId": @"cId1"
}
},
@{
@"index": @(1),
@"name": @"mbox2",
@"parameters": @{
@"mbox_parameter_key2": @"mbox_parameter_value2"
}
}
]
}
};
[AEPMobileTarget executeRawRequest:request completion:^(NSDictionary<NSString *,id> * _Nullable data, NSError * _Nullable err) {
if (err != nil) {
NSLog(@"Error: %@", err);
return;
}
NSLog(@"Target raw response >> %@", data);
// handle response
}];
This API sends notification request(s) to the configured Target server for display or click notifications.
The event tokens required for the Target display or click notifications can be retrieved from the response of a prior executeRawRequest
API call for prefetch or execute.
static func sendRawNotifications(_ request: [String: Any])
- request - is a dictionary containing notifications data in the Target v1 delivery API request format.
var notifications: [[String: Any]] = []
let notification: [String: Any] = [
"id": "0",
"timestamp": Int64(Date().timeIntervalSince1970 * 1000.0),
"type": "click",
"mbox": [
"name": "mbox1"
],
"tokens": [
"someClickToken"
],
"parameters": [
"mbox_parameter_key3": "mbox_parameter_value3"
]
]
notifications.append(notification)
Target.sendRawNotifications([
"notifications": notifications
])
+ (void)sendRawNotifications:(nonnull NSDictionary<NSString *, id> *)request;
- request : is a dictionary containing notifications data in the Target v1 delivery API request format.
NSMutableArray *notifications = [[NSMutableArray alloc] init];
NSDictionary* notification = @{
@"id": @"0",
@"timestamp": @((long)([[NSDate date] timeIntervalSince1970] * 1000.0)),
@"type": @"click",
@"mbox": @{
@"name": @"mbox1",
},
@"tokens": @[ @"someClickToken" ],
@"parameters": @{
@"mbox_parameter_key3": @"mbox_parameter_value3"
}
};
[notifications addObject:notification];
NSDictionary *request = @{
@"notifications": notifications
};
[AEPMobileTarget sendRawNotifications:request];
The visual preview mode allows you to easily perform end-to-end QA of activities by enrolling and previewing these activities on your device. This mode does not require a specialized testing set up. To get started, set up a URL scheme and generate the preview links. For more information on setting up URL schemes, see Defining a Custom URL Scheme for Your App for iOS and see Create Deep Links to App Content for Android. You can also set an application deep link in the SDK that can be triggered when selections are made in the preview mode by using the setPreviewRestartDeeplink
API.
To enter the preview visual mode, use the Mobile Core's collectLaunchInfo
API to enable the mode and click the red floating button that appears on the app screen.
MobileCore.collectLaunchInfo(["adb_deeplink" : "com.adobe.targetpreview://app.adobetarget.com?at_preview_token=tokenFromTarget"])
[AEPMobileCore collectLaunchInfo: @{@"adb_deeplink":@"com.adobe.targetpreview://app.adobetarget.com?at_preview_token=tokenFromTarget"}];