Skip to content

Event tracking support#92

Open
timkimadobe wants to merge 3 commits intoadobe:devfrom
timkimadobe:event-tracking
Open

Event tracking support#92
timkimadobe wants to merge 3 commits intoadobe:devfrom
timkimadobe:event-tracking

Conversation

@timkimadobe
Copy link
Copy Markdown
Contributor

Description

This PR adds SDK tracking events dispatched to the AEP Event Hub, following the Lifecycle for Edge Network paradigm. Users can construct Data Collection rules to forward these events to their datastream for tracking/XDM mapping.

All tracking events use:

  • Event type: com.adobe.eventType.concierge
    • TODO: Need to add this type to Core
  • Event source: com.adobe.eventSource.notification
  • Payload: concierge.eventType (the granular event subtype for XDM mapping) plus event-specific data
    • Note that these correspond to the web client tracking events, other than:
      • webclient:initialized -> implemented as session:initialized (could use mobileclient:initialized to follow the same paradigm?)
      • history:cleared -> history clearing (as an explicit user action) is not available today, when auto session clearing logic is added this event type could be added too
Tracking Event concierge.eventType Additional Data
Session Initialized session:initialized
Query Submitted query:submitted query
Prompt Suggestion Clicked promptSuggestion:clicked suggestion
Card Clicked card:clicked element (product details dict)
Response Started response:started conversationId, interactionId
Response Completed response:completed conversationId, interactionId
Cards Rendered cards:rendered displayMode, elements
Feedback Submitted feedback:submitted conversationId, interactionId, feedbackType, selectedOptions, notes
Error Occurred error:occurred errorMessage

Tracking infrastructure

  • Created ConciergeTrackingEvent enum with a toEvent() factory that produces AEPCore.Event objects with the corresponding type, source, and payload
  • Added ConciergeConstants.TrackingEvent with nested Name, XDMType, and EventData.Key enums for all tracking constants
  • Dispatch closure injected into ChatController at init time (same pattern as LifecycleV2)
  • Concierge+PublicAPI.show() and ConciergeHostingController pass MobileCore.dispatch(event:) as the dispatch closure

Dispatch integration in ChatController

  • sessionInitialized — dispatched in loadWelcomeIfNeeded after welcome content is set up
  • querySubmitted — dispatched in sendMessage when the user sends a query
  • responseStarted — dispatched on the first chunk received in streamAgentResponse (once per stream, guarded by a local flag)
  • responseCompleted — dispatched when the stream completes successfully
  • errorOccurred — dispatched when the stream fails
  • cardsRendered — dispatched in renderMultimodalElements when product cards are appended
  • feedbackSubmitted — dispatched in sendFeedbackFor after feedback is sent to the server
  • promptSuggestionClicked and cardClicked — exposed as public methods on ChatController, called from the view layer

Card tap tracking

  • Created ConciergeCardTapHandler (SwiftUI EnvironmentKey) so card views can report taps back to ChatController without nested callback wiring
  • ChatView injects the handler, ProductDetailCardView and ChatMessageView consume it via @Environment

Tests

  • ConciergeTrackingEventTests — verifies each event case produces the correct Event name, type, source, and payload
  • ConciergeChatViewModelTests — 9 new tests:
    • Dispatch verification for querySubmitted, responseStarted, responseCompleted, errorOccurred, cardsRendered, feedbackSubmitted, promptSuggestionClicked, cardClicked
    • Successive conversation turns dispatch independent tracking events
    • Nil dispatch closure does not crash

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@timkimadobe timkimadobe requested a review from rymorale April 7, 2026 22:40
@rymorale
Copy link
Copy Markdown
Contributor

rymorale commented Apr 9, 2026

The changes look good to me overall but I just had a question about dispatchTrackingEvent. I noticed that some calls can possibly be made with an empty conversation or interaction id. Should we still dispatch tracking events in this case? Or should we consider a missing id as an invalid event?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants