iOS - create a Target location and success metric
To use Target in your mobile app, create a location and success metric.
This section includes sample code that can be used as a template for your app. The samples in this section contain code for iOS. The same patterns apply to Android. Android-specific syntax can be found in the Android SDK 4.x for Experience Cloud Solutions guide.
See the Mobile documentation for a list of all the available Target methods.
To create a Target location in your app and make a request, there are two primary methods:
targetCreateRequestWithName
targetLoadRequest
Create a Target location.
Here is a sample call to create a request:
Copied to your clipboard1// make your request2ADBTargetLocationRequest *myRequest = [ADBMobile targetCreateRequestWithName:@"heroBanner"3 defaultContent:@"default.png"4 parameters:nil];Parameter Description ADBTargetLocationRequest *myRequest
Replace myRequest
with the name of yourtargetLocation
in the app.targetCreateRequestWithName:@"heroBanner"
Replace heroBanner
with the name of yourtargetLocation
in Target. This is the same as the mbox name. This hero banner appears in the Target interface.defaultContent:@"default.png"
Replace default.png
with the value the app uses if Target doesn't respond.parameters:nil
Specify profile or mbox parameters. See more information in the 'Passing custom data' section. Here is a sample call to load the request:
Copied to your clipboard1// load your request2[ADBMobile targetLoadRequest:myRequest callback:^(NSString *content) {3 // do something with content4 heroImage.image = [UIImage imageNamed:content];5}];Parameter Description targetLoadRequest:myRequest
Replace myRequest
with the name of yourtargetLocation
in the app.NSString *content
Replace content with the actual content coming back from Adobe. The string can be XML, JSON or a plain string. Use this section of the code to define variables, set image paths, view controller flows, transaction points, or anything else you want to do. Target will return the content entered in the UI in the exact same format. heroImage.image = [UIImage imageNamed:content];
For example: Take content and set the path for a hero image. Create a success metric.
The method
targetCreateOrderConfirmRequestWithName
can be used to track a conversion/success metric in your app.Copied to your clipboard1ADBTargetLocationRequest *req = [ADBMobile targetCreateOrderConfirmRequestWithName: "orderConfirm"2 orderId: orderId3 orderTotal: @"39.95"4 productPurchasedId: _galleryItem.title5 parameters: nil];6[ADBMobile targetLoadRequest: req callback: nil];Parameter Description orderId
Replace with a dynamic variable representing a unique order ID. @"39.95"
Replace with a dynamic variable representing a unique order total. _galleryItem.title
Replace with a dynamic variable representing a comma-delimited list of products purchased. parameters: nil
Optional dictionary of additional parameters. Build the app.
Step Result After you have successfully created a target location and tagged a success metric, create an A/B test. The activity can be created using the form-based experience composer.