Sending Events
How To Track an Event
Call the track method on EngagementCloud.event to track an event of a given type.
- Android
- Kotlin Multiplatform
- iOS
- Web
EngagementCloud.event.track(event)
EngagementCloud.event.track(event)
await EngagementCloud.shared.event.track(event: event)
await window.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.
eventis aCustomEventwith a mandatoryname(string) and optionalattributes(Map<String, String>).
- Android
- Kotlin Multiplatform
- iOS
- Web
val event = CustomEvent(name, attributes)
val event = CustomEvent(name, attributes)
let event = CustomEvent(name: <event-name>, attributes: <attributes>)
const event = { type: "custom", name: name, attributes: {"key1": "value1"} }
To trigger in-app campaigns or automation programs, the name of the custom event must match the trigger configured for the campaign.
NavigateEvent
The NavigateEvent tracks navigation to a specific location, such as a URL or screen name. It accepts a single location parameter (String).
- Android
- Kotlin Multiplatform
- iOS
- Web
val event = NavigateEvent(location = "home_screen")
EngagementCloud.event.track(event)
val event = NavigateEvent(location = "home_screen")
EngagementCloud.event.track(event)
let event = NavigateEvent(location: "home_screen")
await EngagementCloud.shared.event.track(event: event)
const event = { type: "navigate", location: "https://www.sap.com" }
await window.EngagementCloud.event.track(event);
Error Handling
- Android
- Kotlin Multiplatform
- iOS
- Web
EngagementCloud.event.track(CustomEvent("product_view", mapOf("sku" to sku)))
.onFailure { e -> logger.error("Event failed", e) }
EngagementCloud.event.track(CustomEvent("product_view", mapOf("sku" to sku)))
.onFailure { e -> logger.error("Event failed", e) }
do {
try await EngagementCloud.shared.event.track(
event: CustomEvent(name: "product_view", attributes: ["sku": sku])
)
} catch {
print(error)
}
try {
await window.EngagementCloud.event.track(
{ type: 'custom', name: 'product_view', attributes: { sku } }
);
} catch (e) {
console.error(e);
}
Testing Strategy
Wrap tracking in an interface, for example AnalyticsTracker, so unit tests can assert calls without hitting the SDK.