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.
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.
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()
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.
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.
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.
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.
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 event2class MyCustomEngagementEvent : EngagementEvent(){3 override val category = Event.Category.ENGAGEMENT4 override val priority = Priority.HIGH56 override fun name(): String{7 return "CustomEngagementEvent"8}910 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}1819// Track the event20val event = MyCustomEngagementEvent()21event.track()