Java
Syntax
Copied to your clipboardpublic static String extensionVersion()
Example
Copied to your clipboardString extensionVersion = Identity.extensionVersion();
Kotlin
Example
Copied to your clipboardval extensionVersion = Identity.extensionVersion()
Swift
Syntax
Copied to your clipboardstatic var extensionVersion: String
Example
Copied to your clipboardlet extensionVersion = EdgeIdentity.extensionVersion
Objective-C
Syntax
Copied to your clipboard+ (nonnull NSString*) extensionVersion;
Example
Copied to your clipboardNSString *extensionVersion = [AEPMobileEdgeIdentity extensionVersion];
The ECID value is returned via the AdobeCallback. When AdobeCallbackWithError is provided to this API, the timeout value is 500ms. If the operation times out or an unexpected error occurs, the fail
method is called with the appropriate AdobeError.
Java
Syntax
Copied to your clipboardpublic static void getExperienceCloudId(final AdobeCallback<String> callback);
- callback is invoked after the ECID is available. The callback may be invoked on a different thread.
Example
Copied to your clipboardIdentity.getExperienceCloudId(new AdobeCallback<String>() {@Overridepublic void call(String id) {// Handle the ID returned here}});
Kotlin
Example
Copied to your clipboardIdentity.getExperienceCloudId { id ->// Handle the ID returned here}
Swift
Syntax
Copied to your clipboardstatic func getExperienceCloudId(completion: @escaping (String?, Error?) -> Void)
- completion is invoked after the ECID is available. The default timeout is 1000ms.
Example
Copied to your clipboardIdentity.getExperienceCloudId { (ecid, error) inif let error = error {// Handle the 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[AEPMobileEdgeIdentity getExperienceCloudId:^(NSString *ecid, NSError *error) {// handle the error and the retrieved ID here}];
When AdobeCallbackWithError is provided, and you are fetching the identities from the Mobile SDK, the timeout value is 500ms. If the operation times out or an unexpected error occurs, the fail
method is called with the appropriate AdobeError.
Java
Syntax
Copied to your clipboardpublic static void getIdentities(final AdobeCallback<IdentityMap> callback);
- callback is invoked after the identities are available. The return format is an instance of IdentityMap. The callback may be invoked on a different thread.
Example
Copied to your clipboardIdentity.getIdentities(new AdobeCallback<IdentityMap>() {@Overridepublic void call(IdentityMap identityMap) {// Handle the IdentityMap returned here}});
Kotlin
Example
Copied to your clipboardIdentity.getIdentities { identityMap ->// Handle the IdentityMap returned here}
Swift
Syntax
Copied to your clipboardstatic func getIdentities(completion: @escaping (IdentityMap?, Error?) -> Void)
- completion is invoked after the identities are available. The default timeout is 1000ms. The return format is an instance of IdentityMap.
Example
Copied to your clipboardIdentity.getIdentities { (identityMap, error) inif let error = error {// Handle the error here} else {// Handle the retrieved identitites here}}
Objective-C
Syntax
Copied to your clipboard+ (void) getIdentities:^(AEPIdentityMap * _Nullable map, NSError * _Nullable error)completion
Example
Copied to your clipboard[AEPMobileEdgeIdentity getIdentities:^(AEPIdentityMap *map, NSError *error) {// handle the error and the retrieved ID here}];
When AdobeCallbackWithError
is provided and you are fetching the URL variables from the Mobile SDK, the timeout value is 500ms. If the operation times out or an unexpected error occurs, the fail
method is called with the appropriate AdobeError
.
Java
Syntax
Copied to your clipboardpublic static void getUrlVariables(final AdobeCallback<String> callback);
callback
has a String 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 urlVariablesString) {// Handle the URL query parameter string here// For example, open the URL in a webViewWebView webView;webView = (WebView)findViewById(R.id.your_webview); // Initialize with your webViewwebview.loadUrl("https://example.com?" + urlVariablesString);}});
Kotlin
Example
Copied to your clipboardIdentity.getUrlVariables { urlVariablesString ->// Handle the URL query parameter string here// For example, open the URL in a webViewval webView = findViewById<WebView>(R.id.your_webview) // Initialize with your webViewwebView.loadUrl("http://www.example.com?" + urlVariablesString)}
Swift
Syntax
Copied to your clipboardstatic func getUrlVariables(completion: @escaping (String?, Error?) -> Void)
completion
is invoked withurlVariables
containing the visitor identifiers as a query string, or witherror
if an unexpected error occurs or the request times out. The returnedError
contains the AEPError code of the specific error. The default timeout is 1000ms.
Example
Copied to your clipboardIdentity.getUrlVariables { (urlVariables, error) inif let error = error {// Handle the error here} else {var urlStringWithVisitorData: String = "https://example.com"if let urlVariables: String = urlVariables {urlStringWithVisitorData.append("?" + urlVariables)}guard let urlWithVisitorData: URL = URL(string: urlStringWithVisitorData) else {// Handle the error, unable to construct URLreturn}// Handle the retrieved urlVariables encoded string here// 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[AEPMobileEdgeIdentity getUrlVariables:^(NSString *urlVariables, NSError *error){if (error) {// Handle the 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
Syntax
Copied to your clipboardpublic static void registerExtension()
Example
Copied to your clipboardimport com.adobe.marketing.mobile.edge.identity.Identity...Identity.registerExtension();
Java
Syntax
Copied to your clipboardpublic static void removeIdentity(final IdentityItem item, final String namespace);
Example
Copied to your clipboardIdentityItem item = new IdentityItem("user@example.com");Identity.removeIdentity(item, "Email");
Kotlin
Example
Copied to your clipboardval item = IdentityItem("user@example.com")Identity.removeIdentity(item, "Email")
Swift
Syntax
Copied to your clipboardstatic func removeIdentity(item: IdentityItem, withNamespace: String)
Example
Copied to your clipboardIdentity.removeIdentity(item: IdentityItem(id: "user@example.com"), withNamespace: "Email")
Objective-C
Syntax
Copied to your clipboard+ (void) removeIdentityItem:(AEPIdentityItem * _Nonnull) itemwithNamespace: (NSString * _Nonnull) namespace
Example
Copied to your clipboardAEPIdentityItem *item = [[AEPIdentityItem alloc] initWithId:@"user@example.com" authenticatedState:AEPAuthenticatedStateAuthenticated primary:false];[AEPMobileEdgeIdentity removeIdentityItem:item withNamespace:@"Email"];
In order to enable collection of the user's current advertising tracking authorization selection for the provided advertising identifier, you need to install and register the AEPEdgeConsent extension and update the AEPEdge dependency to minimum 1.3.2.
These examples require Google Play Services to be configured in your mobile application and use the Google Mobile Ads Lite SDK. For instructions on how to import the SDK and configure your ApplicationManifest.xml
file see Google Mobile Ads Lite SDK setup. For more information about advertising identifiers and how to handle them correctly in your mobile application see Google Play Services documentation about AdvertisingIdClient.
Java
Syntax
Copied to your clipboardpublic static void setAdvertisingIdentifier(final String advertisingIdentifier);
- advertisingIdentifier is an ID string that provides developers with a simple, standard system to continue to track ads throughout their apps.
Example
Copied to your clipboardimport com.google.android.gms.ads.identifier.AdvertisingIdClient;import com.google.android.gms.common.GooglePlayServicesNotAvailableException;import com.google.android.gms.common.GooglePlayServicesRepairableException;import java.io.IOException;import android.util.Log;...@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 {Log.d("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).Log.d("ExampleActivity", "IOException while retrieving the advertising identifier " + e.getLocalizedMessage());} catch (GooglePlayServicesNotAvailableException e) {// Google Play services is not available entirely.Log.d("ExampleActivity", "GooglePlayServicesNotAvailableException while retrieving the advertising identifier " + e.getLocalizedMessage());} catch (GooglePlayServicesRepairableException e) {// Google Play services is not installed, up-to-date, or enabled.Log.d("ExampleActivity", "GooglePlayServicesRepairableException while retrieving the advertising identifier " + e.getLocalizedMessage());}MobileCore.setAdvertisingIdentifier(advertisingIdentifier);}}).start();}
Kotlin
- advertisingIdentifier is an ID string that provides developers with a simple, standard system to continue to track ads throughout their apps.
Example
Copied to your clipboardimport android.content.Contextimport android.util.Logimport com.google.android.gms.ads.identifier.AdvertisingIdClientimport com.google.android.gms.common.GooglePlayServicesNotAvailableExceptionimport com.google.android.gms.common.GooglePlayServicesRepairableExceptionimport java.io.IOException...suspend fun getGAID(applicationContext: Context): String {var adID = ""try {val idInfo = AdvertisingIdClient.getAdvertisingIdInfo(applicationContext)if (idInfo.isLimitAdTrackingEnabled) {Log.d("ExampleActivity", "Limit Ad Tracking is enabled by the user, setting ad ID to \"\"")return adID}Log.d("ExampleActivity", "Limit Ad Tracking disabled; ad ID value: ${idInfo.id}")adID = idInfo.id} catch (e: GooglePlayServicesNotAvailableException) {Log.d("ExampleActivity", "GooglePlayServicesNotAvailableException while retrieving the advertising identifier ${e.localizedMessage}")} catch (e: GooglePlayServicesRepairableException) {Log.d("ExampleActivity", "GooglePlayServicesRepairableException while retrieving the advertising identifier ${e.localizedMessage}")} catch (e: IOException) {Log.d("ExampleActivity", "IOException while retrieving the advertising identifier ${e.localizedMessage}")}Log.d("ExampleActivity", "Returning ad ID value: $adID")return adID}
Call site:
Copied to your clipboardimport kotlinx.coroutines.CoroutineScopeimport kotlinx.coroutines.Dispatchersimport kotlinx.coroutines.launch...// Create background coroutine scope to fetch ad ID valueval scope = CoroutineScope(Dispatchers.IO).launch {val adID = sharedViewModel.getGAID(context.applicationContext)Log.d("ExampleActivity", "Sending ad ID value: $adID to MobileCore.setAdvertisingIdentifier")MobileCore.setAdvertisingIdentifier(adID)}
In order to enable the collection of current advertising tracking user's selection based on the provided advertising identifier, you need to install and register the Consent for Edge Network extension and update the Edge Network extension dependency to minimum 1.4.1.
Starting from iOS 14+, applications must use the App Tracking Transparency framework to request user authorization before using the Identifier for Advertising (IDFA). To access IDFA and handle it correctly in your mobile application, see the Apple developer documentation about IDFA.
Swift
Syntax
Copied to your clipboard@objc(setAdvertisingIdentifier:)public static func setAdvertisingIdentifier(_ identifier: String?)
- identifier is an ID string that provides developers with a simple, standard system to continue to track ads throughout their apps.
Example
Copied to your clipboardimport AdSupportimport AppTrackingTransparency...func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {...if #available(iOS 14, *) {setAdvertisingIdentifierUsingTrackingManager()} 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 setAdvertisingIdentifierUsingTrackingManager() {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);
- identifier is an ID string that provides developers with a simple, standard system to continue to track ads throughout their apps.
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 setAdvertisingIdentifierUsingTrackingManager];} 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) setAdvertisingIdentifierUsingTrackingManager 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 updateIdentities(final IdentityMap identityMap);
Example
Copied to your clipboardIdentityItem item = new IdentityItem("user@example.com");IdentityMap identityMap = new IdentityMap();identityMap.addItem(item, "Email")Identity.updateIdentities(identityMap);
Kotlin
Example
Copied to your clipboardval item = IdentityItem("user@example.com")val identityMap = IdentityMap()identityMap.addItem(item, "Email")Identity.updateIdentities(identityMap)
Swift
Syntax
Copied to your clipboardstatic func updateIdentities(with map: IdentityMap)
Example
Copied to your clipboardlet identityMap = IdentityMap()identityMap.addItem(item: IdentityItem(id: "user@example.com"), withNamespace: "Email")Identity.updateIdentities(with: identityMap)
Objective-C
Syntax
Copied to your clipboard+ (void) updateIdentities:(AEPIdentityMap * _Nonnull)map
Example
Copied to your clipboardAEPIdentityItem *item = [[AEPIdentityItem alloc] initWithId:@"user@example.com" authenticatedState:AEPAuthenticatedStateAuthenticated primary:false];AEPIdentityMap *map = [[AEPIdentityMap alloc] init];[map addItem:item withNamespace:@"Email"];[AEPMobileEdgeIdentity updateIdentities:map];
Java
Example
Copied to your clipboard// ConstructIdentityMap identityMap = new IdentityMap();// Add an itemIdentityItem item = new IdentityItem("user@example.com");identityMap.addItem(item, "Email");// Remove an itemIdentityItem item = new IdentityItem("user@example.com");identityMap.removeItem(item, "Email");// Get a list of items for a given namespaceList<IdentityItem> items = identityMap.getIdentityItemsForNamespace("Email");// Get a list of all namespaces used in current IdentityMapList<String> namespaces = identityMap.getNamespaces();// Check if IdentityMap has no identitiesboolean hasNotIdentities = identityMap.isEmpty();
Kotlin
Example
Copied to your clipboard// Constructval identityMap = IdentityMap()// Add an itemval item = IdentityItem("user@example.com")identityMap.addItem(item, "Email")// Remove an itemval item = IdentityItem("user@example.com")identityMap.removeItem(item, "Email")// Get a list of items for a given namespaceval items = identityMap.getIdentityItemsForNamespace("Email")// Get a list of all namespaces used in current IdentityMapval namespaces = identityMap.getNamespaces()// Check if IdentityMap has no identitiesval hasNotIdentities = identityMap.isEmpty()
Swift
Example
Copied to your clipboard// Initializelet identityMap: IdentityMap = IdentityMap()// Add an itemidentityMap.add(item: IdentityItem(id: "user@example.com"), withNamespace: "Email")// Remove an itemidentityMap.remove(item: IdentityItem(id: "user@example.com", withNamespace: "Email"))// Get a list of items for a given namespacelet items: [IdentityItem] = identityMap.getItems(withNamespace: "Email")// Get a list of all namespaces used in current IdentityMaplet namespaces: [String] = identityMap.namespaces// Check if IdentityMap has no identitieslet hasNoIdentities: Bool = identityMap.isEmpty
Objective-C
Example
Copied to your clipboard// InitializeAEPIdentityMap* identityMap = [[AEPIdentityMap alloc] init];// Add an itemAEPIdentityItem* item = [[AEPIdentityItem alloc] initWithId:@"user@example.com" authenticatedState:AEPAuthenticatedStateAuthenticated primary:false];[identityMap addItem:item withNamespace:@"Email"];// Remove an itemAEPIdentityItem* item = [[AEPIdentityItem alloc] initWithId:@"user@example.com" authenticatedState:AEPAuthenticatedStateAuthenticated primary:false];[identityMap removeItem:item withNamespace:@"Email"];// Get a list of items for a given namespaceNSArray<AEPIdentityItem*>* items = [identityMap getItemsWithNamespace:@"Email"];// Get a list of all namespaces used in current IdentityMapNSArray<NSString*>* namespaces = identityMap.namespaces;// Check if IdentityMap has no identitiesbool hasNoIdentities = identityMap.isEmpty;
Java
Example
Copied to your clipboard// ConstructIdentityItem item = new IdentityItem("identifier");IdentityItem item = new IdentityItem("identifier", AuthenticatedState.AUTHENTICATED, false);// GettersString id = item.getId();AuthenticatedState state = item.getAuthenticatedState();boolean primary = item.isPrimary();
Kotlin
Example
Copied to your clipboard// Constructval item = IdentityItem("identifier")val item = IdentityItem("identifier", AuthenticatedState.AUTHENTICATED, false)// Gettersval id = item.idval state = item.authenticatedStateval primary = item.isPrimary
Swift
Example
Copied to your clipboard// Initializelet item = IdentityItem(id: "identifier")let item = IdentityItem(id: "identifier", authenticatedState: .authenticated, primary: false)// Getterslet id: String = item.idlet state: AuthenticatedState = item.authenticatedStatelet primary: Bool = item.primary
Objective-C
Example
Copied to your clipboard// InitializeAEPIdentityItem* item = [[AEPIdentityItem alloc] initWithId:@"identity" authenticatedState:AEPAuthenticatedStateAuthenticated primary:false];// GettersNSString* id = primaryEmail.id;long state = primaryEmail.authenticatedState;bool primary = primaryEmail.primary;
Java
Syntax
Copied to your clipboardpublic enum AuthenticatedState {AMBIGUOUS("ambiguous"),AUTHENTICATED("authenticated"),LOGGED_OUT("loggedOut");}
Kotlin
Syntax
Copied to your clipboardenum class AuthenticatedState(val name: String) {AMBIGUOUS("ambiguous"),AUTHENTICATED("authenticated"),LOGGED_OUT("loggedOut")}
Syntax
Copied to your clipboard@objc(AEPAuthenticatedState)public enum AuthenticatedState: Int, RawRepresentable, Codable {case ambiguous = 0case authenticated = 1case loggedOut = 2}