Skip to main content

Sending Events

How To Track an Event

Call the track method on EngagementCloud.event to track an event of a given type.

EngagementCloud.event.track(event)

The track method accepts different event types. On Web, each event must include a type property to differentiate between them.

CustomEvent

These events trigger in-app campaigns and automations, and can be used for segmentation, personalization, and analytics in SAP Engagement Cloud.

  • event is a CustomEvent with a mandatory name (string) and optional attributes (Map<String, String>).
val event = CustomEvent(name, attributes)

To trigger in-app campaigns or automation programs, the name of the custom event must match the trigger configured for the campaign.

The NavigateEvent tracks navigation to a specific location, such as a URL or screen name. It accepts a single location parameter (String).

val event = NavigateEvent(location = "home_screen")
EngagementCloud.event.track(event)

Error Handling

EngagementCloud.event.track(CustomEvent("product_view", mapOf("sku" to sku)))
.onFailure { e -> logger.error("Event failed", e) }

Testing Strategy

Wrap tracking in an interface, for example AnalyticsTracker, so unit tests can assert calls without hitting the SDK.