EngagementEvent

Package: com.salesforce.marketingcloud.sfmcsdk.components.events

SDK Version: 11.0.0 (also available in 10.0.0)

Target Platform: androidJvm

Overview 

EngagementEvent is a sealed class representing engagement events in the Salesforce Marketing Cloud Unified SDK for Android. It extends the Event class and serves as a base class for specific engagement event types.

Declaration 

1sealed class EngagementEvent : Event

Inheritance Hierarchy 

1Event
2  └── EngagementEvent
3       ├── CartEvent
4       ├── CatalogEvent
5       └── OrderEvent

Description 

This is a base class for engagement-related events in the SDK. As a sealed class, it can only be extended within the same module, and all direct subclasses are known at compile time. This provides type safety and exhaustive when expressions when handling different engagement event types.

Inheritors 

CartEvent 

A sealed class representing cart-related events.

  • Subclasses: AddToCartEvent, RemoveFromCartEvent, ReplaceCartEvent
  • Property: lineItems: List<LineItem> - A list of line items associated with the cart event

CatalogEvent 

A sealed class representing catalog-related events.

  • Subclasses: ViewCatalogEvent, ViewCatalogDetailEvent, QuickViewCatalogEvent, ShareCatalogEvent, ReviewCatalogEvent, CommentCatalogEvent, FavoriteCatalogEvent
  • Property: catalogObject: CatalogObject - The catalog object associated with this event

OrderEvent 

A sealed class representing order-related events.

  • Subclasses: PurchaseOrderEvent, PreorderEvent, CancelOrderEvent, ShipOrderEvent, DeliverOrderEvent, ReturnOrderEvent, ExchangeOrderEvent
  • Property: order: Order - The order associated with this event

Properties 

category 

1open override var category: Event.Category

The Event category name. Category contains a list of allowed values from the Event.Category enum.

Related: See Event.Category Enum for available values.

priority 

1open override val priority: Priority

The priority level for this event.

Functions 

attributes 

1open override fun attributes(): Map<String, Any>

Returns: A map containing the Event attributes for this event.

Description: This method returns a key-value map of all attributes associated with the event. These attributes are used when the event is tracked and sent to the Marketing Cloud.

name 

1open override fun name(): String

Returns: The name for the event. This value must match the Event Name used when creating the event in the Marketing Cloud UI for any action to result from tracking this event.

Description: The event name is a critical identifier that links the SDK event to the corresponding event configuration in Marketing Cloud.

Inherited Functions 

The following methods are inherited from the Event class:

toJson 

1fun toJson(): JSONObject

Converts the event to a JSON object representation.

track 

1fun track()

Tracks this Event via EventManager to subscriber EventSubscriber.

Usage Example:

1val event = /* create your engagement event */
2event.track()

Related Classes 

Event Class 

EngagementEvent extends the abstract Event class.

Package: com.salesforce.marketingcloud.sfmcsdk.components.events

Event Properties 

id
1@JvmField
2val id: String

The event identifier.

producer
1open val producer: Event.Producer

Returns the Event Producer Name from the allowed Producer enum values.

Event Methods 

attributes()
1abstract fun attributes(): Map<String, Any>

Returns the Event attributes for this event.

name()
1abstract fun name(): String

Returns the event name, which must match the Event Name used when creating the event in the Marketing Cloud UI.

Event.Category Enum 

An enumeration defining possible category values for sending Events.

Package: com.salesforce.marketingcloud.sfmcsdk.components.events

Declaration:

1enum Category : Enum<Event.Category>

Enum Values 

ValueDescription
APPLICATIONApplication-related events
ENGAGEMENTUser engagement events
IDENTITYIdentity-related events
SYSTEMSystem events
BILLINGBilling-related events
CUSTOMCustom event categories

Properties 

entries
1val entries: EnumEntries<Event.Category>

Returns a representation of an immutable list of all enum entries, in the order they’re declared.

Methods 

valueOf
1fun valueOf(value: String): Event.Category

Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant. Extraneous whitespace is not permitted.

values
1fun values(): Array<Event.Category>

Returns an array containing the constants of this enum type, in the order they’re declared.

Event.Producer Enum 

An enumeration representing possible Producer values for sending Events.

Package: com.salesforce.marketingcloud.sfmcsdk.components.events

Declaration:

1enum Producer : Enum<Event.Producer>

Usage Guidelines 

  1. Event Name Matching: Ensure the event name returned by name() exactly matches the Event Name configured in the Marketing Cloud UI. This is critical for triggering the correct actions and automations.

  2. Event Tracking: Use the track() method to send the event to Marketing Cloud. The event will be processed by the EventManager and delivered to registered EventSubscriber instances.

  3. Event Attributes: Implement the attributes() method to provide all relevant data for your engagement event. This data will be available in Marketing Cloud for segmentation and personalization.

  4. Event Category: Set the appropriate category value from the Event.Category enum to properly classify your engagement event.

Example Usage 

1// Example of creating and tracking a custom engagement event
2class MyCustomEngagementEvent : EngagementEvent() {
3    override val category = Event.Category.ENGAGEMENT
4    override val priority = Priority.HIGH
5
6    override fun name(): String {
7        return "CustomEngagementEvent"
8    }
9
10    override fun attributes(): Map<String, Any> {
11        return mapOf(
12            "userId" to "12345",
13            "action" to "custom_interaction",
14            "timestamp" to System.currentTimeMillis()
15        )
16    }
17}
18
19// Track the event
20val event = MyCustomEngagementEvent()
21event.track()

See Also