Adobe Campaign Standard API reference

Get the extension version

To return the current version of the Campaign extension, use the following APIs:

Android
iOS
React Native

extensionVersion

Java

Syntax

public String extensionVersion()

Example

Campaign.extensionVersion();

extensionVersion

Syntax

+ (nonnull NSString*) extensionVersion;

Objective-C

Example

NSLog(@"ACPCampaign version: %@", [ACPCampaign extensionVersion]);

Swift

Example

print("ACPCampaign version: ", ACPCampaign.extensionVersion())

extensionVersion

JavaScript

ACPCampaign.extensionVersion().then(version => console.log("AdobeExperienceSDK: ACPCampaign version: " + version));

Set linkage fields

This API sets the Campaign linkage fields (CRM IDs) in the Mobile SDK that are used to download personalized messages from Campaign. The set linkage fields are stored as a base64-encoded JSON string in memory, and they are sent in a custom HTTP header X-InApp-Auth in all future Campaign rules download requests until resetLinkageFields is invoked. These in-memory variables are lost when an application crash event occurs, after a graceful termination of the application, or when the privacy status is updated to OPT_OUT. For more information, see Preparing and sending an In-App message.

Android
iOS
React Native

setLinkageFields

Java

Syntax

public static void setLinkageFields(final Map<String, String> linkageFields)

Example

HashMap<String, String> linkageFields = new HashMap<String, String>();
linkageFields.put("cusFirstName", "John");
linkageFields.put("cusLastName", "Doe");
linkageFields.put("cusEmail", "john.doe@email.com");
Campaign.setLinkageFields(linkageFields);

setLinkageFields

Syntax

+ (void) setLinkageFields: (nonnull NSDictionary<NSString*, NSString*>*) linkageFields;

Example

Objective-C

[ACPCampaign setLinkageFields:@{@"cusFirstName" : @"John", @"cusLastName": @"Doe", @"cusEmail": @"john.doe@email.com"}];

Swift

var linkageFields = [String: String]()
linkageFields["cusFirstName"] = "John"
linkageFields["cusLastName"] = "Doe"
linkageFields["cusEmail"] = "john.doe@email.com"
ACPCampaign.setLinkageFields(linkageFields)

JavaScript

setLinkageFields

ACPCampaign.setLinkageFields({"linkageKey": "linkageValue"});

Reset linkage fields

This method clears the cached rules from the previous download before triggering a rule download request to the configured Campaign server. If the current SDK privacy status is not OPT_IN, no rules download occurs.

Android
iOS
React Native

resetLinkageFields

Syntax

public static void resetLinkageFields()

Example

Campaign.resetLinkageFields()

resetLinkageFields

Syntax

+ (void) resetLinkageFields;

Objective-C

Example

[ACPCampaign resetLinkageFields];

Swift

ACPCampaign.resetLinkageFields()

JavaScript

resetLinkageFields

ACPCampaign.resetLinkageFields();

Set up push messaging

To enable push messaging with Adobe Campaign, the push identifier that is received from the Apple Push Notification Service (APNS) or Firebase Cloud Messaging (FCM) must be sent to the Adobe Identity service by calling setPushIdentifer. After the API is invoked, a network request is made to Campaign that contains the message interaction event. For more information about Campaign message interaction events, see Implementing local notification tracking.

For more information about setting up your iOS app to connect to APNS and retrieve a device token that will be used as a push identifier, see Registering Your App with APNs. For more information about setting up your Android app to connect to FCM and retrieve a device registration token that will be used as a push identifier, see Set up a Firebase Cloud Messaging client app on Android.

Android
iOS
React Native

setPushIdentifier

Syntax

public static void setPushIdentifier(final String registrationID)

Example

FirebaseInstanceId.getInstance().getInstanceId()
.addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
@Override
public void onComplete(@NonNull Task<InstanceIdResult> task) {
if (!task.isSuccessful()) {
return;
}
// Get new Instance ID token
String registrationID = task.getResult().getToken();
// Log and toast
System.out.println("Received new registration token: " + registrationID);
// invoke the API to send the push identifier to the Identity Service
MobileCore.setPushIdentifier(registrationID);
}
});

setPushIdentifier

Syntax

+ (void) setPushIdentifier: (nullable NSData*) deviceToken;

Objective-C

Example

- (void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Set the deviceToken that the APNS has assigned to the device
[ACPCore setPushIdentifier:deviceToken];
//...
}

Swift

Example

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
// Set the deviceToken that the APNS has assigned to the device
ACPCore.setPushIdentifier(deviceToken)
//...
}

setPushIdentifier

JavaScript

ACPCore.setPushIdentifier("pushIdentifier");

Tracking push or local notification message interactions

User interactions with local or push notifications can be tracked by invoking the collectMessageInfo API. After the API is invoked, a network request is made to Campaign that contains the message interaction event. For more information on Campaign message interaction events, see Implementing local notification tracking.

Android
iOS

collectMessageInfo

Syntax

public static void collectMessageInfo(final Map<String, Object> messageInfo)

Example

@Override
protected void onResume() {
super.onResume();
handleTracking();
}
// handle a push or local notification click
private void handleTracking() {
// Check to see if this view was opened based on a notification
Intent intent = getIntent();
Bundle data = intent.getExtras();
if(data != null) {
HashMap<String,Object> userInfo = (HashMap)data.get("NOTIFICATION_USER_INFO");
String deliveryId = (String)userInfo.get("deliveryId");
String broadlogId = (String)userInfo.get("broadlogId");
HashMap<String, Object> contextData = new HashMap<>();
if (deliveryId != null && broadlogId != null) {
contextData.put("deliveryId", deliveryId);
contextData.put("broadlogId", broadlogId);
// Send Click Tracking since the user did click on the notification
contextData.put("action", "2");
MobileCore.collectMessageInfo(contextData);
// Send Open Tracking since the user opened the app
contextData.put("action", "1");
MobileCore.collectMessageInfo(contextData);
}
}
}

collectMessageInfo

Syntax

+ (void) collectMessageInfo: (nonnull NSDictionary*) messageInfo;

Objective-C

Example

// Handle notification interaction from background or closed
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler{
NSLog(@"User Info : %@",response.notification.request.content.userInfo);
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"App state : %ld",(long)[UIApplication sharedApplication].applicationState);
NSDictionary *userInfo = response.notification.request.content.userInfo;
NSString *broadlogId = userInfo[@"_mId"] ?: userInfo[@"broadlogId"];
NSString *deliveryId = userInfo[@"_dId"] ?: userInfo[@"deliveryId"];
// handle the user response to the local notification action buttons
if([response.actionIdentifier isEqualToString:@"YES_ACTION"] || [response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier]){
NSLog(@"Received a positive action with action identifier %@", response.actionIdentifier);
if ([UIApplication sharedApplication].applicationState == UIApplicationStateInactive || [UIApplication sharedApplication].applicationState == UIApplicationStateBackground) {
// App is launched from notification (action = "1")
[self sendTracking:tOpen withBroadlogId:broadlogId andDeliveryId:deliveryId];
}
// Push or Local notification is clicked (action = "2")
[self sendTracking:tClick withBroadlogId:broadlogId andDeliveryId:deliveryId];
} else if ([response.actionIdentifier isEqualToString:@"NO_ACTION"] || [response.actionIdentifier isEqualToString:UNNotificationDismissActionIdentifier]){
NSLog(@"Received a dismiss action with action identifier %@", response.actionIdentifier);
// Push or Local notification is clicked (action = "2")
[self sendTracking:tClick withBroadlogId:broadlogId andDeliveryId:deliveryId];
}
}
- (void) sendTracking:(TrackType)trackType withBroadlogId:(NSString *)broadlogId andDeliveryId:(NSString *)deliveryId {
if (broadlogId != nil && deliveryId != nil) {
NSString *action = nil;
switch (trackType) {
case tImpression:
action = @"7";
break;
case tOpen:
action = @"1";
break;
case tClick:
action = @"2";
break;
default:
NSLog(@"Received invalid tracking type, aborting send!");
return;
}
[ACPCore collectMessageInfo:@{
@"broadlogId" : broadlogId,
@"deliveryId": deliveryId,
@"action": action
}];
}
}

Swift

Example

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
print("User Info :", response.notification.request.content.userInfo)
DispatchQueue.main.async {
print(String(format: "App state :", UIApplication.shared.applicationState.rawValue))
let userInfo = response.notification.request.content.userInfo
let broadlogId = userInfo["_mId"] ?? userInfo["broadlogId"] as? String
let deliveryId = userInfo["_dId"] ?? userInfo["deliveryId"] as? String
// handle the user response to the local notification action buttons
if (response.actionIdentifier == "YES_ACTION") || (response.actionIdentifier == UNNotificationDefaultActionIdentifier) {
print("Received a positive action with action identifier", response.actionIdentifier)
if UIApplication.shared.applicationState == .inactive || UIApplication.shared.applicationState == .background {
// App is launched from notification (action = "1")
self.sendTracking(tOpen, withBroadlogId: broadlogId, andDeliveryId: deliveryId)
}
// Push or Local notification is clicked (action = "2")
self.sendTracking(tClick, withBroadlogId: broadlogId, andDeliveryId: deliveryId)
} else if (response.actionIdentifier == "NO_ACTION") || (response.actionIdentifier == UNNotificationDismissActionIdentifier) {
print("Received a dismiss action with action identifier",response.actionIdentifier)
// Push or Local notification is clicked (action = "2")
self.sendTracking(tClick, withBroadlogId: broadlogId, andDeliveryId: deliveryId)
}
}
}
func sendTracking(_ trackType: TrackType, withBroadlogId broadlogId: String?, andDeliveryId deliveryId: String?) {
if broadlogId != nil && deliveryId != nil {
var action: String? = nil
switch trackType {
case tImpression:
action = "7"
case tOpen:
action = "1"
case tClick:
action = "2"
default:
print("Received invalid tracking type, aborting send!")
return
}
ACPCore.collectMessageInfo([
"broadlogId": broadlogId,
"deliveryId": deliveryId,
"action": action
])
}
}