markSurveyDismissed method
Clears the active survey after the user closes the result page.
Fired when the user closes the survey without completing it.
abandonedAtItem is the 1-based question they were on; answeredCount
is how many they had answered.
Implementation
/// Fired when the user closes the survey without completing it.
/// [abandonedAtItem] is the 1-based question they were on; [answeredCount]
/// is how many they had answered.
void markSurveyDismissed({int? abandonedAtItem, int? answeredCount}) {
final state = _surveyOrchestrator.state;
if (state == null) return;
final completed = _completedSurveyToken == state.token;
_surveyOrchestrator.dismiss();
final dwellMs = _dwellTracker.consumeDwellMs(state.payload.cepCampaignId);
if (completed) {
// Completed wins for CEP outcome (R3-D12). Digia always receives
// SurveyDismissed carrying dwell_ms so completers are included in screen
// duration metrics (#88).
_events.toCep(
const ExperienceDismissed(
reason: DismissReason.completed, completed: true),
state.payload,
);
_events.toDigia(
SurveyDismissed(
dismissReason: DismissReason.completed.wire,
abandonedAtItem: null,
itemTotal: _surveyItemTotal(state.config),
answeredCount: answeredCount,
dwellMs: dwellMs,
),
state.payload,
);
_clearQuestionViewedAt(state.token);
return;
}
const reason = DismissReason.userClose;
_events.toBoth(
const ExperienceDismissed(reason: reason),
SurveyDismissed(
dismissReason: reason.wire,
abandonedAtItem: abandonedAtItem,
itemTotal: _surveyItemTotal(state.config),
answeredCount: answeredCount,
dwellMs: dwellMs,
),
state.payload,
);
_clearQuestionViewedAt(state.token);
}