Java
This API can be called with AdobeCallback or AdobeCallbackWithError for retrieving the attributes from the Mobile SDK. When AdobeCallbackWithError
is provided, this API uses a default timeout of 500ms. If the operation times out or an unexpected error occurs, the fail
method is called with the appropriate AdobeError.
Syntax
Copied to your clipboardpublic static void appendVisitorInfoForURL(@NonNull final String baseURL, @NonNull final AdobeCallback<String> callback)
- baseUrl is the URL to which the visitor information needs to be appended. If the visitor information is nil or empty, the URL is returned as is.
- callback is invoked after the updated URL is available.
Example
Copied to your clipboardIdentity.appendVisitorInfoForURL("https://example.com", new AdobeCallback<String>() {@Overridepublic void call(String urlWithAdobeVisitorInfo) {//handle the new URL here//For example, open the URL on the device browser//Intent i = new Intent(Intent.ACTION_VIEW);i.setData(Uri.parse(urlWithAdobeVisitorInfo));startActivity(i);}});
Swift
Syntax
Copied to your clipboardstatic func appendTo(url: URL?, completion: @escaping (URL?, Error?) -> Void)
- url is the URL to which the visitor information needs to be appended. If the visitor information is nil or empty, the URL is returned as is.
- completion is invoked after the updated URL is available or Error if an unexpected exception occurs or the request times out. The returned
Error
contains the AEPError code of the specific error.
Example
Copied to your clipboardIdentity.appendTo(url: URL(string: "https://example.com")) { appendedURL, error inif let error = error {// handle error} else {// handle the appended url hereif let appendedURL = appendedURL {// APIs which update the UI must be called from main threadDispatchQueue.main.async {self.webView.load(URLRequest(url: appendedURL!))}} else {// handle error, nil appendedURL}}})
Objective-C
Syntax
Copied to your clipboard+ (void) appendToUrl: (NSURL * _Nullable baseUrl) completion: ^(NSURL * _Nullable urlWithVisitorData, NSError * _Nullable error) completion;
Example
Copied to your clipboardNSURL* url = [NSURL URLWithString:@"https://example.com"];[AEPMobileIdentity appendToUrl:url completion:^(NSURL * _Nullable urlWithVisitorData, NSError * _Nullable error) {if (error) {// handle error here} else {// handle the appended url hereif (urlWithVisitorData) {// APIs which update the UI must be called from main threaddispatch_async(dispatch_get_main_queue(), ^{[[self webView] loadRequest:[NSURLRequest requestWithURL:urlWithVisitorData]];}} else {// handle error, nil urlWithVisitorData}}}];
Java
Syntax
Copied to your clipboard@NonNullpublic static String extensionVersion();
Example
Copied to your clipboardString identityExtensionVersion = Identity.extensionVersion();
Swift
Syntax
Copied to your clipboardstatic var extensionVersion: String
Example
Copied to your clipboardlet identityExtensionVersion = Identity.extensionVersion
Objective-C
Syntax
Copied to your clipboard+ (nonnull NSString*) extensionVersion;
Example
Copied to your clipboardNSString *identityVersion = [AEPMobileIdentity extensionVersion];
Java
This API can be called with AdobeCallback or AdobeCallbackWithError for retrieving the ECID from the Mobile SDK. When AdobeCallbackWithError
is provided, this API uses a default timeout of 500ms. If the operation times out or an unexpected error occurs, the fail
method is called with the appropriate AdobeError.
Syntax
Copied to your clipboardpublic static void getExperienceCloudId(@NonNull final AdobeCallback<String> callback)
- callback is invoked after the ECID is available.
Example
Copied to your clipboardIdentity.getExperienceCloudId(new AdobeCallback<String>() {@Overridepublic void call(String id) {//Handle the ID returned here}});
Swift
Syntax
Copied to your clipboard@objc(getExperienceCloudId:)static func getExperienceCloudId(completion: @escaping (String?, Error?) -> Void)
- completion is invoked with String after the ECID is available, or Error if an unexpected error occurs or the request times out. The returned
Error
contains the AEPError code of the specific error.
Example
Copied to your clipboardIdentity.getExperienceCloudId { ecid, error inif let error = error {// handle error here} else {// handle the retrieved ID here}}
Objective-C
Syntax
Copied to your clipboard+ (void) getExperienceCloudId: ^(NSString * _Nullable ecid, NSError * _Nullable error) completion;
Example
Copied to your clipboard[AEPMobileIdentity getExperienceCloudId:^(NSString * _Nullable ecid, NSError *error) {if (error) {// handle error here} else {// handle the retrieved ID here}}];
Java
This API can be called with AdobeCallback or AdobeCallbackWithError for retrieving the custom identifiers from the Mobile SDK. When AdobeCallbackWithError
is provided, this API uses a default timeout of 500ms. If the operation times out or an unexpected error occurs, the fail
method is called with the appropriate AdobeError.
Syntax
Copied to your clipboardpublic static void getIdentifiers(@NonNull final AdobeCallback<List<VisitorID>> callback)
- callback is invoked after the customer identifiers are available.
Example
Copied to your clipboardIdentity.getIdentifiers(new AdobeCallback<List<VisitorID>>() {@Overridepublic void call(List<VisitorID> idList) {//Process the IDs here}});
Swift
Syntax
Copied to your clipboard@objc(getIdentifiers:)static func getIdentifiers(completion: @escaping ([Identifiable]?, Error?) -> Void)
- completion is invoked with a list of Identifiable objects after the customer identifiers are available, or Error if an unexpected error occurs or the request times out. The returned
Error
contains the AEPError code of the specific error.
Example
Copied to your clipboardIdentity.getIdentifiers { identifiers, error inif let error = error {// handle error here} else {// handle the retrieved identifiers here}}
Objective-C
Syntax
Copied to your clipboard+ (void) getIdentifiers: ^(NSArray<id<AEPIdentifiables>> * _Nullable identifiers, NSError * _Nullable error) completion;
Example
Copied to your clipboard[[AEPMobileIdentity getIdentifiers:^(NSArray<id<AEPIdentifiable>> * _Nullable identifiers, NSError *error) {if (error) {// handle error here} else {// handle the retrieved identifiers here}}];
Java
This method was added in Core version 1.4.0 and Identity version 1.1.0.
This API can be called with AdobeCallback or AdobeCallbackWithError for retrieving the attributes from the Mobile SDK. When AdobeCallbackWithError
is provided, this API uses a default timeout of 500ms. If the operation times out or an unexpected error occurs, the fail
method is called with the appropriate AdobeError.
Syntax
Copied to your clipboardpublic static void getUrlVariables(final AdobeCallback<String> callback);
- callback has an NSString value that contains the visitor identifiers as a query string after the service request is complete.
Example
Copied to your clipboardIdentity.getUrlVariables(new AdobeCallback<String>() {@Overridepublic void call(String stringWithAdobeVisitorInfo) {//handle the URL query parameter string here//For example, open the URL on the device browser//Intent i = new Intent(Intent.ACTION_VIEW);i.setData(Uri.parse("https://example.com?" + urlWithAdobeVisitorInfo));startActivity(i);}});
Swift
Syntax
Copied to your clipboard@objc(getUrlVariables:)static func getUrlVariables(completion: @escaping (String?, Error?) -> Void)
- completion is invoked with String containing the visitor identifiers as a query string, or Error if an unexpected error occurs or the request times out. The returned
Error
contains the AEPError code of the specific error. The default timeout of 500ms.
Example
Copied to your clipboardIdentity.getUrlVariables { (urlVariables, error) inif let error = error {// handle error} else {var urlStringWithVisitorData: String = "https://example.com"if let urlVariables: String = urlVariables {urlStringWithVisitorData.append("?" + urlVariables)}guard let urlWithVisitorData: URL = URL(string: urlStringWithVisitorData) else {// handle error, unable to construct URLreturn}// APIs which update the UI must be called from main threadDispatchQueue.main.async {self.webView.load(URLRequest(url: urlWithVisitorData))}}}
Objective-C
Syntax
Copied to your clipboard+ (void) getUrlVariables: ^(NSString * _Nullable urlVariables, NSError * _Nullable error) completion;
Example
Copied to your clipboard[AEPMobileIdentity getUrlVariables:^(NSString * _Nullable urlVariables, NSError *error) {if (error) {// handle error here} else {// handle the URL query parameter string hereNSString* urlString = @"https://example.com";NSString* urlStringWithVisitorData = [NSString stringWithFormat:@"%@?%@", urlString, urlVariables];NSURL* urlWithVisitorData = [NSURL URLWithString:urlStringWithVisitorData];// APIs which update the UI must be called from main threaddispatch_async(dispatch_get_main_queue(), ^{[[self webView] loadRequest:[NSURLRequest requestWithURL:urlWithVisitorData]];}}}];
Java
After calling the setApplication()
method in the onCreate()
method, register the extension. If the registration was not successful, an InvalidInitException
is thrown.
Copied to your clipboardpublic class MobileApp extends Application {@Overridepublic void onCreate() {super.onCreate();MobileCore.setApplication(this);try {Identity.registerExtension();} catch (Exception e) {//Log the exception}}}
For iOS AEP libraries, registration is changed to a single API call. Calling the MobileCore.start API is no longer required. See MobileCore.registerExtensions() for more information.
Swift
Example
Copied to your clipboard// AppDelegate.swiftfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {MobileCore.registerExtensions([AEPIdentity.Identity.self, Lifecycle.self, Analytics.self], {MobileCore.configureWith(appId: "mobilePropertyEnvironmentID")})...}
Objective-C
Example
Copied to your clipboard// AppDelegate.m- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {[AEPMobileCore registerExtensions:@[AEPMobileIdentity.class, AEPMobileLifecycle.class, AEPMobileAnalytics.class] completion:^{[AEPMobileCore configureWithAppId: @"mobilePropertyEnvironmentID"];}];...}
Java
Syntax
Copied to your clipboardpublic static void setAdvertisingIdentifier(@Nullable final String advertisingIdentifier)
- advertisingIdentifier is a string that provides developers with a simple, standard system to track the Ads through their apps.
Example
This is just an implementation example. For more information about advertising identifiers and how to handle them correctly in your mobile application, see Google Play Services documentation about AdvertisingIdClient.
This example requires Google Play Services to be configured in your mobile application. For instructions on how to import the Google Mobile Ads SDK and how to configure your ApplicationManifest.xml file, see Google Mobile Ads SDK setup.
Copied to your clipboard...@Overridepublic void onResume() {super.onResume();...new Thread(new Runnable() {@Overridepublic void run() {String advertisingIdentifier = null;try {AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(getApplicationContext());if (adInfo != null) {if (!adInfo.isLimitAdTrackingEnabled()) {advertisingIdentifier = adInfo.getId();} else {MobileCore.log(LoggingMode.DEBUG, "ExampleActivity", "Limit Ad Tracking is enabled by the user, cannot process the advertising identifier");}}} catch (IOException e) {// Unrecoverable error connecting to Google Play services (e.g.,// the old version of the service doesn't support getting AdvertisingId).MobileCore.log(LoggingMode.DEBUG, "ExampleActivity", "IOException while retrieving the advertising identifier " + e.getLocalizedMessage());} catch (GooglePlayServicesNotAvailableException e) {// Google Play services is not available entirely.MobileCore.log(LoggingMode.DEBUG, "ExampleActivity", "GooglePlayServicesNotAvailableException while retrieving the advertising identifier " + e.getLocalizedMessage());} catch (GooglePlayServicesRepairableException e) {// Google Play services is not installed, up-to-date, or enabled.MobileCore.log(LoggingMode.DEBUG, "ExampleActivity", "GooglePlayServicesRepairableException while retrieving the advertising identifier " + e.getLocalizedMessage());}MobileCore.setAdvertisingIdentifier(advertisingIdentifier);}}).start();}
To access IDFA and handle it correctly in your mobile application, see the Apple developer documentation about IDFA
Starting iOS 14+, applications must use the App Tracking Transparency framework to request user authorization before using the Identifier for Advertising (IDFA).
Swift
Syntax
Copied to your clipboard@objc(setAdvertisingIdentifier:)public static func setAdvertisingIdentifier(_ identifier: String?)
- identifier is a string that provides developers with a simple, standard system to continue to track the Ads through their apps.
Example
Copied to your clipboardimport AdSupportimport AppTrackingTransparency...func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {...if #available(iOS 14, *) {setAdvertisingIdentiferUsingTrackingManager()} else {// Fallback on earlier versionssetAdvertisingIdentifierUsingIdentifierManager()}}func setAdvertisingIdentifierUsingIdentifierManager() {var idfa:String = "";if (ASIdentifierManager.shared().isAdvertisingTrackingEnabled) {idfa = ASIdentifierManager.shared().advertisingIdentifier.uuidString;} else {Log.debug(label: "AppDelegateExample","Advertising Tracking is disabled by the user, cannot process the advertising identifier.");}MobileCore.setAdvertisingIdentifier(idfa);}@available(iOS 14, *)func setAdvertisingIdentiferUsingTrackingManager() {ATTrackingManager.requestTrackingAuthorization { (status) invar idfa: String = "";switch (status) {case .authorized:idfa = ASIdentifierManager.shared().advertisingIdentifier.uuidStringcase .denied:Log.debug(label: "AppDelegateExample","Advertising Tracking is denied by the user, cannot process the advertising identifier.")case .notDetermined:Log.debug(label: "AppDelegateExample","Advertising Tracking is not determined, cannot process the advertising identifier.")case .restricted:Log.debug(label: "AppDelegateExample","Advertising Tracking is restricted by the user, cannot process the advertising identifier.")}MobileCore.setAdvertisingIdentifier(idfa)}}
Objective-C
Syntax
Copied to your clipboard+ (void) setAdvertisingIdentifier: (NSString * _Nullable identifier);
Example
Copied to your clipboard#import <AdSupport/ASIdentifierManager.h>#import <AppTrackingTransparency/ATTrackingManager.h>...- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {- ...-if (@available(iOS 14, *)) {[self setAdvertisingIdentiferUsingTrackingManager];} else {// fallback to earlier versions[self setAdvertisingIdentifierUsingIdentifierManager];}}- (void) setAdvertisingIdentifierUsingIdentifierManager {// setup the advertising identifierNSString *idfa = nil;if ([[ASIdentifierManager sharedManager] isAdvertisingTrackingEnabled]) {idfa = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];} else {[AEPLog debugWithLabel:@"AppDelegateExample"message:@"Advertising Tracking is disabled by the user, cannot process the advertising identifier"];}[AEPMobileCore setAdvertisingIdentifier:idfa];}- (void) setAdvertisingIdentiferUsingTrackingManager API_AVAILABLE(ios(14)) {[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status){NSString *idfa = nil;switch(status) {case ATTrackingManagerAuthorizationStatusAuthorized:idfa = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];break;case ATTrackingManagerAuthorizationStatusDenied:[AEPLog debugWithLabel:@"AppDelegateExample"message:@"Advertising Tracking is denied by the user, cannot process the advertising identifier"];break;case ATTrackingManagerAuthorizationStatusNotDetermined:[AEPLog debugWithLabel:@"AppDelegateExample"message:@"Advertising Tracking is not determined, cannot process the advertising identifier"];break;case ATTrackingManagerAuthorizationStatusRestricted:[AEPLog debugWithLabel:@"AppDelegateExample"message:@"Advertising Tracking is restricted by the user, cannot process the advertising identifier"];break;}[AEPMobileCore setAdvertisingIdentifier:idfa];}];}
Java
Syntax
Copied to your clipboardpublic static void setPushIdentifier(@Nullable final String pushIdentifier)
- pushIdentifier is a string that contains the device token for push notifications.
Example
Copied to your clipboard//Retrieve the token from either GCM or FCM, and pass it to the SDKMobileCore.setPushIdentifier(token);
Swift
Syntax
Copied to your clipboard@objc(setPushIdentifier:)public static func setPushIdentifier(_ deviceToken: Data?)
- deviceToken is a string that contains the device token for push notifications.
Example
Copied to your clipboard// Set the deviceToken that the APNs has assigned to the deviceMobileCore.setPushIdentifier(deviceToken)
Objective-C
Syntax
Copied to your clipboard+ (void) setPushIdentifier: (NSString * _Nullable deviceToken);
Example
Copied to your clipboard// Set the deviceToken that the APNS has assigned to the device[AEPMobileCore setPushIdentifier:deviceToken];
Java
Syntax
Copied to your clipboardpublic static void syncIdentifier(@NonNull final String identifierType,@Nullable final String identifier,@NonNull final VisitorID.AuthenticationState authenticationState)
- identifierType (String) contains the
identifier type
, and this parameter should not be null or empty. The allowed characters are [A-Za-z0-9_.] - identifier (String) contains the
identifier value
, and this parameter should not be null or empty. - authenticationState (AuthenticationState) indicates the authentication state of the user and contains one of the VisitorID.AuthenticationState values.
Example
Copied to your clipboardIdentity.syncIdentifier("idType","idValue",VisitorID.AuthenticationState.AUTHENTICATED);
Swift
Syntax
Copied to your clipboard@objc(syncIdentifierWithType:identifier:authenticationState:)static func syncIdentifier(identifierType: String, identifier: String, authenticationState: MobileVisitorAuthenticationState)
- The identifierType (String) contains the
identifier type
, and this parameter should not be null or empty. The allowed characters are [A-Za-z0-9_.] - The identifier (String) contains the
identifier
value, and this parameter should not be null or empty. If either theidentifierType
oridentifier
contains a null or an empty string, the identifier is ignored by the Identity extension. - The authenticationState (MobileVisitorAuthenticationState) value indicates the authentication state for the user and contains one of the MobileVisitorAuthenticationState values.
Example
Copied to your clipboardIdentity.syncIdentifier(identifierType: "idType",identifier: "idValue",authentication: .unknown)
Objective-C
Syntax
Copied to your clipboard+ (void) syncIdentifierWithType: (NSString * _Nonnull identifierType)identifier: (NSString * _Nonnull identifier)authentication: (enum AEPAuthenticationState authenticationState);
Example
Copied to your clipboard[AEPMobileIdentity syncIdentifierWithType:@"idType"identifier:@"idValue"authenticationState:AEPMobileVisitorAuthStateUnknown];
Java
Syntax
Copied to your clipboardpublic static void syncIdentifiers(@NonNull final Map<String, String> identifiers)
- identifiers is a map that contains the identifiers with the Identifier type as the key, and the string identifier as the value. In each identifier pair, if the
identifier type
contains a null or an empty string, the identifier is ignored by the Identity extension.
Example
Copied to your clipboardMap<String, String> identifiers = new HashMap<String, String>();identifiers.put("idType1", "idValue1");identifiers.put("idType2", "idValue2");identifiers.put("idType3", "idValue3");Identity.syncIdentifiers(identifiers);
Swift
Syntax
Copied to your clipboard@objc(syncIdentifiers:)static func syncIdentifiers(identifiers: [String: String]?)
- The identifiers dictionary contains identifier type as the key and identifier as the value, both identifier type and identifier should be non empty and non nil values.
Example
Copied to your clipboardlet ids : [String: String] = ["idType1":"idValue1","idType2":"idValue2","idType3":"idValue3"];Identity.syncIdentifiers(identifiers: ids)
Objective-C
Syntax
Copied to your clipboard+ (void) syncIdentifiers: (NSDictionary<NSString *, NSString *> * _Nullable identifiers);
Example
Copied to your clipboardNSDictionary *ids = @{@"idType1":@"idValue1",@"idType2":@"idValue2",@"idType3":@"idValue3"};[AEPMobileIdentity syncIdentifiers:ids];
Java
Syntax
Copied to your clipboardpublic static void syncIdentifiers(@NonNull final Map<String, String> identifiers,@NonNull final VisitorID.AuthenticationState authenticationState)
- identifiers is a map that contains IDs with the identifier type as the key, and the string identifier as the value.
- authState indicates the authentication state for the user, which contains one of the following VisitorID.AuthenticationState values.
Example
Copied to your clipboardMap<String, String> identifiers = new HashMap<String, String>();identifiers.put("idType1", "idValue1");identifiers.put("idType2", "idValue2");identifiers.put("idType3", "idValue3");Identity.syncIdentifiers(identifiers, VisitorID.AuthenticationState.AUTHENTICATED);
Swift
Syntax
Copied to your clipboard@objc(syncIdentifiers:authenticationState:)static func syncIdentifiers(identifiers: [String: String]?, authenticationState: MobileVisitorAuthenticationState)
- The identifiers dictionary contains identifier type as the key and identifier as the value, both identifier type and identifier should be non empty and non nil values.
- The authenticationState (MobileVisitorAuthenticationState) indicates the authentication state of the user and contains one of the MobileVisitorAuthenticationState values.
Example
Copied to your clipboardlet ids : [String: String] = ["idType1":"idValue1","idType2":"idValue2","idType3":"idValue3"];Identity.syncIdentifiers(identifiers: ids, authenticationState: .authenticated)
Objective-C
Syntax
Copied to your clipboard+ (void) syncIdentifiers: (NSDictionary<NSString *, NSString *> * _Nullable identifiers)authentication: (enum AEPAuthenticationState authenticationState);
Example
Copied to your clipboardNSDictionary *ids = @{@"idType1":@"idValue1",@"idType2":@"idValue2",@"idType3":@"idValue3"};[AEPMobileIdentity syncIdentifiers:ids authenticationState:AEPMobileVisitorAuthStateAuthenticated];
AuthenticationState
This class is used to indicate the authentication state for the current VisitorID
.
Copied to your clipboardpublic enum AuthenticationState {UNKNOWN,AUTHENTICATED,LOGGED_OUT;}
VisitorID
This class is an identifier to be used with the Adobe Experience Cloud Identity Service.
Copied to your clipboardpublic class VisitorID {//Constructorpublic VisitorID(String idOrigin, String idType, String id, VisitorID.AuthenticationState authenticationState);public VisitorID.AuthenticationState getAuthenticationState();public final String getId();public final String getIdOrigin();public final String getIdType();}
MobileVisitorAuthenticationState
This is used to indicate the authentication state for the current Identifiable
.
Copied to your clipboard@objc(AEPMobileVisitorAuthState) public enum MobileVisitorAuthenticationState: Int, Codable {case unknown = 0case authenticated = 1case loggedOut = 2}
Identifiable
Copied to your clipboard@objc(AEPIdentifiable) public protocol Identifiable {/// Origin of the identifiervar origin: String? { get }/// Type of the identifiervar type: String? { get }/// The identifiervar identifier: String? { get }/// The authentication state for the identifiervar authenticationState: MobileVisitorAuthenticationState { get }}