API Reference
extensionVersion
The extensionVersion() API returns the version of the Identity for Edge Network extension.
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];
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];
getExperienceCloudId
This API retrieves the Experience Cloud ID (ECID) that was generated when the app was initially launched. This ID is preserved between app upgrades, is saved and restored during the standard application backup process, and is removed at uninstall.
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}];
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}];
getIdentities
Get all identities in the Identity for Edge Network extension, including customer identifiers which were previously added.
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 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}];
getUrlVariables
This API is available with version 1.1.0 and above.
Returns the identifiers in a URL's query parameters for consumption in hybrid mobile applications. The response will not return any leading &
or ?
, since the caller is responsible for placing the variables in the resulting URL in the correct locations. If an error occurs while retrieving the URL variables, the callback handler will return a null
value. Otherwise, the encoded string is returned.
An example of an encoded string is as follows: "adobe_mc=TS%3DTIMESTAMP_VALUE%7CMCMID%3DYOUR_ECID%7CMCORGID%3D9YOUR_EXPERIENCE_CLOUD_ID"
MCMID
: This is also known as the Experience Cloud ID (ECID).MCORGID
: This is also known as the Experience Cloud Organization ID.TS
: The timestamp that is taken when the request was made.
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]];}}}];
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]];}}}];
registerExtension
This API has been deprecated starting in v2.0.0 and removed in v3.0.0 of the Android mobile extension.
Use MobileCore.registerExtensions()
API instead.
removeIdentity
Remove the identity from the stored client-side IdentityMap. The Identity extension will stop sending the identifier to the Edge Network. Using this API does not remove the identifier from the server-side User Profile Graph or Identity Graph.
Identities with an empty id or namespace are not allowed and are ignored.
Removing identities using a reserved namespace is not allowed using this API. The reserved namespaces are:
- ECID
- IDFA
- GAID
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"];
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"];
resetIdentities
Clears all identities stored in the Identity extension and generates a new Experience Cloud ID (ECID). Using this API does not remove the identifiers from the server-side User Profile Graph or Identity Graph.
This is a destructive action, since once an ECID is removed it cannot be reused. The new ECID generated by this API can increase metrics like unique visitors when a new user profile is created.
Some example use cases for this API are:
- During debugging, to see how new ECIDs (and other identifiers paired with it) behave with existing rules and metrics.
- A last-resort reset for when an ECID should no longer be used.
This API is not recommended for:
- Resetting a user's consent and privacy settings; see Privacy and GDPR.
- Removing existing custom identifiers; use the
removeIdentity
API instead. - Removing a previously synced advertising identifier after the advertising tracking settings were changed by the user; use the
setAdvertisingIdentifier
API instead.
The Identity for Edge Network extension does not read the Mobile SDK's privacy status, and therefore setting the SDK's privacy status to opt-out will not automatically clear the identities from the Identity for Edge Network extension.
See MobileCore.resetIdentities
for more details.
setAdvertisingIdentifier
When this API is called with a valid advertising identifier, the Identity for Edge Network extension includes the advertising identifier in the XDM Identity Map using the namespace GAID
(Google Advertising ID) in Android and IDFA
(Identifier for Advertisers) in iOS. If the API is called with the empty string (""
), null
/nil
, or the all-zeros UUID string values, the advertising identifier is removed from the XDM Identity Map (if previously set).
The advertising identifier is preserved between app upgrades, is saved and restored during the standard application backup process, and is removed at uninstall.
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];}];}
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];}];}
updateIdentities
Update the currently known identities within the SDK. The Identity extension will merge the received identifiers with the previously saved ones in an additive manner; no identities are removed by this API.
Identities with an empty id or namespace are not allowed and are ignored.
Updating identities using a reserved namespace is not allowed using this API. The reserved namespaces are:
- ECID
- IDFA
- GAID
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
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];
Public Classes
IdentityMap
Defines a map containing a set of end user identities, keyed on either namespace integration code or the namespace ID of the identity. The values of the map are an array, meaning that more than one identity of each namespace may be carried.
The format of the IdentityMap class is defined by the XDM Identity Map Schema.
For more information, please read an overview of the Identity Service.
Copied to your clipboard"identityMap" : {"Email" : [{"id" : "user@example.com","authenticatedState" : "authenticated","primary" : false}],"Phone" : [{"id" : "1234567890","authenticatedState" : "ambiguous","primary" : false},{"id" : "5557891234","authenticatedState" : "ambiguous","primary" : false}],"ECID" : [{"id" : "44809014977647551167356491107014304096","authenticatedState" : "ambiguous","primary" : true}]}
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// 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;
IdentityItem
Defines an identity to be included in an IdentityMap.
The format of the IdentityItem class is defined by the XDM Identity Item Schema.
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
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;
AuthenticatedState
Defines the state an Identity Item is authenticated for.
The possible authenticated states are:
- Ambiguous - the state is ambiguous or not defined
- Authenticated - the user is identified by a login or similar action
- LoggedOut - the user was identified by a login action at a previous time, but is not logged in now
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}
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}