Skip to main content

Receiving SDK Events

Event Handling​

The SDK communicates with your application by emitting events as a result of SDK-related operations. Access these events as follows:

applicationScope.launch {
EngagementCloud.events.collect { event ->
when(event){
is AppEvent -> handleAppEvent(event)
is BadgeCountEvent -> handleBadgeCountEvent(event)
}
}
}

Event Types​

The events emitted by the SDK conform to the following base structure:

sealed class EngagementCloudEvent {
abstract val id: String
internal abstract val type: EventType
}

All events extend EngagementCloudEvent and include a unique identifier (id).

info

On Web, each event includes a type string property for differentiating between event types. The event types follow the lowercase snake_case convention of the event name, for example badge_count for the badge count event and app_event for the app event.

App Events​

data class AppEvent(
val type: String,
val id: String,
val name: String,
val payload: Map<String, Any>?,
val source: EventSource?
)
  • name is the name of the event.
  • payload is the additional payload for the event, which can be null.
  • source is the origin that triggered the event. EventSource is on of the following:
    • Push: the event was triggered by a push notification interaction.
    • InApp: the event was triggered by an in-app message interaction.
    • InlineInApp: the event was triggered by an inline in-app message interaction.
    • EmbeddedMessagingRichContent: the event was triggered by an embedded messaging rich content interaction.
    • OnEvent: the event was triggered by an on-event action.

Badge Count Events​

data class BadgeCountEvent(
val id: String,
val badgeCount: Int,
val method: String,
)
  • badgeCount is the int value of the badge.
  • method is the string value the operation with one of the following possible values:
    • Use set to set the current value to the value of the badgeCount
    • Use add to increase the current value by the badgeCount

Memory Considerations​

To avoid memory leaks, always unsubscribe or cancel collectors when the component scope ends, for example when the Android ViewModel is cleared.