Capture Engagement Data (Version 3.x)

The Data 360 Module for the Engagement Mobile SDK enables the collection of rich engagement data from customer interactions within your mobile application through event tracking.

Prerequisites

Before engagement data can be sent to Data 360:

  • The Data 360 Module for the Engagement Mobile SDK must be configured and initialized.
  • Consent to track engagement data must be granted.

note: SFMCSdk.track(event:) calls are silently dropped (not queued) when consent is optOut or when the event type is blocked during pending. Set consent before or immediately after SDK initialization.

Supported Event Types

The Engagement Mobile SDK supports two types of events — structured and unstructured events. Both event types are collected using the SFMCSdk.track(event) function.

Structured Events

Structured events have predefined schemas with strict data requirements. They come pre-configured with the Mobile Connector schema for Data 360 and can be extended to capture additional custom data. The Data 360 Module supports the following structured events.

  • Cart Event: Track shopping cart interactions
  • Catalog Event: Monitor product catalog engagement
  • Order Event: Capture purchase and order data

Unstructured Events

Unstructured events have no predefined data requirements. You must create and add custom event definitions to the Mobile Connector schema for Data 360 ingestion.

Implementation Examples

import Cdp
import SFMCSDK

...

// Add to cart
SFMCSdk.track(event: AddToCartEvent(
    lineItem: LineItem(
        catalogObjectType: "Product",
        catalogObjectId: "product-001",
        quantity: 1,
        price: 29.99,
        currency: "USD"
    )
))

// Purchase order
SFMCSdk.track(event: PurchaseOrderEvent(
    order: Order(
        id: "order-001",
        lineItems: [
            LineItem(catalogObjectType: "Product", catalogObjectId: "product-001", quantity: 1)
        ],
        totalValue: 29.99,
        currency: "USD"
    )
))

// View catalog object
SFMCSdk.track(event: ViewCatalogObjectEvent(
    catalogObject: CatalogObject(
        type: "Product",
        id: "product-001",
        attributes: ["promoCode": "WINTER2025"],
        relatedCatalogObjects: [
            "sizes": ["S", "M", "L"]
        ]
    )
))

// Custom event
if let event = CustomEvent(
    name: "myCustomEvent",
    attributes: [
        "giftWrap": true,
        "giftMessage": "Happy Birthday"
    ]
) {
    SFMCSdk.track(event: event)
}

note: CustomEvent(name:attributes:) returns an optional — the call returns nil if the name is empty or contains invalid characters.

Android

On Android, the preferred pattern is calling .track() directly on the event object. This makes null-safety explicit at the call site (event construction can return null on invalid input). The older SFMCSdk.track(CartEvent.add(...)) form still works — both patterns route through the same event bus.

import com.salesforce.marketingcloud.sfmcsdk.components.events.CartEvent
import com.salesforce.marketingcloud.sfmcsdk.components.events.EventManager

...

// Add to cart
CartEvent.add(LineItem(
    catalogObjectId = "SKU-123",
    catalogObjectType = "Product",
    quantity = 1,
    price = 9.99,
    currency = "USD"
))?.track()

// View catalog object
CatalogEvent.view(CatalogObject(
    id = "SKU-123",
    type = "Product"
))?.track()

// Purchase order
OrderEvent.purchase(Order(
    id = "order-1",
    totalValue = 29.99,
    currency = "USD",
    lineItems = listOf(
        LineItem(
            catalogObjectId = "SKU-123",
            catalogObjectType = "Product",
            quantity = 1,
            price = 29.99,
            currency = "USD"
        )
    )
))?.track()

// Custom event (via sfmcsdk event bus — recommended)
EventManager.customEvent(
    name = "level_complete",
    attributes = mapOf("level" to 5)
)?.track()