Skip to content

Analytics

Allows handle analytics events generated by the SDK. By implementing the onAnalyticsEvent callback, developers can integrate these events with external analytics services or define custom event handling logic.

Analytics {
  handler: {
    onAnalyticsEvent: Callback(Event) // (1)!
  }
}
  1. Callback function that processes analytics events generated by the SDK, allowing integration with external analytics services or custom event handling.

Event

Each event has a type (general category) and most have a specific event within that type, along with contextual parameters like pageId and productIds.

// Sealed interface with @Serializable subclasses
sealed interface AiutaAnalyticsEvent {
    val type: String
}

// Example: try-on event
class AiutaAnalyticsTryOnEvent(
    val event: AiutaAnalyticsTryOnEventType, // initiated, tryOnStarted, ...
    val pageId: AiutaAnalyticsPageId?,
    val productIds: List<String>,
    val errorType: AiutaAnalyticsTryOnEventErrorType?,
    val uploadDuration: Double?,
    val tryOnDuration: Double?,
    // ...
) : AiutaAnalyticsEvent
// Enum with associated values
enum Event: Sendable {
    case configure
    case session(flow: Flow, productIds: [String])
    case page(pageId: Page, productIds: [String])
    case tryOn(event: TryOn, pageId: Page, productIds: [String])
    case results(event: Results, pageId: Page, productIds: [String])
    // ...
}

// Nested enums for sub-events
enum TryOn {
    case initiated(origin: Origin)
    case tryOnFinished(uploadDuration: TimeInterval, ...)
    case tryOnError(type: ErrorType, message: String?)
}
// Sealed class hierarchy with json_serializable
sealed class AiutaAnalyticsEvent {
    final AiutaAnalyticsEventType type;
    final AiutaAnalyticsPageId? pageId;
    final List<String> productIds;
}

// Example: try-on event
class AiutaAnalyticsTryOnEvent extends AiutaAnalyticsEvent {
    final AiutaAnalyticsTryOnEventType event;
    final double? uploadDuration;
    final double? tryOnDuration;
    // ...
}
// Plain object passed to callback
{
    type: string         // "tryOn", "picker", "results", ...
    event: string        // "initiated", "tryOnStarted", ...
    pageId: string
    productIds: string[]
    errorType?: string
    errorMessage?: string
}