Skip to main content

Enabling Tracking

Enable​

Call enable with a platform-specific EngagementCloudConfiguration to start tracking. Calling enable with a valid configuration allows the SDK to track user activity, send custom events, and receive messages such as in-app and push notifications. See Initial Configuration. The onContactLinkingFailed parameter is a required callback invoked when automatic contact linking fails.

warning

The onContactLinkingFailed callback must be set on each app start, either by passing it to enable or by calling the setOnContactLinkingFailedCallback method.

EngagementCloud.setup.enable(
config = AndroidEngagementCloudSDKConfig(
applicationCode = "ABCDE-12345",
launchActivityClass = MainActivity::class.java
),
onContactLinkingFailed = {
// Example: Prompt user to log in and retrieve their contact identifier
val loggedInUser = showLoginDialogAndAwaitResult()
loggedInUser?.let { LinkContactData(contactFieldValue = it.userId) }
}
)

Parameters​

ParameterTypeRequiredDescription
configEngagementCloudSDKConfigYesPlatform-specific SDK configuration
onContactLinkingFailedCallback returning LinkContactData?YesInvoked when contact linking fails. Return contact data for the SDK to retry linking.

LinkContactData​

The LinkContactData object can contain either:

  • contactFieldValue: A string identifier for the contact
  • openIdToken: An OpenID token for authenticated linking

Disable​

To stop tracking while keeping the SDK initialized, call disable.

EngagementCloud.setup.disable()

isEnabled​

Checks whether the SDK is enabled.

EngagementCloud.setup.isEnabled()

setOnContactLinkingFailedCallback​

warning

Must be called on each app start.

Sets the callback used to acquire contact data when automatic contact linking fails. Must be called on each app start.

EngagementCloud.setup.setOnContactLinkingFailedCallback {
// Prompt user to log in and retrieve their contact identifier
val loggedInUser = showLoginDialogAndAwaitResult()
loggedInUser?.let { LinkContactData(contactFieldValue = it.userId) }
}

Parameters​

ParameterTypeDescription
onContactLinkingFailedCallback returning LinkContactData?Invoked when contact linking fails. Return contact data for the SDK to retry linking.

What Happens After Enabling the SDK​

AspectBehavior After Enable
Event DispatchSends queued and new events
Push TokenAttempts to register the token if one was captured before enabling
Contact Re-LinkRe-links the contact automatically if previously linked
In-AppStarts listening for in-app message triggers

Idempotency and Errors​

Calling enable again returns an error that is safe to ignore.

Before You Start Tracking Events​

Follow this order:

Initialize the SDK -> Enable the SDK -> Link a contact -> Register a push token -> Track events

Disabling Tracking​

For example, when a user revokes consent:

  • Queued events remain in the database and are sent when the SDK is re-enabled.
  • The SDK automatically calls unlink(). When calling enable() again, call link() to re-identify the contact.
  • Push tokens are not deleted automatically. Call EngagementCloud.push.clearToken() if needed.