Swan

object Swan

Swan SDK — Android, v1.

Wire-format byte-equivalent with swan-react-native-sdk@2.7.x.

Properties

Link copied to clipboard
val registrationState: StateFlow<RegistrationState>

Observable registration state. Tests + host apps can collect this.

Functions

Link copied to clipboard

Fire a delivered ACK for a push notification.

Link copied to clipboard

Cold-start variant of ackPushDelivered — POST a delivered ACK without requiring init to have run.

Link copied to clipboard
fun addDeepLinkOpenedListener(listener: (DeepLinkOpenedPayload) -> Unit): (DeepLinkOpenedPayload) -> Unit

Register a callback for the unified DEEP_LINK_OPENED event.

Link copied to clipboard
fun addDeviceRegisteredListener(listener: (TelemetryEvent.DeviceRegistered) -> Unit): () -> Unit

Subscribe to the deviceRegistered lifecycle event.

Link copied to clipboard
fun addDeviceRegistrationFailedListener(listener: (TelemetryEvent.DeviceRegistrationFailed) -> Unit): () -> Unit

Subscribe to the deviceRegistrationFailed lifecycle event.

Link copied to clipboard

Register a one-shot callback fired when the SDK's background device-registration phase resolves (either RegistrationState.Registered or RegistrationState.Failed).

Link copied to clipboard
fun addNetworkStateChangedListener(listener: (TelemetryEvent.NetworkStateChanged) -> Unit): () -> Unit

Subscribe to the networkStateChanged lifecycle event.

Link copied to clipboard
fun addNotificationOpenedListener(listener: (NotificationOpenedPayload) -> Unit): (NotificationOpenedPayload) -> Unit

Register a callback fired every time the user taps a Swan push notification.

Link copied to clipboard
fun addPushLifecycleListener(listener: (PushLifecycleEvent) -> Unit): () -> Unit

Subscribe to push-permission lifecycle events.

Link copied to clipboard

Subscribe to the pushNotificationReceived lifecycle event — fires when a data-only FCM message arrives in the FOREGROUND, BEFORE the SDK posts the system notification.

Link copied to clipboard
fun addPushTokenRefreshListener(listener: (TelemetryEvent.PushTokenRefreshed) -> Unit): () -> Unit

Subscribe to the pushTokenRefresh lifecycle event — fires on FCM token rotations (FirebaseMessagingService.onNewToken).

Link copied to clipboard
fun addPushTokenRegisteredListener(listener: (TelemetryEvent.PushTokenRegistered) -> Unit): () -> Unit

Subscribe to the pushTokenRegistered lifecycle event.

Link copied to clipboard
fun addPushTokenRegistrationFailedListener(listener: (TelemetryEvent.PushTokenRegistrationFailed) -> Unit): () -> Unit

Subscribe to the pushTokenRegistrationFailed lifecycle event.

Link copied to clipboard

Subscribe to identifier-change events fired by identify and logout.

Link copied to clipboard
fun createNotificationChannel(channelId: String, channelName: String, importance: Int = 4, description: String? = null, soundResName: String? = null): String?

Create a notification channel (Android 8+; no-op on older API levels).

Link copied to clipboard
fun customEvent(name: String, attributes: Map<String, Any?> = emptyMap())

RN-parity alias for track.

Link copied to clipboard

Delete a notification channel (Android 8+; no-op on older API levels).

Link copied to clipboard

Toggle the SDK's internal debug-log gate at runtime.

Link copied to clipboard
fun enrichProfile(attributes: Map<String, Any?>)

Update arbitrary attributes on the user's customer profile.

fun enrichProfile(attributes: JsonObject)

Update arbitrary attributes on the user's customer profile using a pre-built JsonObject. Skips the Map<String, Any?>JsonObject conversion.

Link copied to clipboard

Force a flush of the pending event queue.

Link copied to clipboard

Read the current app-icon badge count.

Link copied to clipboard

Return the current session id, or null if init hasn't been called yet.

Link copied to clipboard

Snapshot of the SDK's view of the host device.

Link copied to clipboard

Returns the current FCM token, or null if push hasn't been registered yet.

Link copied to clipboard

The id of the default Swan notification channel.

Link copied to clipboard

Returns the number of pending events in the durable queue.

Link copied to clipboard

Returns the current Swan identifier — the logged-in CDID if present, else the anonymous generatedCDID, else null if registration hasn't completed yet.

Link copied to clipboard

Handle a deep-link URL from an EXTERNAL source — email, SMS, WhatsApp, Universal Links, custom schemes, ad-network click-throughs.

Link copied to clipboard
fun handleFcmDataForTests(context: Context, data: Map<String, String>, transportMessageId: String? = null)

Test / demo entrypoint exposing handleFcmInbound to the sample app and instrumented tests. Behaves identically to a real FCM-dispatched RemoteMessage arriving via SwanMessagingService.onMessageReceived: the template router resolves NotificationTemplate, the appropriate renderer fires, and the notification is posted.

Link copied to clipboard

Cold-start handler — Bundle variant.

Link copied to clipboard

Cold-start handler: extract the notification payload from a launch Intent and route it through the SDK.

Link copied to clipboard

Deliver a notification tap to the SDK.

Link copied to clipboard

Check the current OS notification-permission state.

Link copied to clipboard
fun identify(identifier: String, attributes: Map<String, Any?> = emptyMap())

Assert external user identity.

Link copied to clipboard
fun init(context: Context, appId: String)

Initialize the SDK with the default SwanConfig (production backend, debug logs off).

fun init(context: Context, appId: String, config: SwanConfig)

Initialize the SDK.

Link copied to clipboard

Snapshot read — is location tracking enabled in the SwanConfig?

Link copied to clipboard

Snapshot read — is push enabled in the SwanConfig passed to init?

Link copied to clipboard

Snapshot read of the push subsystem state.

Link copied to clipboard

Snapshot read — is the SDK fully initialized and ready to track / send?

Link copied to clipboard
suspend fun login(identifier: String, attributes: Map<String, Any?> = emptyMap()): LoginResult

Log a user in — typed, suspending RN-parity surface.

Link copied to clipboard

Log the user out, revert to the anonymous profile, and clear the cached identifier.

Link copied to clipboard

Register a host-supplied FCM token with the Swan backend.

Link copied to clipboard
fun removeDeepLinkOpenedListener(listener: (DeepLinkOpenedPayload) -> Unit)

Unregister a previously-registered DEEP_LINK_OPENED listener.

Link copied to clipboard
fun removeNotificationOpenedListener(listener: (NotificationOpenedPayload) -> Unit)

Unregister a previously-registered NOTIFICATION_OPENED listener.

Link copied to clipboard
suspend fun requestFcmToken(): Result<String?>

Fetch the FCM token via the host's Firebase Messaging SDK and register it with Swan.

Link copied to clipboard

Prompt the user for notification permission.

Link copied to clipboard
fun screen(name: String, attributes: Map<String, Any?> = emptyMap())

Track a manual screen-view event.

Link copied to clipboard

Set the app-icon badge count.

Link copied to clipboard
fun setBusinessUnit(businessUnit: String)

Set the businessUnit super-property.

Link copied to clipboard

Set the country super-property. Auto-enriched onto every subsequent event's data.country.

Link copied to clipboard

Set the currency super-property.

Link copied to clipboard

Register the host Activity backing the notification-permission OS dialog. Call from onResume(); pass null from onDestroy() if you want to be explicit (the SDK uses a java.lang.ref.WeakReference internally so it never prevents the Activity from being GC'd).

Link copied to clipboard

Set the current screen name as a super-property.

Link copied to clipboard
fun track(name: String, attributes: Map<String, Any?> = emptyMap())

Track a custom event.

fun track(name: String, attributes: JsonObject)

Track a custom event with a pre-built JsonObject payload.

Link copied to clipboard

Revoke the push subscription with the Swan backend.

Link copied to clipboard
fun updateLocation(latitude: Double, longitude: Double, accuracy: Double? = null)

Update the SDK's view of the device location.