Identity
The Identity extension enables your app with the Experience Cloud ID (ECID). This service helps with the synchronization of Adobe and other customer identifiers.
On web or other platforms, there might situations where this extension might not be required, and the implementation of this SDK extension on mobile apps is required.
To get started with Identity, complete the following steps:
- Add the Identity extension to your app.
- Implement the SDK APIs to complete the following tasks:
- Update customer IDs.
- Append Adobe visitor data to a URL string.
- Return customer IDs.
- Retrieve Experience Cloud IDs.
- Set advertising IDs.
- Set the device notification for push notifications.
Add the Identity extension to your app
- Add the
Identity
library to your project using the app's gradle file.
Kotlin
Copied to your clipboardimplementation(platform("com.adobe.marketing.mobile:sdk-bom:3.+"))implementation("com.adobe.marketing.mobile:core")implementation("com.adobe.marketing.mobile:identity")
Groovy
Copied to your clipboardimplementation platform('com.adobe.marketing.mobile:sdk-bom:3.+')implementation 'com.adobe.marketing.mobile:core'implementation 'com.adobe.marketing.mobile:identity'
Using dynamic dependency versions is not recommended for production apps. Please read the managing Gradle dependencies guide for more information.
- Import the Identity and MobileCore extensions in your application's main activity.
Java
Import the library:
Copied to your clipboardimport com.adobe.marketing.mobile.MobileCore;import com.adobe.marketing.mobile.Identity;
- Add the Mobile Core and Identity extensions to your project using Cocoapods. Add following pods in your
Podfile
:
Copied to your clipboarduse_frameworks!target 'YourTargetApp' dopod 'AEPCore', '~> 5.0'pod 'AEPIdentity', '~> 5.0'end
- Import the Identity library.
Swift
Copied to your clipboardimport AEPCoreimport AEPIdentity
Objective-C
Copied to your clipboard@import AEPCore;@import AEPIdentity;
- Add the
Identity
library to your project using the app's gradle file.
Kotlin
Copied to your clipboardimplementation(platform("com.adobe.marketing.mobile:sdk-bom:3.+"))implementation("com.adobe.marketing.mobile:core")implementation("com.adobe.marketing.mobile:identity")
Groovy
Copied to your clipboardimplementation platform('com.adobe.marketing.mobile:sdk-bom:3.+')implementation 'com.adobe.marketing.mobile:core'implementation 'com.adobe.marketing.mobile:identity'
Using dynamic dependency versions is not recommended for production apps. Please read the managing Gradle dependencies guide for more information.
- Import the Identity and MobileCore extensions in your application's main activity.
Java
Import the library:
Copied to your clipboardimport com.adobe.marketing.mobile.MobileCore;import com.adobe.marketing.mobile.Identity;
- Add the Mobile Core and Identity extensions to your project using Cocoapods. Add following pods in your
Podfile
:
Copied to your clipboarduse_frameworks!target 'YourTargetApp' dopod 'AEPCore', '~> 5.0'pod 'AEPIdentity', '~> 5.0'end
- Import the Identity library.
Swift
Copied to your clipboardimport AEPCoreimport AEPIdentity
Objective-C
Copied to your clipboard@import AEPCore;@import AEPIdentity;
Register the Identity extension
The MobileCore.registerExtensions()
API can be used to register the Identity extension with the Mobile Core extension. This API allows the extension to send and receive events to and from the Mobile SDK.
To register the Identity extension, use the following code sample:
After calling the setApplication()
method in the onCreate()
method, register the Identity extension.
Java
Copied to your clipboardpublic class MobileApp extends Application {@Overridepublic void onCreate() {super.onCreate();MobileCore.setApplication(this);List<Class<? extends Extension>> extensions = Arrays.asList(Identity.EXTENSION, ...);MobileCore.registerExtensions(extensions, o -> {// Any other post registration processing});}}
Register the Identity extension in your app's didFinishLaunchingWithOptions
function:
Swift
When including both Identity and Identity for Edge Network extensions, register the extensions using their full Swift module names, such as AEPIdentity.Identity.self
.
Copied to your clipboardfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {MobileCore.registerExtensions([Identity.self, ...], {...})}
Objective-C
Copied to your clipboard- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {[AEPMobileCore registerExtensions:@[AEPMobileIdentity.class, ...] completion:^{...}];return YES;}
After calling the setApplication()
method in the onCreate()
method, register the Identity extension.
Java
Copied to your clipboardpublic class MobileApp extends Application {@Overridepublic void onCreate() {super.onCreate();MobileCore.setApplication(this);List<Class<? extends Extension>> extensions = Arrays.asList(Identity.EXTENSION, ...);MobileCore.registerExtensions(extensions, o -> {// Any other post registration processing});}}
Register the Identity extension in your app's didFinishLaunchingWithOptions
function:
Swift
When including both Identity and Identity for Edge Network extensions, register the extensions using their full Swift module names, such as AEPIdentity.Identity.self
.
Copied to your clipboardfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {MobileCore.registerExtensions([Identity.self, ...], {...})}
Objective-C
Copied to your clipboard- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {[AEPMobileCore registerExtensions:@[AEPMobileIdentity.class, ...] completion:^{...}];return YES;}
Previously known as MCID/MID/MCMID, the Experience Cloud ID (ECID) is a 38 character ID that uniquely identifies each visitor in the Adobe Experience Platform.
After the configuration is complete, an ECID is generated and, where applicable, is included on all Analytics and Audience Manager hits. Other IDs, such as custom and automatically-generated IDs, continue to be sent with each hit.
Visitor tracking between an app and the mobile web
If your app opens mobile web content, you need to ensure that visitors are not identified separately as they move between the native and mobile web.
Visitor IDs in apps
The Mobile SDK generates a unique visitor ID when the app is installed. This ECID is stored in persistent memory on the mobile device and is sent with every hit. The ECID is removed when the user uninstalls the app or when the user sets the Mobile SDK global privacy status to optedout
.
When the Mobile SDK privacy status is set to optedout
, and the ECID is removed, a new unique visitor ID (ECID) is generated when the user sets the global privacy status to optedin
.
App visitor IDs persist through upgrades.
Visitor IDs in the mobile web
Typical mobile web implementations use the same standard analytics s_code.js
or AppMeasurement.js
that is used in desktop sites. The JavaScript libraries have their own methods of generating unique visitor IDs, which causes a different visitor ID to be generated when you open mobile web content from your app.
To use the same visitor ID in the app and mobile web and pass the visitor ID to the mobile web in the URL, complete the following steps:
Implementing visitor tracking between an app and the mobile web
Java
To append visitor information to the URL that is being used to open the web view, call appendVisitorInfoForUrl:
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);}});
Alternately, starting in SDK version 1.4.0 (Identity version 1.1.0), you can call getUrlVariables and build your own URL:
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);}});
To append visitor information to the URL that is being used to open the web view, call appendToUrl:
Swift
Copied to your clipboardlet url = URL(string: "https://example.com")Identity.appendTo(url: url) { appendedUrl, error inif error != nil {// handle error here} else {// handle appended url here}}
Objective-C
Copied to your clipboardNSURL *sampleUrl = [NSURL URLWithString:@"https://example.com"];[AEPMobileIdentity appendToUrl:sampleUrl completion:^(NSURL * _Nullable appendedUrl, NSError *error) {if (error != nil) {// Handle error here} else {// Handle appended url here}}];
Alternately, you can call getUrlVariables and build your own URL:
Swift
Copied to your clipboardIdentity.getUrlVariables { urlVariables, error inif error != nil {// handle error here} else {if let url = URL(string: "https://example.com?\(urlVariables ?? "")") {DispatchQueue.main.async {UIApplication.shared.open(url)}}}}
Objective-C
Copied to your clipboard[AEPMobileIdentity getUrlVariables:^(NSString * _Nullable urlVariables, NSError *error) {NSString *sampleURLString = @"https://example.com";if (error != nil) {// Handle variables being nil} else {NSString *stringWithData = [NSString stringWithFormat:@"%@?%@", sampleURLString, urlVariables];NSURL *appendedUrl = [NSURL URLWithString:stringWithData];dispatch_async(dispatch_get_main_queue(), ^{[[UIApplication sharedApplication] openURL:appendedUrl options:@{} completionHandler:nil];});}}];
Java
To append visitor information to the URL that is being used to open the web view, call appendVisitorInfoForUrl:
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);}});
Alternately, starting in SDK version 1.4.0 (Identity version 1.1.0), you can call getUrlVariables and build your own URL:
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);}});
To append visitor information to the URL that is being used to open the web view, call appendToUrl:
Swift
Copied to your clipboardlet url = URL(string: "https://example.com")Identity.appendTo(url: url) { appendedUrl, error inif error != nil {// handle error here} else {// handle appended url here}}
Objective-C
Copied to your clipboardNSURL *sampleUrl = [NSURL URLWithString:@"https://example.com"];[AEPMobileIdentity appendToUrl:sampleUrl completion:^(NSURL * _Nullable appendedUrl, NSError *error) {if (error != nil) {// Handle error here} else {// Handle appended url here}}];
Alternately, you can call getUrlVariables and build your own URL:
Swift
Copied to your clipboardIdentity.getUrlVariables { urlVariables, error inif error != nil {// handle error here} else {if let url = URL(string: "https://example.com?\(urlVariables ?? "")") {DispatchQueue.main.async {UIApplication.shared.open(url)}}}}
Objective-C
Copied to your clipboard[AEPMobileIdentity getUrlVariables:^(NSString * _Nullable urlVariables, NSError *error) {NSString *sampleURLString = @"https://example.com";if (error != nil) {// Handle variables being nil} else {NSString *stringWithData = [NSString stringWithFormat:@"%@?%@", sampleURLString, urlVariables];NSURL *appendedUrl = [NSURL URLWithString:stringWithData];dispatch_async(dispatch_get_main_queue(), ^{[[UIApplication sharedApplication] openURL:appendedUrl options:@{} completionHandler:nil];});}}];
The ID service code on the destination domain extracts the ECID from the URL instead of sending a request to Adobe for a new ID. The ID service code on the destination page uses this ECID to track the visitor. On hits from the mobile web content, verify that the mid
parameter exists on each hit, and that this value matches the mid
value that is being sent by the app code.