Analytics API reference

clearQueue

Force delete, without sending to Analytics, all hits being stored or batched on the SDK.

data-variant=warning
data-slots=text
Use caution when manually clearing the queue. This operation cannot be reverted.

Android Java

data-slots=heading, code
data-repeat=2

Syntax

public static void clearQueue()

Example

Analytics.clearQueue();

Android Kotlin

data-slots=heading, code
data-repeat=1

Example

Analytics.clearQueue();

iOS Swift

data-slots=heading, code
data-repeat=2

Syntax

static func clearQueue()

Example

Analytics.clearQueue()

iOS Objective-C

data-slots=heading, code
data-repeat=2

Syntax

+ (void) clearQueue;

Example

[AEPMobileAnalytics clearQueue];

extensionVersion

The extensionVersion() API returns the version of the Analytics extension that is registered with the Mobile Core extension.

To get the version of the Analytics extension, use the following code sample:

Android Java

data-slots=heading, code
data-repeat=2

Syntax

public static String extensionVersion()

Example

String analyticsExtensionVersion = Analytics.extensionVersion();

Android Kotlin

data-slots=heading, code
data-repeat=1

Example

val extensionVersion = Analytics.extensionVersion();

iOS Swift

data-slots=heading, code
data-repeat=2

Syntax

static var extensionVersion: String

Example

let version = Analytics.extensionVersion

iOS Objective-C

data-slots=heading, code
data-repeat=2

Syntax

+ (nonnull NSString*) extensionVersion;

Example

NSString *version = [AEPMobileAnalytics extensionVersion];

getQueueSize

Retrieves the total number of Analytics hits in the tracking queue.

Android Java

data-slots=heading, code
data-repeat=2

Syntax

public static void getQueueSize(@NonNull final AdobeCallback<Long> callback)

Example

Analytics.getQueueSize(new AdobeCallbackWithError<Long>() {
    @Override
    public void fail(AdobeError adobeError) {
        // Handle the error
    }

    @Override
    public void call(Long size) {
        // Handle the queue size
    }
});

Android Kotlin

data-slots=heading, code
data-repeat=1

Example

Analytics.getQueueSize(object: AdobeCallbackWithError<Long> {
    override fun call(size: Long?) {
        // Handle the queue size
    }

    override fun fail(error: AdobeError?) {
        // Handle the error
    }
})

Please use the getQueueSizeWithCompletionHandler API instead.

getQueueSizeWithCompletionHandler

Retrieves the total number of Analytics hits in the tracking queue. Invoke the callback with NSError if an unexpected error occurs or the request times out.

iOS Swift

data-slots=heading, code
data-repeat=2

Syntax

static func getQueueSize(completion: @escaping (Int, Error?) -> Void)

Example

Analytics.getQueueSize { (queueSize, error) in
    // Handle error (if non-nil) or use queueSize.
}

iOS Objective-C

data-slots=heading, code
data-repeat=2

Syntax

+ (void)getQueueSize:^(NSInteger, NSError * _Nullable)completion

Example

[AEPMobileAnalytics getQueueSize:^(NSInteger queueSize, NSError * _Nullable error) {
    // Handle error (if non-nil) or use queueSize.
 }];

getTrackingIdentifier

Retrieves the Analytics tracking identifier that is generated for this app/device instance. This identifier is an app-specific, unique visitor ID that is generated at the initial launch and is stored and used after the initial launch. The ID is preserved between app upgrades and is removed when the app is uninstalled as well as on MobileCore.resetIdentities API call or on privacy status opt out.

data-variant=warning
data-slots=text
Starting with v1.2.9 (Android) / v3.0.3(iOS AEPAnalytics) / v2.5.1 (iOS ACPAnalytics) this API does not generate or retrieve a new tracking identifier (AID) for new visitors. For the visitors which have an AID previously generated will continue retrieve the AID value with this API, and new users will use the ECID (MID) value as the primary identity.<br/><br/>Before using this API, see the documentation on identifying unique visitors.

Android Java

data-slots=heading, code
data-repeat=2

Syntax

public static void getTrackingIdentifier(@NonNull final AdobeCallback<String> callback)

Example

Analytics.getTrackingIdentifier(new AdobeCallbackWithError<String>() {
    @Override
    public void fail(AdobeError adobeError) {
        // Handle the error
    }

    @Override
    public void call(String s) {
        // Handle the Experience Cloud ID
    }
});

Android Kotlin

data-slots=heading, code
data-repeat=1

Example

Analytics.getTrackingIdentifier(object: AdobeCallbackWithError<String> {
    override fun call(id: String?) {
        // Handle the Experience Cloud ID
    }

    override fun fail(error: AdobeError?) {
        // Handle the error
    }
})

iOS

Please see the getTrackingIdentifierWithCompletionHandler section for using this API call.

getTrackingIdentifierWithCompletionHandler

data-variant=warning
data-slots=text
Starting with v1.2.9 (Android) / v3.0.3(iOS AEPAnalytics) / v2.5.1 (iOS ACPAnalytics) this API does not generate or retrieve a new tracking identifier (AID) for new visitors. For the visitors which have an AID previously generated will continue retrieve the AID value with this API, and new users will use the ECID (MID) value as the primary identity.<br/><br/>Before you use this API, please read the documentation on identifying unique visitors.

Retrieves the Analytics tracking identifier that is generated for this app/device instance. This identifier is an app-specific, unique visitor ID that is generated at the initial launch and is stored and used after the initial launch. The ID is preserved between app upgrades and is removed when the app is uninstalled. Invoke the callback with NSError if an unexpected error occurs or the request times out.

data-variant=info
data-slots=text
If you have an Experience Cloud ID and have not yet configured a visitor ID grace period, the value returned by getTrackingIdentifier may be null.

iOS Swift

data-slots=heading, code
data-repeat=2

Syntax

static func getTrackingIdentifier(completion: @escaping (String?, Error?) -> Void)

Example

Analytics.getTrackingIdentifier { (trackingId, error) in
   // Handle the error (if non-nil) or use the trackingIdentifier value
}

iOS Objective-C

data-slots=heading, code
data-repeat=2

Syntax

+ (void) getTrackingIdentifier:^(NSString * _Nullable, NSError * _Nullable)completion

Example

AEPMobileAnalytics getTrackingIdentifier:^(NSString * _Nullable trackingIdentifier, NSError * _Nullable error) {
   // Handle the error (if non-nil) or use the trackingIdentifier value
}];

getVisitorIdentifier

data-variant=warning
data-slots=text
Before using this API, please read the documentation on identifying unique visitors.

This API gets a custom Analytics visitor identifier, which has been set previously using setVisitorIdentifier.

Android Java

data-slots=heading, code
data-repeat=2

Syntax

public static void getVisitorIdentifier(@NonNull final AdobeCallback<String> callback)

Example

Analytics.getVisitorIdentifier(new AdobeCallbackWithError<String>() {
    @Override
    public void fail(AdobeError adobeError) {
        // Handle the error
    }

    @Override
    public void call(String s) {
        // Handle the Visitor ID
    }
});

Android Kotlin

data-slots=heading, code
data-repeat=1

Example

Analytics.getVisitorIdentifier(object: AdobeCallbackWithError<String> {
    override fun call(id: String?) {
        // Handle the Visitor ID
    }

    override fun fail(error: AdobeError?) {
        // Handle the error
    }
})

For more information on using this API call, please read getVisitorIdentifierWithCompletionHandler.

getVisitorIdentifierWithCompletionHandler

data-variant=warning
data-slots=text
Before using this API, see Identify unique visitors.

This API gets a custom Analytics visitor identifier, which has been set previously using setVisitorIdentifier. Callback with NSError if an unexpected error occurs or the request times out.

iOS Swift

data-slots=heading, code
data-repeat=2

Syntax

static func getVisitorIdentifier(completion: @escaping (String?, Error?) -> Void)

Example

Analytics.getVisitorIdentifier { (visitorIdentifier, error) in
   // Handle the error (if non-nil) or use the visitorIdentifier value
}

iOS Objective-C

data-slots=heading, code
data-repeat=2

Syntax

+ (void) getVisitorIdentifier:^(NSString * _Nullable, NSError * _Nullable)completion

Example

[AEPMobileAnalytics getVisitorIdentifier:^(NSString * _Nullable visitorIdentifier, NSError * _Nullable error) {
   // Handle the error (if non-nil) or use the visitorIdentifier value
}];

registerExtension

data-variant=warning
data-slots=text1, text2
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.

Registers the Analytics extension with the Mobile Core SDK.

Android Java

data-slots=heading, code
data-repeat=2

Syntax

public static void registerExtension()

Example

Analytics.registerExtension();

Android Kotlin

data-slots=heading, code
data-repeat=1

Example

Analytics.registerExtension()

resetIdentities

Clears the identities stored in the Analytics extension - tracking identifier (AID) and the custom visitor identifiers (VID) stored in the Analytics extension and force deletes, without sending to Analytics, all hits being stored or batched on the SDK.

data-variant=info
data-slots=text
Support for this API was added in: <ul><li>Android Analytics version 1.2.9</li><li>iOS AEPAnalytics version 3.0.3</li></ul><br/>See MobileCore.resetIdentities for more details.

sendQueuedHits

Sends all queued hits to Analytics, regardless of the current hit batch settings.

This method forces the library to send all hits in the offline queue, regardless of how many hits are currently queued.

data-variant=warning
data-slots=text
Use caution when manually clearing the queue. This operation cannot be reverted.

Android Java

data-slots=heading, code
data-repeat=2

Syntax

public static void sendQueuedHits()

Example

Analytics.sendQueuedHits();

Android Kotlin

data-slots=heading, code
data-repeat=1

Example

Analytics.sendQueuedHits();

iOS Swift

data-slots=heading, code
data-repeat=2

Syntax

static func sendQueuedHits()

Example

[AEPMobileAnalytics sendQueueHits];

iOS Objective-C

data-slots=heading, code
data-repeat=2

Syntax

+ (void) sendQueueHits

Example

Analytics.sendQueuedHits()

setVisitorIdentifier

data-variant=warning
data-slots=text
Before using this API, see Identify unique visitors.

Sets a custom Analytics visitor identifier. For more information, see Custom Visitor ID.

Android Java

data-slots=heading, code
data-repeat=2

Syntax

public static void setVisitorIdentifier(@NonNull final String visitorID)

Example

Analytics.setVisitorIdentifier("custom_identifier");

Android Kotlin

data-slots=heading, code
data-repeat=1

Example

Analytics.setVisitorIdentifier("custom_identifier");

iOS Swift

data-slots=heading, code
data-repeat=2

Syntax

static func setVisitorIdentifier(visitorIdentifier: String)

Example

Analytics.setVisitorIdentifier(visitorIdentifier:"custom_identifier")

iOS Objective-C

data-slots=heading, code
data-repeat=2

Syntax

+ (void) setVisitorIdentifier:(NSString * _Nonnull)

Example

[AEPMobileAnalytics setVisitorIdentifier:@"custom_identifier"];